return nil
}
-// If peer requests are buffered on read, this instructs the amount of memory that might be used to
-// cache pending writes. Assuming 512KiB cached for sending, for 16KiB chunks.
+// Maximum pending requests we allow peers to send us. If peer requests are buffered on read, this
+// instructs the amount of memory that might be used to cache pending writes. Assuming 512KiB
+// (1<<19) cached for sending, for 16KiB (1<<14) chunks.
const localClientReqq = 1 << 5
// See the order given in Transmission's tr_peerMsgsNew.
const (
pieceHash = crypto.SHA1
- maxRequests = 250 // Maximum pending requests we allow peers to send us.
defaultChunkSize = 0x4000 // 16KiB
)
}
return nil
}
- if len(c.peerRequests) >= maxRequests {
+ // TODO: What if they've already requested this?
+ if len(c.peerRequests) >= localClientReqq {
torrent.Add("requests received while queue full", 1)
if c.fastEnabled() {
c.reject(r)
return errors.New("bad Request")
}
if c.peerRequests == nil {
- c.peerRequests = make(map[Request]*peerRequestState, maxRequests)
+ c.peerRequests = make(map[Request]*peerRequestState, localClientReqq)
}
value := &peerRequestState{}
c.peerRequests[r] = value