]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Limit outstanding requests
authorMatt Joiner <anacrolix@gmail.com>
Sun, 9 May 2021 04:41:03 +0000 (14:41 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 7 Jun 2021 03:01:39 +0000 (13:01 +1000)
peerconn.go
request-strategy.go

index 9522adf32a34584dadd13c207d2bec085f17d904..1ce06994d228996184ae750766e350706bb1cbdd 100644 (file)
@@ -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")
        }
index 62e7174f02c4929e87c4ad0775589b85bbcd628b..d762d0f5cfc1d37dd7722f7f46996b23356a529a 100644 (file)
@@ -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
                                }
                        }