aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-04 19:03:43 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 19:27:24 +0800
commit7964f30dcbdde00b2960ef6e98320e0a0f9300e2 (patch)
treeadd3fbd54ec615135f3ecdac2917d22e77581d56 /p2p/message.go
parent21649100b1ed64c9bd73c547360dd6db9b5218fb (diff)
downloaddexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.tar.gz
dexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.tar.zst
dexon-7964f30dcbdde00b2960ef6e98320e0a0f9300e2.zip
p2p: msg.Payload contains list data
With RLPx frames, the message code is contained in the frame and is no longer part of the encoded data. EncodeMsg, Msg.Decode have been updated to match. Code that decodes RLP directly from Msg.Payload will need to change.
Diffstat (limited to 'p2p/message.go')
-rw-r--r--p2p/message.go18
1 files changed, 3 insertions, 15 deletions
diff --git a/p2p/message.go b/p2p/message.go
index 2ef84f99d..04b9e71f3 100644
--- a/p2p/message.go
+++ b/p2p/message.go
@@ -51,19 +51,8 @@ type Msg struct {
// NewMsg creates an RLP-encoded message with the given code.
func NewMsg(code uint64, params ...interface{}) Msg {
- buf := new(bytes.Buffer)
- for _, p := range params {
- buf.Write(ethutil.Encode(p))
- }
- return Msg{Code: code, Size: uint32(buf.Len()), Payload: buf}
-}
-
-func encodePayload(params ...interface{}) []byte {
- buf := new(bytes.Buffer)
- for _, p := range params {
- buf.Write(ethutil.Encode(p))
- }
- return buf.Bytes()
+ p := bytes.NewReader(ethutil.Encode(params))
+ return Msg{Code: code, Size: uint32(p.Len()), Payload: p}
}
// Decode parse the RLP content of a message into
@@ -71,8 +60,7 @@ func encodePayload(params ...interface{}) []byte {
//
// For the decoding rules, please see package rlp.
func (msg Msg) Decode(val interface{}) error {
- s := rlp.NewListStream(msg.Payload, uint64(msg.Size))
- if err := s.Decode(val); err != nil {
+ if err := rlp.Decode(msg.Payload, val); err != nil {
return newPeerError(errInvalidMsg, "(code %#x) (size %d) %v", msg.Code, msg.Size, err)
}
return nil