]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Tweak handshaking and peer water marks
authorMatt Joiner <anacrolix@gmail.com>
Sat, 21 Feb 2015 03:56:17 +0000 (14:56 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sat, 21 Feb 2015 03:56:17 +0000 (14:56 +1100)
client.go

index 67cf314945b9d74cb22c376c4c350c3bc01a1dd2..94cbca0d81f68b9699f1cc2fce10898be55e295e 100644 (file)
--- 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