peerconn.go | 13 +++++++++---- diff --git a/peerconn.go b/peerconn.go index a387e1e6b2589e6d7a127919b7437f5c6c498c09..c54be39faa51aea43335678606fb11986fd2b7f6 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1425,10 +1425,15 @@ return cn._stats.PiecesDirtiedGood.Int64() - cn._stats.PiecesDirtiedBad.Int64() } func (c *Peer) peerHasWantedPieces() bool { - // TODO: Can this be done just with AndCardinality? - missingPeerHas := c.newPeerPieces() - missingPeerHas.AndNot(&c.t._completedPieces) - return !missingPeerHas.IsEmpty() + if c.peerSentHaveAll { + return !c.t.haveAllPieces() + } + if !c.t.haveInfo() { + return c._peerPieces.GetCardinality() != 0 + } + return c._peerPieces.Intersects( + roaring.FlipInt(&c.t._completedPieces, 0, c.t.numPieces()), + ) } func (c *Peer) deleteRequest(r RequestIndex) bool {