Limit outstanding requests
This commit is contained in:
parent
0830589b0a
commit
b2c68b314b
|
@ -533,6 +533,9 @@ func (cn *Peer) request(r Request) (more bool, err error) {
|
||||||
if _, ok := cn.requests[r]; ok {
|
if _, ok := cn.requests[r]; ok {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
if cn.numLocalRequests() >= cn.nominalMaxRequests() {
|
||||||
|
return true, errors.New("too many outstanding requests")
|
||||||
|
}
|
||||||
if !cn.peerHasPiece(pieceIndex(r.Index)) {
|
if !cn.peerHasPiece(pieceIndex(r.Index)) {
|
||||||
return true, errors.New("requesting piece peer doesn't have")
|
return true, errors.New("requesting piece peer doesn't have")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/anacrolix/log"
|
|
||||||
"github.com/anacrolix/multiless"
|
"github.com/anacrolix/multiless"
|
||||||
pp "github.com/anacrolix/torrent/peer_protocol"
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
||||||
"github.com/bradfitz/iter"
|
"github.com/bradfitz/iter"
|
||||||
|
@ -115,7 +114,7 @@ func (cl *Client) doRequests() {
|
||||||
req := Request{pp.Integer(p.index), chunk}
|
req := Request{pp.Integer(p.index), chunk}
|
||||||
_, err := peer.request(req)
|
_, err := peer.request(req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("requested %v", req)
|
//log.Printf("requested %v", req)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue