Skip to content

Commit

Permalink
don't add conns when torrent is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
mh0lt committed Jul 14, 2024
1 parent 74f6e52 commit a6ac7dc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ func (t *Torrent) deletePeerConn(c *PeerConn, lock bool) (ret bool) {
torrent.Add("deleted connections", 1)
c.deleteAllRequests("Torrent.deletePeerConn", false)
t.assertPendingRequests(false)

if t.numActivePeers(false) == 0 && len(t.connsWithAllPieces) != 0 {
panic(fmt.Sprintf("no active peers, but %d conns with all", len(t.connsWithAllPieces)))
}
Expand Down Expand Up @@ -3392,6 +3393,10 @@ func (t *Torrent) addConnWithAllPieces(p *Peer, lock bool) {
defer t.mu.Unlock()
}

if t.haveAllPieces(false, true) {
return
}

if t.connsWithAllPieces == nil {
t.connsWithAllPieces = make(map[*Peer]struct{}, t.maxEstablishedConns)
}
Expand Down

0 comments on commit a6ac7dc

Please sign in to comment.