]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't error receiving unchoke while already unchoked
authorMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 02:36:37 +0000 (13:36 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 19 Oct 2021 03:08:56 +0000 (14:08 +1100)
peerconn.go

index 2d2722690368a5a4a8a133fc66c001caa0312f62..2b27706a20e9f4fea9310dc88685741e76ab2eab 100644 (file)
@@ -1006,6 +1006,12 @@ func runSafeExtraneous(f func()) {
        }
 }
 
+func (c *PeerConn) logProtocolBehaviour(level log.Level, format string, arg ...interface{}) {
+       c.logger.WithLevel(level).WithContextText(fmt.Sprintf(
+               "peer id %q, ext v %q", c.PeerID, c.PeerClientName,
+       )).Printf(format, arg...)
+}
+
 // Processes incoming BitTorrent wire-protocol messages. The client lock is held upon entry and
 // exit. Returning will end the connection.
 func (c *PeerConn) mainReadLoop() (err error) {
@@ -1071,7 +1077,10 @@ func (c *PeerConn) mainReadLoop() (err error) {
                        c.updateExpectingChunks()
                case pp.Unchoke:
                        if !c.peerChoking {
-                               return errors.New("got unchoke but not choked")
+                               // Some clients do this for some reason. Transmission doesn't error on this, so we
+                               // won't for consistency.
+                               c.logProtocolBehaviour(log.Info, "received unchoke when already unchoked")
+                               break
                        }
                        c.peerChoking = false
                        preservedCount := 0