]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Torrent.AddPeers can't fail, so don't return an error
authorMatt Joiner <anacrolix@gmail.com>
Thu, 12 May 2016 02:26:09 +0000 (12:26 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 12 May 2016 02:26:09 +0000 (12:26 +1000)
cmd/torrent-pick/main.go
cmd/torrent/main.go
cmd/torrentfs/main.go
t.go

index e8a25ad2278f977c96508bece61a3b2fbe7ebf1a..be590b8b4401bf1a97d80afb09b86663b384f083 100644 (file)
@@ -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)
index 55c68c9f92cb977f90a78e2c48249b1abfcad3b3..39edca57a0fc6555412106df4419ad87e5c748f6 100644 (file)
@@ -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 {}
        }
 }
index 1e1c61985821ff260262f80d6d40b83d25fc98eb..13f7c18a28db51c918f709857192c60223c67cf8 100644 (file)
@@ -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 9a726a7713d58f6e22d386d66afb174f74eefb74..899f759f9dc1bb68477fd52befac1ecd7bfcde36 100644 (file)
--- 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