4 "github.com/anacrolix/missinggo/pubsub"
6 "github.com/anacrolix/torrent/metainfo"
9 // The torrent's infohash. This is fixed and cannot change. It uniquely
10 // identifies a torrent.
11 func (t *Torrent) InfoHash() metainfo.Hash {
15 // Closed when the info (.Info()) for the torrent has become available. Using
16 // features of Torrent that require the info before it is available will have
17 // undefined behaviour.
18 func (t *Torrent) GotInfo() <-chan struct{} {
22 // Returns the metainfo info dictionary, or nil if it's not yet available.
23 func (t *Torrent) Info() *metainfo.InfoEx {
27 // Returns a Reader bound to the torrent's data. All read calls block until
28 // the data requested is actually available.
29 func (t *Torrent) NewReader() (ret *Reader) {
32 readahead: 5 * 1024 * 1024,
38 // Returns the state of pieces of the torrent. They are grouped into runs of
39 // same state. The sum of the state run lengths is the number of pieces
41 func (t *Torrent) PieceStateRuns() []PieceStateRun {
43 defer t.cl.mu.Unlock()
44 return t.pieceStateRuns()
47 func (t *Torrent) PieceState(piece int) PieceState {
49 defer t.cl.mu.Unlock()
50 return t.pieceState(piece)
53 // The number of pieces in the torrent. This requires that the info has been
55 func (t *Torrent) NumPieces() int {
59 // Drop the torrent from the client, and close it. It's always safe to do
60 // this. No data corruption can, or should occur to either the torrent's data,
61 // or connected peers.
62 func (t *Torrent) Drop() {
64 t.cl.dropTorrent(t.infoHash)
68 // Number of bytes of the entire torrent we have completed.
69 func (t *Torrent) BytesCompleted() int64 {
71 defer t.cl.mu.RUnlock()
72 return t.bytesCompleted()
75 // The subscription emits as (int) the index of pieces as their state changes.
76 // A state change is when the PieceState for a piece alters in value.
77 func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription {
78 return t.pieceStateChanges.Subscribe()
81 // Returns true if the torrent is currently being seeded. This occurs when the
82 // client is willing to upload without wanting anything in return.
83 func (t *Torrent) Seeding() bool {
85 defer t.cl.mu.Unlock()
86 return t.cl.seeding(t)
89 // Clobbers the torrent display name. The display name is used as the torrent
90 // name if the metainfo is not available.
91 func (t *Torrent) SetDisplayName(dn string) {
93 defer t.cl.mu.Unlock()
97 // The current working name for the torrent. Either the name in the info dict,
98 // or a display name given such as by the dn value in a magnet link, or "".
99 func (t *Torrent) Name() string {
101 defer t.cl.mu.Unlock()
105 func (t *Torrent) Length() int64 {
114 // Returns a run-time generated metainfo for the torrent that includes the
115 // info bytes and announce-list as currently known to the client.
116 func (t *Torrent) Metainfo() *metainfo.MetaInfo {
118 defer t.cl.mu.Unlock()
122 func (t *Torrent) addReader(r *Reader) {
124 defer t.cl.mu.Unlock()
125 if t.readers == nil {
126 t.readers = make(map[*Reader]struct{})
128 t.readers[r] = struct{}{}
132 func (t *Torrent) deleteReader(r *Reader) {
134 defer t.cl.mu.Unlock()
139 func (t *Torrent) DownloadPieces(begin, end int) {
141 defer t.cl.mu.Unlock()
142 t.pendPieceRange(begin, end)
145 func (t *Torrent) CancelPieces(begin, end int) {
147 defer t.cl.mu.Unlock()
148 t.unpendPieceRange(begin, end)