From: Matt Joiner Date: Fri, 5 Dec 2014 06:58:43 +0000 (-0600) Subject: Set a low water mark for replenishing requests X-Git-Tag: v1.0.0~1414 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=3c41002317cde2fc9e0b01d5b5dc10efb2ed4f3b;p=btrtrc.git Set a low water mark for replenishing requests --- diff --git a/connection.go b/connection.go index ea4295de..f8855aee 100644 --- a/connection.go +++ b/connection.go @@ -47,9 +47,10 @@ type connection struct { 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 @@ func (c *connection) Request(chunk request) bool { 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 572eadba..d3f38e98 100644 --- a/download_strategies.go +++ b/download_strategies.go @@ -38,7 +38,7 @@ func (s *DefaultDownloadStrategy) FillRequests(t *torrent, c *connection) { if c.PeerChoked { return } - if len(c.Requests) != 0 { + if len(c.Requests) > c.requestsLowWater { return } }