diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-06 00:21:32 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-06 00:21:32 +0800 |
commit | ba0c41436c8a067937aa0845963f9ec3b81e7aed (patch) | |
tree | 7bd9bbc9422353ab341f01581abeb346b5a6cacf /eth/protocol.go | |
parent | fabaf4f1f01db773f6c0c2e9a9499736b1a40848 (diff) | |
parent | 215c763d53fc8e06e8c9807875eacaccf3ef45fa (diff) | |
download | dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.gz dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.tar.zst dexon-ba0c41436c8a067937aa0845963f9ec3b81e7aed.zip |
Merge branch 'p2p-handshake-2' of https://github.com/fjl/go-ethereum into fjl-p2p-handshake-2
Diffstat (limited to 'eth/protocol.go')
-rw-r--r-- | eth/protocol.go | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/eth/protocol.go b/eth/protocol.go index c887af129..b52c7db42 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) |