client.go | 13 +++++++++---- diff --git a/client.go b/client.go index ba689c91a8f3d0016e0f419a503c22d4ae92d44b..d6ab47270503d319956b39200f413aeeb14b1c2c 100644 --- a/client.go +++ b/client.go @@ -1807,12 +1807,14 @@ // Actively prunes unused connections. This is required to make space to dial // for replacements. func (cl *Client) connectionPruner(t *torrent) { for { - time.Sleep(15 * time.Second) - cl.mu.Lock() select { case <-t.ceasingNetworking: - default: + return + case <-t.closing: + return + case <-time.After(15 * time.Second): } + cl.mu.Lock() license := len(t.Conns) - (socketsPerTorrent+1)/2 for _, c := range t.Conns { if license <= 0 { @@ -1923,7 +1925,7 @@ case <-t.ceasingNetworking: return false default: } - if len(t.Peers) < torrentPeersLowWater { + if len(t.Peers) < torrentPeersLowWater && t.needData() { return true } cl.mu.Unlock() @@ -2041,6 +2043,9 @@ NumWant: -1, Port: int16(cl.incomingPeerPort()), PeerId: cl.peerID, InfoHash: t.InfoHash, + } + if !cl.waitWantPeers(t) { + return } cl.mu.RLock() req.Left = t.BytesLeft()