]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't try to do conventional dials if we have no dialers
authorMatt Joiner <anacrolix@gmail.com>
Thu, 16 Apr 2020 02:00:49 +0000 (12:00 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 16 Apr 2020 02:00:49 +0000 (12:00 +1000)
Stops us from consuming all the peers we store for no reason.

client.go
torrent.go

index da45ec093e3a86c11c45d0370cef83eb6e83757a..36ad98b42df52849bd303de69741ce50bd52850d 100644 (file)
--- a/client.go
+++ b/client.go
@@ -257,7 +257,12 @@ func (cl *Client) AddDhtServer(d DhtServer) {
 // Adds a Dialer for outgoing connections. All Dialers are used when attempting to connect to a
 // given address for any Torrent.
 func (cl *Client) AddDialer(d Dialer) {
+       cl.lock()
+       defer cl.unlock()
        cl.dialers = append(cl.dialers, d)
+       for _, t := range cl.torrents {
+               t.openNewConns()
+       }
 }
 
 // Registers a Listener, and starts Accepting on it. You must Close Listeners provided this way
index 1cd5e257b668fc208705f9a096c01f8fbc021e00..872c9102e40a94908628cc0b3c0d1b70e9495d78 100644 (file)
@@ -1065,6 +1065,9 @@ func (t *Torrent) openNewConns() {
                if len(t.halfOpen) >= t.maxHalfOpen() {
                        return
                }
+               if len(t.cl.dialers) == 0 {
+                       return
+               }
                p := t.peers.PopMax()
                t.initiateConn(p)
        }