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.
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)
}