Update requests after deleting all in some corner cases
Choked by non-fast PeerConn, deleted PeerConn. They're not exactly guarded as strictly as they could be, so there's plenty of room for performance improvements here.
This commit is contained in:
parent
47ef8d9c2d
commit
98f188dcbe
23
peerconn.go
23
peerconn.go
|
@ -1095,7 +1095,13 @@ func (c *PeerConn) mainReadLoop() (err error) {
|
|||
break
|
||||
}
|
||||
if !c.fastEnabled() {
|
||||
c.deleteAllRequests()
|
||||
if !c.deleteAllRequests().IsEmpty() {
|
||||
c.t.iterPeers(func(p *Peer) {
|
||||
if p.isLowOnRequests() {
|
||||
p.updateRequests("choked by non-fast PeerConn")
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// We don't decrement pending requests here, let's wait for the peer to either
|
||||
// reject or satisfy the outstanding requests. Additionally, some peers may unchoke
|
||||
|
@ -1554,16 +1560,27 @@ func (c *Peer) deleteRequest(r RequestIndex) bool {
|
|||
}
|
||||
delete(c.t.pendingRequests, r)
|
||||
delete(c.t.lastRequested, r)
|
||||
// c.t.iterPeers(func(p *Peer) {
|
||||
// if p.isLowOnRequests() {
|
||||
// p.updateRequests("Peer.deleteRequest")
|
||||
// }
|
||||
// })
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Peer) deleteAllRequests() {
|
||||
c.requestState.Requests.Clone().Iterate(func(x uint32) bool {
|
||||
func (c *Peer) deleteAllRequests() (deleted *roaring.Bitmap) {
|
||||
deleted = c.requestState.Requests.Clone()
|
||||
deleted.Iterate(func(x uint32) bool {
|
||||
if !c.deleteRequest(x) {
|
||||
panic("request should exist")
|
||||
}
|
||||
return true
|
||||
})
|
||||
c.assertNoRequests()
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Peer) assertNoRequests() {
|
||||
if !c.requestState.Requests.IsEmpty() {
|
||||
panic(c.requestState.Requests.GetCardinality())
|
||||
}
|
||||
|
|
|
@ -1396,7 +1396,13 @@ func (t *Torrent) deletePeerConn(c *PeerConn) (ret bool) {
|
|||
}
|
||||
}
|
||||
torrent.Add("deleted connections", 1)
|
||||
c.deleteAllRequests()
|
||||
if !c.deleteAllRequests().IsEmpty() {
|
||||
t.iterPeers(func(p *Peer) {
|
||||
if p.isLowOnRequests() {
|
||||
p.updateRequests("Torrent.deletePeerConn")
|
||||
}
|
||||
})
|
||||
}
|
||||
t.assertPendingRequests()
|
||||
return
|
||||
}
|
||||
|
|
|
@ -133,6 +133,11 @@ func (ws *webseedPeer) onClose() {
|
|||
for _, r := range ws.activeRequests {
|
||||
r.Cancel()
|
||||
}
|
||||
ws.peer.t.iterPeers(func(p *Peer) {
|
||||
if p.isLowOnRequests() {
|
||||
p.updateRequests("webseedPeer.onClose")
|
||||
}
|
||||
})
|
||||
ws.requesterCond.Broadcast()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue