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 // Returns a channel that is closed when the info (.Info()) for the torrent
16 // has become available.
17 func (t *Torrent) GotInfo() <-chan struct{} {
21 // Returns the metainfo info dictionary, or nil if it's not yet available.
22 func (t *Torrent) Info() *metainfo.InfoEx {
26 // Returns a Reader bound to the torrent's data. All read calls block until
27 // the data requested is actually available.
28 func (t *Torrent) NewReader() (ret *Reader) {
31 readahead: 5 * 1024 * 1024,
37 // Returns the state of pieces of the torrent. They are grouped into runs of
38 // same state. The sum of the state run lengths is the number of pieces
40 func (t *Torrent) PieceStateRuns() []PieceStateRun {
42 defer t.cl.mu.Unlock()
43 return t.pieceStateRuns()
46 func (t *Torrent) PieceState(piece int) PieceState {
48 defer t.cl.mu.Unlock()
49 return t.pieceState(piece)
52 // The number of pieces in the torrent. This requires that the info has been
54 func (t *Torrent) NumPieces() int {
58 // Drop the torrent from the client, and close it. It's always safe to do
59 // this. No data corruption can, or should occur to either the torrent's data,
60 // or connected peers.
61 func (t *Torrent) Drop() {
63 t.cl.dropTorrent(t.infoHash)
67 // Number of bytes of the entire torrent we have completed.
68 func (t *Torrent) BytesCompleted() int64 {
70 defer t.cl.mu.RUnlock()
71 return t.bytesCompleted()
74 // The subscription emits as (int) the index of pieces as their state changes.
75 // A state change is when the PieceState for a piece alters in value.
76 func (t *Torrent) SubscribePieceStateChanges() *pubsub.Subscription {
77 return t.pieceStateChanges.Subscribe()
80 // Returns true if the torrent is currently being seeded. This occurs when the
81 // client is willing to upload without wanting anything in return.
82 func (t *Torrent) Seeding() bool {
84 defer t.cl.mu.Unlock()
85 return t.cl.seeding(t)
88 // Clobbers the torrent display name. The display name is used as the torrent
89 // name if the metainfo is not available.
90 func (t *Torrent) SetDisplayName(dn string) {
92 defer t.cl.mu.Unlock()
96 // The current working name for the torrent. Either the name in the info dict,
97 // or a display name given such as by the dn value in a magnet link, or "".
98 func (t *Torrent) Name() string {
100 defer t.cl.mu.Unlock()
104 // The completed length of all the torrent data, in all its files. This is
105 // derived from the torrent info, when it is available.
106 func (t *Torrent) Length() int64 {
115 // Returns a run-time generated metainfo for the torrent that includes the
116 // info bytes and announce-list as currently known to the client.
117 func (t *Torrent) Metainfo() *metainfo.MetaInfo {
119 defer t.cl.mu.Unlock()
123 func (t *Torrent) addReader(r *Reader) {
125 defer t.cl.mu.Unlock()
126 if t.readers == nil {
127 t.readers = make(map[*Reader]struct{})
129 t.readers[r] = struct{}{}
133 func (t *Torrent) deleteReader(r *Reader) {
135 defer t.cl.mu.Unlock()
140 func (t *Torrent) DownloadPieces(begin, end int) {
142 defer t.cl.mu.Unlock()
143 t.pendPieceRange(begin, end)
146 func (t *Torrent) CancelPieces(begin, end int) {
148 defer t.cl.mu.Unlock()
149 t.unpendPieceRange(begin, end)