diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-04 19:03:43 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-04 19:27:24 +0800 |
commit | 7964f30dcbdde00b2960ef6e98320e0a0f9300e2 (patch) | |
tree | add3fbd54ec615135f3ecdac2917d22e77581d56 /p2p/peer_test.go | |
parent | 21649100b1ed64c9bd73c547360dd6db9b5218fb (diff) | |
download | dexon-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/peer_test.go')
-rw-r--r-- | p2p/peer_test.go | 43 |
1 files changed, 2 insertions, 41 deletions
diff --git a/p2p/peer_test.go b/p2p/peer_test.go index 1ba43bed5..cc9f1f0cd 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -85,41 +85,6 @@ func TestPeerProtoReadMsg(t *testing.T) { } } -func TestPeerProtoReadLargeMsg(t *testing.T) { - defer testlog(t).detach() - - msgsize := uint32(10 * 1024 * 1024) - done := make(chan struct{}) - proto := Protocol{ - Name: "a", - Length: 5, - Run: func(peer *Peer, rw MsgReadWriter) error { - msg, err := rw.ReadMsg() - if err != nil { - t.Errorf("read error: %v", err) - } - if msg.Size != msgsize+4 { - t.Errorf("incorrect msg.Size, got %d, expected %d", msg.Size, msgsize) - } - msg.Discard() - close(done) - return nil - }, - } - - closer, rw, _, errc := testPeer([]Protocol{proto}) - defer closer.Close() - - EncodeMsg(rw, 18, make([]byte, msgsize)) - select { - case <-done: - case err := <-errc: - t.Errorf("peer returned: %v", err) - case <-time.After(2 * time.Second): - t.Errorf("receive timeout") - } -} - func TestPeerProtoEncodeMsg(t *testing.T) { defer testlog(t).detach() @@ -246,13 +211,9 @@ func expectMsg(r MsgReader, code uint64, content interface{}) error { if err != nil { panic("content encode error: " + err.Error()) } - // skip over list header in encoded value. this is temporary. - contentEncR := bytes.NewReader(contentEnc) - if k, _, err := rlp.NewStream(contentEncR).Kind(); k != rlp.List || err != nil { - panic("content must encode as RLP list") + if int(msg.Size) != len(contentEnc) { + return fmt.Errorf("message size mismatch: got %d, want %d", msg.Size, len(contentEnc)) } - contentEnc = contentEnc[len(contentEnc)-contentEncR.Len():] - actualContent, err := ioutil.ReadAll(msg.Payload) if err != nil { return err |