connection.go | 8 +++++--- download_strategies.go | 2 +- diff --git a/connection.go b/connection.go index ea4295dee483d14be9e9d3bc25a4abaf57e8f4cf..f8855aeedc7ddbfdae43dea235ad0948b9d2eea3 100644 --- a/connection.go +++ b/connection.go @@ -47,9 +47,10 @@ completedHandshake time.Time lastUsefulChunkReceived time.Time // Stuff controlled by the local peer. - Interested bool - Choked bool - Requests map[request]struct{} + Interested bool + Choked bool + Requests map[request]struct{} + requestsLowWater int // Stuff controlled by the remote peer. PeerID [20]byte @@ -248,6 +249,7 @@ if c.Requests == nil { c.Requests = make(map[request]struct{}, c.PeerMaxRequests) } c.Requests[chunk] = struct{}{} + c.requestsLowWater = len(c.Requests) / 2 c.Post(pp.Message{ Type: pp.Request, Index: chunk.Index, diff --git a/download_strategies.go b/download_strategies.go index 572eadba3ccbd6ca78a66bde7541e4cd12fa3bb2..d3f38e98e4a70ad931936a81bcac53e22c65969d 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -38,7 +38,7 @@ if c.Interested { if c.PeerChoked { return } - if len(c.Requests) != 0 { + if len(c.Requests) > c.requestsLowWater { return } }