return roaring.Flip(&cn._peerPieces, 0, bitmap.BitRange(cn.t.numPieces())).IsEmpty(), true
}
-func (cn *PeerConn) locker() *lockWithDeferreds {
+func (cn *Peer) locker() *lockWithDeferreds {
return cn.t.cl.locker()
}
if !p.closed.Set() {
return
}
+ if p.updateRequestsTimer != nil {
+ p.updateRequestsTimer.Stop()
+ }
p.peerImpl.onClose()
if p.t != nil {
p.t.decPeerPieceAvailability(p)
if cn.pex.IsEnabled() {
cn.pex.Close()
}
- if cn.updateRequestsTimer != nil {
- cn.updateRequestsTimer.Stop()
- }
cn.tickleWriter()
if cn.conn != nil {
cn.conn.Close()
}
func (cn *PeerConn) fillWriteBuffer() {
- if !cn.applyNextRequestState() {
+ if !cn.maybeUpdateActualRequestState() {
return
}
if cn.pex.IsEnabled() {
cn.sentHaves = bitmap.Bitmap{cn.t._completedPieces.Clone()}
}
-func (cn *PeerConn) updateRequests(reason string) {
+// Sets a reason to update requests, and if there wasn't already one, handle it.
+func (cn *Peer) updateRequests(reason string) {
if cn.needRequestUpdate != "" {
return
}
cn.needRequestUpdate = reason
+ cn.handleUpdateRequests()
+}
+
+func (cn *PeerConn) handleUpdateRequests() {
+ // The writer determines the request state as needed when it can write.
cn.tickleWriter()
}