diff --git a/router/connection.go b/router/connection.go index a662f7d6..a02bd1b1 100644 --- a/router/connection.go +++ b/router/connection.go @@ -310,9 +310,8 @@ func (conn *LocalConnection) handshake(acceptNewPeer bool) error { // ourself. Only when we add this connection to the conn.local // peer will it be visible from multiple go-routines. tcpConn := conn.TCPConn - tcpConn.SetKeepAlive(true) tcpConn.SetLinger(0) - tcpConn.SetNoDelay(true) + conn.extendReadDeadline() enc := gob.NewEncoder(tcpConn) @@ -454,6 +453,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool var err error for { var msg []byte + conn.extendReadDeadline() if conn.CheckFatal(decoder.Decode(&msg)) != nil { return } @@ -527,6 +527,10 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder, usingPassword bool } } +func (conn *LocalConnection) extendReadDeadline() { + conn.TCPConn.SetReadDeadline(time.Now().Add(ReadTimeout)) +} + // Heartbeating serves two purposes: a) keeping NAT paths alive, and // b) updating a remote peer's knowledge of our address, in the event // it changes (e.g. because NAT paths expired). diff --git a/router/consts.go b/router/consts.go index ae9fa46b..92245167 100644 --- a/router/consts.go +++ b/router/consts.go @@ -22,6 +22,7 @@ const ( SlowHeartbeat = 10 * time.Second FetchAllInterval = 30 * time.Second FragTestInterval = 5 * time.Minute + ReadTimeout = 2 * FetchAllInterval PMTUVerifyAttempts = 8 PMTUVerifyTimeout = 10 * time.Millisecond // gets doubled with every attempt MaxDuration = time.Duration(math.MaxInt64)