Limit outstanding requests

This commit is contained in:
Matt Joiner 2021-05-09 14:41:03 +10:00
parent 0830589b0a
commit b2c68b314b
2 changed files with 4 additions and 2 deletions

View 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")
}

View 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
}
}