From: Matt Joiner Date: Thu, 12 May 2016 02:26:09 +0000 (+1000) Subject: Torrent.AddPeers can't fail, so don't return an error X-Git-Tag: v1.0.0~732 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b714da8184e8032bb932117160f9bdded6853c5c;p=btrtrc.git Torrent.AddPeers can't fail, so don't return an error --- diff --git a/cmd/torrent-pick/main.go b/cmd/torrent-pick/main.go index e8a25ad2..be590b8b 100644 --- a/cmd/torrent-pick/main.go +++ b/cmd/torrent-pick/main.go @@ -154,10 +154,7 @@ func main() { 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 55c68c9f..39edca57 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -67,7 +67,7 @@ func torrentBar(t *torrent.Torrent) { } 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 @@ func addTorrents(client *torrent.Client) { } }() 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 @@ func addTorrents(client *torrent.Client) { } return }()) - if err != nil { - log.Fatal(err) - } go func() { <-t.GotInfo() t.DownloadAll() @@ -108,24 +105,24 @@ func addTorrents(client *torrent.Client) { } } -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 @@ func main() { 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 @@ func main() { } 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 1e1c6198..13f7c18a 100644 --- a/cmd/torrentfs/main.go +++ b/cmd/torrentfs/main.go @@ -68,14 +68,10 @@ func exitSignalHandlers(fs *torrentfs.TorrentFS) { 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 9a726a77..899f759f 100644 --- a/t.go +++ b/t.go @@ -175,12 +175,11 @@ func (t *Torrent) Files() (ret []File) { 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