]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Don't send keepalives if a connection isn't useful to us
authorMatt Joiner <anacrolix@gmail.com>
Thu, 10 Dec 2020 00:13:27 +0000 (11:13 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 10 Dec 2020 00:13:45 +0000 (11:13 +1100)
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

index 633e54ce49a16658c7e16085dbf7fa7c43b04199..e333d21372b036d334e2769b429b904b55b638c8 100644 (file)
@@ -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)
                }