client.go | 5 +++-- global.go | 1 - peerconn.go | 5 +++-- diff --git a/client.go b/client.go index 8544d4e3eb535a7d6266f0ae077244e024f44a13..9300b24b23c4c94e8b99497023ccb3c4339fb458 100644 --- a/client.go +++ b/client.go @@ -969,8 +969,9 @@ } 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. diff --git a/global.go b/global.go index 1a09b06e6b4d6dbd96cd018a6522721429af593b..e06d93230428a2ac08c5538a0ea09821492386cc 100644 --- a/global.go +++ b/global.go @@ -9,7 +9,6 @@ ) const ( pieceHash = crypto.SHA1 - maxRequests = 250 // Maximum pending requests we allow peers to send us. defaultChunkSize = 0x4000 // 16KiB ) diff --git a/peerconn.go b/peerconn.go index a5d078e00c1743f0e26cea63366ec4c8c3fb5f2a..71ac5f3d252a230d4b7bbed38ae9033e41d30e52 100644 --- a/peerconn.go +++ b/peerconn.go @@ -989,7 +989,8 @@ c.reject(r) } 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) @@ -1010,7 +1011,7 @@ torrent.Add("bad requests received", 1) 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