Don't error receiving unchoke while already unchoked

This commit is contained in:
Matt Joiner 2021-10-19 13:36:37 +11:00
parent b50e941d1d
commit e51accb3e2
1 changed files with 10 additions and 1 deletions

View 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