aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-04 20:12:50 +0800
committerFelix Lange <fjl@twurst.com>2015-03-04 20:25:01 +0800
commit6e7e5d5fd56a9a6f73e51239ed6648d76db9650d (patch)
tree0a70a79b3dc162632b439e926f3c633bb17610c4 /eth
parent7964f30dcbdde00b2960ef6e98320e0a0f9300e2 (diff)
downloadgo-tangerine-6e7e5d5fd56a9a6f73e51239ed6648d76db9650d.tar.gz
go-tangerine-6e7e5d5fd56a9a6f73e51239ed6648d76db9650d.tar.zst
go-tangerine-6e7e5d5fd56a9a6f73e51239ed6648d76db9650d.zip
eth, whisper: fix msg.Payload reads
Diffstat (limited to 'eth')
-rw-r--r--eth/protocol.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/eth/protocol.go b/eth/protocol.go
index 663af43fe..b86f33614 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -3,7 +3,6 @@ package eth
import (
"bytes"
"fmt"
- "io"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
@@ -188,33 +187,37 @@ func (self *ethProtocol) handle() error {
case BlockHashesMsg:
msgStream := rlp.NewStream(msg.Payload)
- var err error
- var i int
+ if _, err := msgStream.List(); err != nil {
+ return err
+ }
+ var i int
iter := func() (hash []byte, ok bool) {
- hash, err = msgStream.Bytes()
- if err == nil {
- i++
- ok = true
- } else {
- if err != io.EOF {
- self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err)
- }
+ hash, err := msgStream.Bytes()
+ if err == rlp.EOL {
+ return nil, false
+ } else if err != nil {
+ self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err)
+ return nil, false
}
- return
+ i++
+ return hash, true
}
-
self.blockPool.AddBlockHashes(iter, self.id)
case GetBlocksMsg:
msgStream := rlp.NewStream(msg.Payload)
+ if _, err := msgStream.List(); err != nil {
+ return err
+ }
+
var blocks []interface{}
var i int
for {
i++
var hash []byte
if err := msgStream.Decode(&hash); err != nil {
- if err == io.EOF {
+ if err == rlp.EOL {
break
} else {
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
@@ -232,10 +235,13 @@ func (self *ethProtocol) handle() error {
case BlocksMsg:
msgStream := rlp.NewStream(msg.Payload)
+ if _, err := msgStream.List(); err != nil {
+ return err
+ }
for {
var block types.Block
if err := msgStream.Decode(&block); err != nil {
- if err == io.EOF {
+ if err == rlp.EOL {
break
} else {
return self.protoError(ErrDecode, "msg %v: %v", msg, err)