From f621f0f5a842ae23381af15e83d3799915f392a2 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 28 Nov 2021 22:40:53 +1100 Subject: [PATCH] Don't want conns for seeding unless we have a piece --- torrent.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/torrent.go b/torrent.go index 2cf05b68..244d3281 100644 --- a/torrent.go +++ b/torrent.go @@ -1223,6 +1223,7 @@ func (t *Torrent) updatePieceCompletion(piece pieceIndex) bool { x := uint32(piece) if complete { t._completedPieces.Add(x) + t.openNewConns() } else { t._completedPieces.Remove(x) } @@ -1811,13 +1812,13 @@ func (t *Torrent) wantConns() bool { if t.closed.IsSet() { return false } - if !t.seeding() && !t.needData() { + if len(t.conns) >= t.maxEstablishedConns && t.worstBadConn() == nil { return false } - if len(t.conns) < t.maxEstablishedConns { + if t.seeding() && t.haveAnyPieces() { return true } - return t.worstBadConn() != nil + return t.needData() } func (t *Torrent) SetMaxEstablishedConns(max int) (oldMax int) {