aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message.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/message.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/message.go')
-rw-r--r--p2p/message.go40
1 files changed, 12 insertions, 28 deletions
diff --git a/p2p/message.go b/p2p/message.go
index 04b9e71f3..f88c31d1d 100644
--- a/p2p/message.go
+++ b/p2p/message.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "net"
"sync"
"sync/atomic"
"time"
@@ -14,28 +15,6 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
-// parameters for frameRW
-const (
- // maximum time allowed for reading a message header.
- // this is effectively the amount of time a connection can be idle.
- frameReadTimeout = 1 * time.Minute
-
- // maximum time allowed for reading the payload data of a message.
- // this is shorter than (and distinct from) frameReadTimeout because
- // the connection is not considered idle while a message is transferred.
- // this also limits the payload size of messages to how much the connection
- // can transfer within the timeout.
- payloadReadTimeout = 5 * time.Second
-
- // maximum amount of time allowed for writing a complete message.
- msgWriteTimeout = 5 * time.Second
-
- // messages smaller than this many bytes will be read at
- // once before passing them to a protocol. this increases
- // concurrency in the processing.
- wholePayloadSize = 64 * 1024
-)
-
// Msg defines the structure of a p2p message.
//
// Note that a Msg can only be sent once since the Payload reader is
@@ -103,22 +82,27 @@ func EncodeMsg(w MsgWriter, code uint64, data ...interface{}) error {
return w.WriteMsg(NewMsg(code, data...))
}
-// lockedRW wraps a MsgReadWriter with locks around
-// ReadMsg and WriteMsg.
-type lockedRW struct {
+// netWrapper wrapsa MsgReadWriter with locks around
+// ReadMsg/WriteMsg and applies read/write deadlines.
+type netWrapper struct {
rmu, wmu sync.Mutex
- wrapped MsgReadWriter
+
+ rtimeout, wtimeout time.Duration
+ conn net.Conn
+ wrapped MsgReadWriter
}
-func (rw *lockedRW) ReadMsg() (Msg, error) {
+func (rw *netWrapper) ReadMsg() (Msg, error) {
rw.rmu.Lock()
defer rw.rmu.Unlock()
+ rw.conn.SetReadDeadline(time.Now().Add(rw.rtimeout))
return rw.wrapped.ReadMsg()
}
-func (rw *lockedRW) WriteMsg(msg Msg) error {
+func (rw *netWrapper) WriteMsg(msg Msg) error {
rw.wmu.Lock()
defer rw.wmu.Unlock()
+ rw.conn.SetWriteDeadline(time.Now().Add(rw.wtimeout))
return rw.wrapped.WriteMsg(msg)
}