2
0
mirror of synced 2025-02-24 22:58:28 +00:00
torrent/t.go

65 lines
1.5 KiB
Go
Raw Normal View History

package torrent
2015-04-28 15:24:17 +10:00
import (
"github.com/anacrolix/torrent/metainfo"
)
// The public interface for a torrent within a Client.
// A handle to a live torrent within a Client.
type Torrent struct {
cl *Client
*torrent
}
2015-08-02 03:55:48 +10:00
func (t Torrent) InfoHash() InfoHash {
return t.torrent.InfoHash
}
// Closed when the info (.Info()) for the torrent has become available. Using
// features of Torrent that require the info before it is available will have
// undefined behaviour.
func (t *Torrent) GotInfo() <-chan struct{} {
return t.torrent.gotMetainfo
2015-04-28 15:24:17 +10:00
}
func (t *Torrent) Info() *metainfo.Info {
return t.torrent.Info
}
2015-06-03 13:30:55 +10:00
// Returns a Reader bound to the torrent's data. All read calls block until
// the data requested is actually available. Priorities are set to ensure the
// data requested will be downloaded as soon as possible.
func (t *Torrent) NewReader() (ret *Reader) {
ret = &Reader{
t: t,
readahead: 5 * 1024 * 1024,
}
return
}
// Returns the state of pieces of the torrent. They are grouped into runs of
// same state. The sum of the state run lengths is the number of pieces
// in the torrent.
func (t *Torrent) PieceStateRuns() []PieceStateRun {
t.stateMu.Lock()
defer t.stateMu.Unlock()
return t.torrent.pieceStateRuns()
}
2015-06-23 02:02:22 +10:00
func (t Torrent) NumPieces() int {
return t.numPieces()
}
func (t Torrent) Drop() {
t.cl.mu.Lock()
2015-08-02 03:55:48 +10:00
t.cl.dropTorrent(t.torrent.InfoHash)
2015-06-23 02:02:22 +10:00
t.cl.mu.Unlock()
}
2015-07-21 22:54:02 +10:00
func (t Torrent) BytesCompleted() int64 {
t.cl.mu.RLock()
defer t.cl.mu.RUnlock()
return t.bytesCompleted()
}