From b2c68b314bb62ef831a83e4fefbf21bb8bddaa1e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 9 May 2021 14:41:03 +1000 Subject: [PATCH] Limit outstanding requests --- peerconn.go | 3 +++ request-strategy.go | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/peerconn.go b/peerconn.go index 9522adf3..1ce06994 100644 --- a/peerconn.go +++ b/peerconn.go @@ -533,6 +533,9 @@ func (cn *Peer) request(r Request) (more bool, err error) { if _, ok := cn.requests[r]; ok { return true, nil } + if cn.numLocalRequests() >= cn.nominalMaxRequests() { + return true, errors.New("too many outstanding requests") + } if !cn.peerHasPiece(pieceIndex(r.Index)) { return true, errors.New("requesting piece peer doesn't have") } diff --git a/request-strategy.go b/request-strategy.go index 62e7174f..d762d0f5 100644 --- a/request-strategy.go +++ b/request-strategy.go @@ -4,7 +4,6 @@ import ( "sort" "time" - "github.com/anacrolix/log" "github.com/anacrolix/multiless" pp "github.com/anacrolix/torrent/peer_protocol" "github.com/bradfitz/iter" @@ -115,7 +114,7 @@ func (cl *Client) doRequests() { req := Request{pp.Integer(p.index), chunk} _, err := peer.request(req) if err == nil { - log.Printf("requested %v", req) + //log.Printf("requested %v", req) break } }