config.go | 4 ++++ peer-conn-msg-writer.go | 2 +- testing.go | 2 ++ diff --git a/config.go b/config.go index 845a16b5f53f4b15f5c686639044e346cab641fc..1895f3c37aa715a5d050c481fb08d29691351b87 100644 --- a/config.go +++ b/config.go @@ -118,6 +118,9 @@ // Limit how long handshake can take. This is to reduce the lingering // impact of a few bad apples. 4s loses 1% of successful handshakes that // are obtained with 60s timeout, and 5% of unsuccessful handshakes. HandshakesTimeout time.Duration + // How long between writes before sending a keep alive message on a peer connection that we want + // to maintain. + KeepAliveTimeout time.Duration // The IP addresses as our peers should see them. May differ from the // local interfaces due to NAT or other network configurations. @@ -170,6 +173,7 @@ TotalHalfOpenConns: 100, TorrentPeersHighWater: 500, TorrentPeersLowWater: 50, HandshakesTimeout: 4 * time.Second, + KeepAliveTimeout: time.Minute, DhtStartingNodes: func(network string) dht.StartingNodesGetter { return func() ([]dht.Addr, error) { return dht.GlobalBootstrapAddrs(network) } }, diff --git a/peer-conn-msg-writer.go b/peer-conn-msg-writer.go index 40fc27ef122e83a70b49a861fb26fc94a4c1b6a8..293c838896ba08d6de01f75c45e8c6e8ecdd7a06 100644 --- a/peer-conn-msg-writer.go +++ b/peer-conn-msg-writer.go @@ -37,7 +37,7 @@ go func() { defer pc.locker().Unlock() defer pc.close() defer pc.locker().Lock() - pc.messageWriter.run(time.Minute) + pc.messageWriter.run(pc.t.cl.config.KeepAliveTimeout) }() } diff --git a/testing.go b/testing.go index 01e728578fb902fb0ab7325b906431fdd09a0452..ed8251453de2697e156883d0b5b92574414b0855 100644 --- a/testing.go +++ b/testing.go @@ -2,6 +2,7 @@ package torrent import ( "testing" + "time" ) func TestingConfig(t testing.TB) *ClientConfig { @@ -13,6 +14,7 @@ cfg.DisableTrackers = true cfg.NoDefaultPortForwarding = true cfg.DisableAcceptRateLimiting = true cfg.ListenPort = 0 + cfg.KeepAliveTimeout = time.Microsecond //cfg.Debug = true //cfg.Logger = cfg.Logger.WithText(func(m log.Msg) string { // t := m.Text()