peerconn.go | 23 ++++++++++++++++++++--- torrent.go | 8 +++++++- webseed-peer.go | 5 +++++ diff --git a/peerconn.go b/peerconn.go index 4ec0944ba7090f3a9ede320a3873488e0610728e..0083a0735879d6215958c7308988f5bf910cf6e8 100644 --- a/peerconn.go +++ b/peerconn.go @@ -1095,7 +1095,13 @@ if c.peerChoking { 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 @@ panic("only one peer should have a given request at a time") } 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()) } diff --git a/torrent.go b/torrent.go index c41b213b21fdc1ee304ae8a7c855b568bf9d0c75..5c8dca25d58db702d5eba5e4cb5c0b663c565d44 100644 --- a/torrent.go +++ b/torrent.go @@ -1396,7 +1396,13 @@ t.pex.Drop(c) } } 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 } diff --git a/webseed-peer.go b/webseed-peer.go index 221aa53fe71cca0253759de957185a5021f43140..08a7be2cbc86c86cf7b131ff5240ce016ea6eed4 100644 --- a/webseed-peer.go +++ b/webseed-peer.go @@ -133,6 +133,11 @@ ws.peer.deleteAllRequests() for _, r := range ws.activeRequests { r.Cancel() } + ws.peer.t.iterPeers(func(p *Peer) { + if p.isLowOnRequests() { + p.updateRequests("webseedPeer.onClose") + } + }) ws.requesterCond.Broadcast() }