From de964db3c2ebdf439722c23f797a78c43fd8f6c2 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 10 Dec 2020 11:13:27 +1100 Subject: [PATCH] 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. --- peerconn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) } -- 2.48.1