From: Matt Joiner <anacrolix@gmail.com>
Date: Sat, 23 Jun 2018 12:32:11 +0000 (+1000)
Subject: Retain interest if requests are outstanding and don't clear peer requests if they... 
X-Git-Tag: v1.0.0~125
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=ad03e64722b4a076a6b73102c1bb438c5e26012d;p=btrtrc.git

Retain interest if requests are outstanding and don't clear peer requests if they send not_interested

Apparent shortcomings found when trying new request algorithms.
---

diff --git a/connection.go b/connection.go
index 21ebbf1b..e5075887 100644
--- a/connection.go
+++ b/connection.go
@@ -591,6 +591,9 @@ func nextRequestState(
 	if len(currentRequests) > requestsLowWater {
 		return false, nil, true
 	}
+	// If we have existing requests, better maintain interest to ensure we get
+	// them. iterPendingRequests might not iterate over outstanding requests.
+	interested = len(currentRequests) != 0
 	iterPendingRequests(func(r request) bool {
 		interested = true
 		if peerChoking {
@@ -1040,8 +1043,9 @@ func (c *connection) mainReadLoop() (err error) {
 			c.tickleWriter()
 		case pp.NotInterested:
 			c.PeerInterested = false
-			// TODO: Reject?
-			c.PeerRequests = nil
+			// We don't clear their requests since it isn't clear in the spec.
+			// We'll probably choke them for this, which will clear them if
+			// appropriate, and is clearly specified.
 		case pp.Have:
 			err = c.peerSentHave(int(msg.Index))
 		case pp.Request: