--- /dev/null
+.idea/
\ No newline at end of file
}
// Returns a handle to the given torrent, if it's present in the client.
-func (cl *Client) Torrent(ih InfoHash) (T Torrent, ok bool) {
+func (cl *Client) Torrent(ih InfoHash) (T Download, ok bool) {
cl.mu.Lock()
defer cl.mu.Unlock()
t, ok := cl.torrents[ih]
// trackers will be merged with the existing ones. If the Info isn't yet
// known, it will be set. The display name is replaced if the new spec
// provides one. Returns new if the torrent wasn't already in the client.
-func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (T Torrent, new bool, err error) {
+func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (D Download, new bool, err error) {
+ T := Torrent{}
T.cl = cl
+ D = &T
cl.mu.Lock()
defer cl.mu.Unlock()
}
// Returns handles to all the torrents loaded in the Client.
-func (me *Client) Torrents() (ret []Torrent) {
+func (me *Client) Torrents() (ret []Download) {
me.mu.Lock()
for _, t := range me.torrents {
ret = append(ret, Torrent{me, t})
return
}
-func (me *Client) AddMagnet(uri string) (T Torrent, err error) {
+func (me *Client) AddMagnet(uri string) (T Download, err error) {
spec, err := TorrentSpecFromMagnetURI(uri)
if err != nil {
return
return
}
-func (me *Client) AddTorrent(mi *metainfo.MetaInfo) (T Torrent, err error) {
+func (me *Client) AddTorrent(mi *metainfo.MetaInfo) (T Download, err error) {
T, _, err = me.AddTorrentSpec(TorrentSpecFromMetaInfo(mi))
return
}
-func (me *Client) AddTorrentFromFile(filename string) (T Torrent, err error) {
+func (me *Client) AddTorrentFromFile(filename string) (T Download, err error) {
mi, err := metainfo.LoadFromFile(filename)
if err != nil {
return
// TODO: The piece state publishing is kinda jammed in here until I have a
// more thorough test.
go func() {
- s := leecherGreeting.pieceStateChanges.Subscribe()
+ s := leecherGreeting.SubscribePieceStateChanges()
defer s.Close()
for i := range s.Values {
log.Print(i)
if new {
t.FailNow()
}
- assert.EqualValues(t, T.Trackers[0][0].URL(), "http://a")
- assert.EqualValues(t, T.Trackers[1][0].URL(), "udp://b")
+ assert.EqualValues(t, T.Trackers()[0][0].URL(), "http://a")
+ assert.EqualValues(t, T.Trackers()[1][0].URL(), "udp://b")
}
type badData struct{}
--- /dev/null
+package torrent
+
+import(
+ "github.com/anacrolix/torrent/metainfo"
+ "github.com/anacrolix/missinggo/pubsub"
+ "github.com/anacrolix/torrent/tracker"
+)
+
+type Download interface {
+ InfoHash() InfoHash
+ GotInfo() <-chan struct{}
+ Info() *metainfo.Info
+ NewReader() (ret *Reader)
+ PieceStateRuns() []PieceStateRun
+ NumPieces() int
+ Drop()
+ BytesCompleted() int64
+ SubscribePieceStateChanges() *pubsub.Subscription
+ Seeding() bool
+ SetDisplayName(dn string)
+ Client() *Client
+ AddPeers(pp []Peer) error
+ DownloadAll()
+ Trackers() [][]tracker.Client
+}
\ No newline at end of file
fi metainfo.FileInfo
}
-func (f *File) Torrent() Torrent {
+func (f *File) Torrent() Download {
return f.t
}
import (
"github.com/anacrolix/missinggo/pubsub"
-
+ "github.com/anacrolix/torrent/tracker"
"github.com/anacrolix/torrent/metainfo"
)
defer t.cl.mu.Unlock()
t.torrent.setDisplayName(dn)
}
+
+// Client returns Torrent's client instance
+func (t Torrent) Client() *Client {
+ return t.cl
+}
+
+// Trackers returns torrent's trackers
+func (t Torrent) Trackers() [][]tracker.Client {
+ return t.torrent.Trackers
+}
\ No newline at end of file