]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Set a low water mark for replenishing requests
authorMatt Joiner <anacrolix@gmail.com>
Fri, 5 Dec 2014 06:58:43 +0000 (00:58 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 5 Dec 2014 06:58:43 +0000 (00:58 -0600)
connection.go
download_strategies.go

index ea4295dee483d14be9e9d3bc25a4abaf57e8f4cf..f8855aeedc7ddbfdae43dea235ad0948b9d2eea3 100644 (file)
@@ -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,
index 572eadba3ccbd6ca78a66bde7541e4cd12fa3bb2..d3f38e98e4a70ad931936a81bcac53e22c65969d 100644 (file)
@@ -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
                }
        }