From: Matt Joiner Date: Thu, 16 Apr 2020 02:00:49 +0000 (+1000) Subject: Don't try to do conventional dials if we have no dialers X-Git-Tag: v1.16.0~77 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=74986db9ed33a163416583b0a5750dbd083eb5da;p=btrtrc.git Don't try to do conventional dials if we have no dialers Stops us from consuming all the peers we store for no reason. --- diff --git a/client.go b/client.go index da45ec09..36ad98b4 100644 --- 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 diff --git a/torrent.go b/torrent.go index 1cd5e257..872c9102 100644 --- a/torrent.go +++ b/torrent.go @@ -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) }