From 763f2384927f5b75c78f837ad8910373a9e3a1b4 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sat, 21 Feb 2015 14:56:17 +1100 Subject: [PATCH] Tweak handshaking and peer water marks --- client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 67cf3149..94cbca0d 100644 --- a/client.go +++ b/client.go @@ -73,8 +73,13 @@ const ( 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 @@ func (me *Client) runConnection(sock net.Conn, torrent *torrent, discovery peerS 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 -- 2.48.1