]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Merge maxRequests into localClientReqq
authorMatt Joiner <anacrolix@gmail.com>
Wed, 19 May 2021 22:34:20 +0000 (08:34 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 7 Jun 2021 03:01:39 +0000 (13:01 +1000)
client.go
global.go
peerconn.go

index 8544d4e3eb535a7d6266f0ae077244e024f44a13..9300b24b23c4c94e8b99497023ccb3c4339fb458 100644 (file)
--- a/client.go
+++ b/client.go
@@ -969,8 +969,9 @@ func (cl *Client) runHandshookConn(c *PeerConn, t *Torrent) error {
        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.
index 1a09b06e6b4d6dbd96cd018a6522721429af593b..e06d93230428a2ac08c5538a0ea09821492386cc 100644 (file)
--- a/global.go
+++ b/global.go
@@ -9,7 +9,6 @@ import (
 
 const (
        pieceHash        = crypto.SHA1
-       maxRequests      = 250    // Maximum pending requests we allow peers to send us.
        defaultChunkSize = 0x4000 // 16KiB
 )
 
index a5d078e00c1743f0e26cea63366ec4c8c3fb5f2a..71ac5f3d252a230d4b7bbed38ae9033e41d30e52 100644 (file)
@@ -989,7 +989,8 @@ func (c *PeerConn) onReadRequest(r Request) error {
                }
                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 @@ func (c *PeerConn) onReadRequest(r Request) error {
                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