aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-02-27 11:06:55 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 19:27:23 +0800
commit736e632215d49dd7bc61126f78dda4bad12768ea (patch)
tree063327c533fd57620e0448f331832e79f9ba0dda /p2p/message.go
parent51e01cceca81bc5e82896815754b7c33bb6e6005 (diff)
downloadgo-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.tar.gz
go-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.tar.zst
go-tangerine-736e632215d49dd7bc61126f78dda4bad12768ea.zip
p2p: use RLPx frames for messaging
Diffstat (limited to 'p2p/message.go')
-rw-r--r--p2p/message.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/p2p/message.go b/p2p/message.go
index 7adad4b09..d61faad13 100644
--- a/p2p/message.go
+++ b/p2p/message.go
@@ -119,6 +119,25 @@ 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 {
+ rmu, wmu sync.Mutex
+ wrapped MsgReadWriter
+}
+
+func (rw *lockedRW) ReadMsg() (Msg, error) {
+ rw.rmu.Lock()
+ defer rw.rmu.Unlock()
+ return rw.wrapped.ReadMsg()
+}
+
+func (rw *lockedRW) WriteMsg(msg Msg) error {
+ rw.wmu.Lock()
+ defer rw.wmu.Unlock()
+ return rw.wrapped.WriteMsg(msg)
+}
+
// frameRW is a MsgReadWriter that reads and writes devp2p message frames.
// As required by the interface, ReadMsg and WriteMsg can be called from
// multiple goroutines.