diff options
author | Felix Lange <fjl@twurst.com> | 2015-01-06 18:35:09 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-01-06 19:23:38 +0800 |
commit | eb0e7b1b8120852a1d56aa0ebd3a98e652965635 (patch) | |
tree | 9e87afc204d178d89ed24cc43afcc3da6b252a49 /p2p/message.go | |
parent | 36e1e5f15142b37801844a072eb46ea67fbc8868 (diff) | |
download | go-tangerine-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.tar.gz go-tangerine-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.tar.zst go-tangerine-eb0e7b1b8120852a1d56aa0ebd3a98e652965635.zip |
eth, p2p: remove EncodeMsg from p2p.MsgWriter
...and make it a top-level function instead.
The original idea behind having EncodeMsg in the interface was that
implementations might be able to encode RLP data to their underlying
writer directly instead of buffering the encoded data. The encoder
will buffer anyway, so that doesn't matter anymore.
Given the recent problems with EncodeMsg (copy-pasted implementation
bug) I'd rather implement once, correctly.
Diffstat (limited to 'p2p/message.go')
-rw-r--r-- | p2p/message.go | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/p2p/message.go b/p2p/message.go index a6f62ec4c..daf2bf05c 100644 --- a/p2p/message.go +++ b/p2p/message.go @@ -71,14 +71,11 @@ type MsgReader interface { } type MsgWriter interface { - // WriteMsg sends an existing message. - // The Payload reader of the message is consumed. + // WriteMsg sends a message. It will block until the message's + // Payload has been consumed by the other end. + // // Note that messages can be sent only once. WriteMsg(Msg) error - - // EncodeMsg writes an RLP-encoded message with the given - // code and data elements. - EncodeMsg(code uint64, data ...interface{}) error } // MsgReadWriter provides reading and writing of encoded messages. @@ -87,6 +84,12 @@ type MsgReadWriter interface { MsgWriter } +// EncodeMsg writes an RLP-encoded message with the given code and +// data elements. +func EncodeMsg(w MsgWriter, code uint64, data ...interface{}) error { + return w.WriteMsg(NewMsg(code, data...)) +} + var magicToken = []byte{34, 64, 8, 145} func writeMsg(w io.Writer, msg Msg) error { @@ -209,11 +212,6 @@ func (p *MsgPipeRW) WriteMsg(msg Msg) error { return ErrPipeClosed } -// EncodeMsg is a convenient shorthand for sending an RLP-encoded message. -func (p *MsgPipeRW) EncodeMsg(code uint64, data ...interface{}) error { - return p.WriteMsg(NewMsg(code, data...)) -} - // ReadMsg returns a message sent on the other end of the pipe. func (p *MsgPipeRW) ReadMsg() (Msg, error) { if atomic.LoadInt32(p.closed) == 0 { |