From: Matt Joiner <anacrolix@gmail.com>
Date: Mon, 8 Feb 2016 05:09:12 +0000 (+1100)
Subject: Reintroduce 64 outbound request cap
X-Git-Tag: v1.0.0~902
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=3df7d6183629d854fbd0fe9c51dedca3ea411352;p=btrtrc.git

Reintroduce 64 outbound request cap
---

diff --git a/connection.go b/connection.go
index 2340e5e2..a3e6041a 100644
--- a/connection.go
+++ b/connection.go
@@ -299,9 +299,18 @@ func (c *connection) requestedMetadataPiece(index int) bool {
 	return index < len(c.metadataRequests) && c.metadataRequests[index]
 }
 
+// The actual value to use as the maximum outbound requests.
+func (c *connection) nominalMaxRequests() (ret int) {
+	ret = c.PeerMaxRequests
+	if ret > 64 {
+		ret = 64
+	}
+	return
+}
+
 // Returns true if more requests can be sent.
 func (c *connection) Request(chunk request) bool {
-	if len(c.Requests) >= c.PeerMaxRequests {
+	if len(c.Requests) >= c.nominalMaxRequests() {
 		return false
 	}
 	if !c.PeerHasPiece(int(chunk.Index)) {