|
|
@ -3,7 +3,6 @@ package eth |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bytes" |
|
|
|
"bytes" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io" |
|
|
|
|
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
@ -188,33 +187,37 @@ func (self *ethProtocol) handle() error { |
|
|
|
|
|
|
|
|
|
|
|
case BlockHashesMsg: |
|
|
|
case BlockHashesMsg: |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
var err error |
|
|
|
if _, err := msgStream.List(); err != nil { |
|
|
|
var i int |
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var i int |
|
|
|
iter := func() (hash []byte, ok bool) { |
|
|
|
iter := func() (hash []byte, ok bool) { |
|
|
|
hash, err = msgStream.Bytes() |
|
|
|
hash, err := msgStream.Bytes() |
|
|
|
if err == nil { |
|
|
|
if err == rlp.EOL { |
|
|
|
i++ |
|
|
|
return nil, false |
|
|
|
ok = true |
|
|
|
} else if err != nil { |
|
|
|
} else { |
|
|
|
self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err) |
|
|
|
if err != io.EOF { |
|
|
|
return nil, false |
|
|
|
self.protoError(ErrDecode, "msg %v: after %v hashes : %v", msg, i, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return |
|
|
|
i++ |
|
|
|
|
|
|
|
return hash, true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.blockPool.AddBlockHashes(iter, self.id) |
|
|
|
self.blockPool.AddBlockHashes(iter, self.id) |
|
|
|
|
|
|
|
|
|
|
|
case GetBlocksMsg: |
|
|
|
case GetBlocksMsg: |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
|
|
|
|
if _, err := msgStream.List(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var blocks []interface{} |
|
|
|
var blocks []interface{} |
|
|
|
var i int |
|
|
|
var i int |
|
|
|
for { |
|
|
|
for { |
|
|
|
i++ |
|
|
|
i++ |
|
|
|
var hash []byte |
|
|
|
var hash []byte |
|
|
|
if err := msgStream.Decode(&hash); err != nil { |
|
|
|
if err := msgStream.Decode(&hash); err != nil { |
|
|
|
if err == io.EOF { |
|
|
|
if err == rlp.EOL { |
|
|
|
break |
|
|
|
break |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return self.protoError(ErrDecode, "msg %v: %v", msg, err) |
|
|
|
return self.protoError(ErrDecode, "msg %v: %v", msg, err) |
|
|
@ -232,10 +235,13 @@ func (self *ethProtocol) handle() error { |
|
|
|
|
|
|
|
|
|
|
|
case BlocksMsg: |
|
|
|
case BlocksMsg: |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
msgStream := rlp.NewStream(msg.Payload) |
|
|
|
|
|
|
|
if _, err := msgStream.List(); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
for { |
|
|
|
for { |
|
|
|
var block types.Block |
|
|
|
var block types.Block |
|
|
|
if err := msgStream.Decode(&block); err != nil { |
|
|
|
if err := msgStream.Decode(&block); err != nil { |
|
|
|
if err == io.EOF { |
|
|
|
if err == rlp.EOL { |
|
|
|
break |
|
|
|
break |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return self.protoError(ErrDecode, "msg %v: %v", msg, err) |
|
|
|
return self.protoError(ErrDecode, "msg %v: %v", msg, err) |
|
|
|