diff options
author | Felix Lange <fjl@twurst.com> | 2015-02-27 11:06:55 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-04 19:27:23 +0800 |
commit | 736e632215d49dd7bc61126f78dda4bad12768ea (patch) | |
tree | 063327c533fd57620e0448f331832e79f9ba0dda /p2p/message.go | |
parent | 51e01cceca81bc5e82896815754b7c33bb6e6005 (diff) | |
download | dexon-736e632215d49dd7bc61126f78dda4bad12768ea.tar.gz dexon-736e632215d49dd7bc61126f78dda4bad12768ea.tar.zst dexon-736e632215d49dd7bc61126f78dda4bad12768ea.zip |
p2p: use RLPx frames for messaging
Diffstat (limited to 'p2p/message.go')
-rw-r--r-- | p2p/message.go | 19 |
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. |