client.go | 12 ++++++++---- diff --git a/client.go b/client.go index 67cf314945b9d74cb22c376c4c350c3bc01a1dd2..94cbca0d81f68b9699f1cc2fce10898be55e295e 100644 --- a/client.go +++ b/client.go @@ -73,8 +73,13 @@ // DHT: http://www.bittorrent.org/beps/bep_0005.html extensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01" socketsPerTorrent = 40 - torrentPeersHighWater = 1000 - torrentPeersLowWater = socketsPerTorrent * 5 + torrentPeersHighWater = 200 + torrentPeersLowWater = 50 + + // 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. + handshakeTimeout = 4 * time.Second ) // Currently doesn't really queue, but should in the future. @@ -851,8 +856,7 @@ if tcpConn, ok := sock.(*net.TCPConn); ok { tcpConn.SetLinger(0) } defer sock.Close() - // One minute to complete handshake. - err = sock.SetDeadline(time.Now().Add(time.Minute)) + err = sock.SetDeadline(time.Now().Add(handshakeTimeout)) if err != nil { err = fmt.Errorf("couldn't set handshake deadline: %s", err) return