aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-04 23:27:37 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 23:42:00 +0800
commit22659a7feaf4e939a33762c3f83b43d8bec757db (patch)
tree59ae2809af292a79a4f619042ed190b4708d5c2a /p2p/server.go
parent6e7e5d5fd56a9a6f73e51239ed6648d76db9650d (diff)
downloadgo-tangerine-22659a7feaf4e939a33762c3f83b43d8bec757db.tar.gz
go-tangerine-22659a7feaf4e939a33762c3f83b43d8bec757db.tar.zst
go-tangerine-22659a7feaf4e939a33762c3f83b43d8bec757db.zip
p2p: restore read/write timeouts
They got lost in the transition to rlpxFrameRW.
Diffstat (limited to 'p2p/server.go')
-rw-r--r--p2p/server.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 67d5514b4..8f99bc33d 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -17,9 +17,17 @@ import (
)
const (
- handshakeTimeout = 5 * time.Second
defaultDialTimeout = 10 * time.Second
refreshPeersInterval = 30 * time.Second
+
+ // total timeout for encryption handshake and protocol
+ // handshake in both directions.
+ handshakeTimeout = 5 * time.Second
+ // maximum time allowed for reading a complete message.
+ // this is effectively the amount of time a connection can be idle.
+ frameReadTimeout = 1 * time.Minute
+ // maximum amount of time allowed for writing a complete message.
+ frameWriteTimeout = 5 * time.Second
)
var srvlog = logger.NewLogger("P2P Server")
@@ -359,14 +367,18 @@ func (srv *Server) findPeers() {
func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
// TODO: handle/store session token
- // TODO: reenable deadlines
- // fd.SetDeadline(time.Now().Add(handshakeTimeout))
+ fd.SetDeadline(time.Now().Add(handshakeTimeout))
conn, err := srv.setupFunc(fd, srv.PrivateKey, srv.ourHandshake, dest)
if err != nil {
fd.Close()
srvlog.Debugf("Handshake with %v failed: %v", fd.RemoteAddr(), err)
return
}
+
+ conn.MsgReadWriter = &netWrapper{
+ wrapped: conn.MsgReadWriter,
+ conn: fd, rtimeout: frameReadTimeout, wtimeout: frameWriteTimeout,
+ }
p := newPeer(fd, conn, srv.Protocols)
if ok, reason := srv.addPeer(conn.ID, p); !ok {
srvlog.DebugDetailf("Not adding %v (%v)\n", p, reason)