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.
60 func (t *Torrent) Drop() {
62 t.cl.dropTorrent(t.infoHash)
66 // Number of bytes of the entire torrent we have completed.
67 func (t *Torrent) BytesCompleted() int64 {
69 defer t.cl.mu.RUnlock()
70 return t.bytesCompleted()
73 // The subscription emits as (int) the index of pieces as their state changes.
74 // A state change is when the PieceState for a piece alters in value.
75 func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription {
76 return t.pieceStateChanges.Subscribe()
79 // Returns true if the torrent is currently being seeded. This occurs when the
80 // client is willing to upload without wanting anything in return.
81 func (t *Torrent) Seeding() bool {
83 defer t.cl.mu.Unlock()
84 return t.cl.seeding(t)
87 // Clobbers the torrent display name. The display name is used as the torrent
88 // name if the metainfo is not available.
89 func (t *Torrent) SetDisplayName(dn string) {
91 defer t.cl.mu.Unlock()
95 // The current working name for the torrent. Either the name in the info dict,
96 // or a display name given such as by the dn value in a magnet link, or "".
97 func (t *Torrent) Name() string {
99 defer t.cl.mu.Unlock()
103 func (t *Torrent) Length() int64 {
112 // Returns a run-time generated metainfo for the torrent that includes the
113 // info bytes and announce-list as currently known to the client.
114 func (t *Torrent) Metainfo() *metainfo.MetaInfo {
116 defer t.cl.mu.Unlock()
120 func (t *Torrent) addReader(r *Reader) {
122 defer t.cl.mu.Unlock()
123 if t.readers == nil {
124 t.readers = make(map[*Reader]struct{})
126 t.readers[r] = struct{}{}
130 func (t *Torrent) deleteReader(r *Reader) {
132 defer t.cl.mu.Unlock()
137 func (t *Torrent) DownloadPieces(begin, end int) {
139 defer t.cl.mu.Unlock()
140 t.pendPieceRange(begin, end)
143 func (t *Torrent) CancelPieces(begin, end int) {
145 defer t.cl.mu.Unlock()
146 t.unpendPieceRange(begin, end)