From 74986db9ed33a163416583b0a5750dbd083eb5da Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 16 Apr 2020 12:00:49 +1000 Subject: [PATCH] Don't try to do conventional dials if we have no dialers Stops us from consuming all the peers we store for no reason. --- client.go | 5 +++++ torrent.go | 3 +++ 2 files changed, 8 insertions(+) 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) } -- 2.50.0