From 3c41002317cde2fc9e0b01d5b5dc10efb2ed4f3b Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 5 Dec 2014 00:58:43 -0600 Subject: [PATCH] Set a low water mark for replenishing requests --- connection.go | 8 +++++--- download_strategies.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) 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 } } -- 2.48.1