From: Matt Joiner Date: Thu, 10 Dec 2020 00:13:27 +0000 (+1100) Subject: Don't send keepalives if a connection isn't useful to us X-Git-Tag: v1.19.0~2 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=de964db3c2ebdf439722c23f797a78c43fd8f6c2;p=btrtrc.git Don't send keepalives if a connection isn't useful to us This might help break the situation where anacrolix/torrent Clients that are connected to each other never release a connection until there's new connections that look more promising. --- diff --git a/peerconn.go b/peerconn.go index 633e54ce..e333d213 100644 --- a/peerconn.go +++ b/peerconn.go @@ -663,7 +663,7 @@ func (cn *PeerConn) writer(keepAliveTimeout time.Duration) { if cn.writeBuffer.Len() == 0 { cn.fillWriteBuffer() } - if cn.writeBuffer.Len() == 0 && time.Since(lastWrite) >= keepAliveTimeout { + if cn.writeBuffer.Len() == 0 && time.Since(lastWrite) >= keepAliveTimeout && cn.useful() { cn.writeBuffer.Write(pp.Message{Keepalive: true}.MustMarshalBinary()) postedKeepalives.Add(1) }