cmd/torrent-pick/main.go | 5 +---- cmd/torrent/main.go | 26 +++++++++++++------------- cmd/torrentfs/main.go | 12 ++++-------- t.go | 3 +-- diff --git a/cmd/torrent-pick/main.go b/cmd/torrent-pick/main.go index e8a25ad2278f977c96508bece61a3b2fbe7ebf1a..be590b8b4401bf1a97d80afb09b86663b384f083 100644 --- a/cmd/torrent-pick/main.go +++ b/cmd/torrent-pick/main.go @@ -154,10 +154,7 @@ } return t } }() - err := t.AddPeers(testPeers) - if err != nil { - log.Fatal(err) - } + t.AddPeers(testPeers) go func() { defer close(done) diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 55c68c9f92cb977f90a78e2c48249b1abfcad3b3..39edca57a0fc6555412106df4419ad87e5c748f6 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -67,7 +67,7 @@ }() } func addTorrents(client *torrent.Client) { - for _, arg := range opts.Torrent { + for _, arg := range flags.Torrent { t := func() *torrent.Torrent { if strings.HasPrefix(arg, "magnet:") { t, err := client.AddMagnet(arg) @@ -89,8 +89,8 @@ return t } }() torrentBar(t) - err := t.AddPeers(func() (ret []torrent.Peer) { - for _, ta := range opts.TestPeer { + t.AddPeers(func() (ret []torrent.Peer) { + for _, ta := range flags.TestPeer { ret = append(ret, torrent.Peer{ IP: ta.IP, Port: ta.Port, @@ -98,9 +98,6 @@ }) } return }()) - if err != nil { - log.Fatal(err) - } go func() { <-t.GotInfo() t.DownloadAll() @@ -108,24 +105,24 @@ }() } } -var opts struct { +var flags struct { Mmap bool `help:"memory-map torrent data"` TestPeer []*net.TCPAddr `short:"p" help:"addresses of some starting peers"` Seed bool `help:"seed after download is complete"` Addr *net.TCPAddr `help:"network listen addr"` tagflag.StartPos - Torrent []string `type:"pos" arity:"+" help:"torrent file path or magnet uri"` + Torrent []string `arity:"+" help:"torrent file path or magnet uri"` } func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) - tagflag.Parse(&opts) + tagflag.Parse(&flags) var clientConfig torrent.Config - if opts.Mmap { + if flags.Mmap { clientConfig.DefaultStorage = storage.NewMMap("") } - if opts.Addr != nil { - clientConfig.ListenAddr = opts.Addr.String() + if flags.Addr != nil { + clientConfig.ListenAddr = flags.Addr.String() } client, err := torrent.NewClient(&clientConfig) @@ -133,6 +130,9 @@ if err != nil { log.Fatalf("error creating client: %s", err) } defer client.Close() + // Write status on the root path on the default HTTP muxer. This will be + // bound to localhost somewhere if GOPPROF is set, thanks to the envpprof + // import. http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { client.WriteStatus(w) }) @@ -143,7 +143,7 @@ log.Print("downloaded ALL the torrents") } else { log.Fatal("y u no complete torrents?!") } - if opts.Seed { + if flags.Seed { select {} } } diff --git a/cmd/torrentfs/main.go b/cmd/torrentfs/main.go index 1e1c61985821ff260262f80d6d40b83d25fc98eb..13f7c18a28db51c918f709857192c60223c67cf8 100644 --- a/cmd/torrentfs/main.go +++ b/cmd/torrentfs/main.go @@ -68,14 +68,10 @@ } func addTestPeer(client *torrent.Client) { for _, t := range client.Torrents() { - if testPeerAddr != nil { - if err := t.AddPeers([]torrent.Peer{{ - IP: testPeerAddr.IP, - Port: testPeerAddr.Port, - }}); err != nil { - log.Print(err) - } - } + t.AddPeers([]torrent.Peer{{ + IP: testPeerAddr.IP, + Port: testPeerAddr.Port, + }}) } } diff --git a/t.go b/t.go index 9a726a7713d58f6e22d386d66afb174f74eefb74..899f759f9dc1bb68477fd52befac1ecd7bfcde36 100644 --- a/t.go +++ b/t.go @@ -175,12 +175,11 @@ } return } -func (t *Torrent) AddPeers(pp []Peer) error { +func (t *Torrent) AddPeers(pp []Peer) { cl := t.cl cl.mu.Lock() defer cl.mu.Unlock() cl.addPeers(t, pp) - return nil } // Marks the entire torrent for download. Requires the info first, see