mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
ProtocolError -> self.protoError
This commit is contained in:
parent
d55d6a5c19
commit
52706be77b
1 changed files with 21 additions and 21 deletions
|
|
@ -117,7 +117,7 @@ func (self *ethProtocol) handle() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if msg.Size > ProtocolMaxMsgSize {
|
if msg.Size > ProtocolMaxMsgSize {
|
||||||
return ProtocolError(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
|
return self.protoError(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
|
||||||
}
|
}
|
||||||
// make sure that the payload has been fully consumed
|
// make sure that the payload has been fully consumed
|
||||||
defer msg.Discard()
|
defer msg.Discard()
|
||||||
|
|
@ -125,20 +125,20 @@ func (self *ethProtocol) handle() error {
|
||||||
switch msg.Code {
|
switch msg.Code {
|
||||||
|
|
||||||
case StatusMsg:
|
case StatusMsg:
|
||||||
return ProtocolError(ErrExtraStatusMsg, "")
|
return self.protoError(ErrExtraStatusMsg, "")
|
||||||
|
|
||||||
case TxMsg:
|
case TxMsg:
|
||||||
// TODO: rework using lazy RLP stream
|
// TODO: rework using lazy RLP stream
|
||||||
var txs []*types.Transaction
|
var txs []*types.Transaction
|
||||||
if err := msg.Decode(&txs); err != nil {
|
if err := msg.Decode(&txs); err != nil {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
self.txPool.AddTransactions(txs)
|
self.txPool.AddTransactions(txs)
|
||||||
|
|
||||||
case GetBlockHashesMsg:
|
case GetBlockHashesMsg:
|
||||||
var request getBlockHashesMsgData
|
var request getBlockHashesMsgData
|
||||||
if err := msg.Decode(&request); err != nil {
|
if err := msg.Decode(&request); err != nil {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
||||||
return self.rw.EncodeMsg(BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...)
|
return self.rw.EncodeMsg(BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...)
|
||||||
|
|
@ -156,13 +156,13 @@ func (self *ethProtocol) handle() error {
|
||||||
}
|
}
|
||||||
self.blockPool.AddBlockHashes(iter, self.id)
|
self.blockPool.AddBlockHashes(iter, self.id)
|
||||||
if err != nil && err != rlp.EOL {
|
if err != nil && err != rlp.EOL {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case GetBlocksMsg:
|
case GetBlocksMsg:
|
||||||
var blockHashes [][]byte
|
var blockHashes [][]byte
|
||||||
if err := msg.Decode(&blockHashes); err != nil {
|
if err := msg.Decode(&blockHashes); err != nil {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
max := int(math.Min(float64(len(blockHashes)), blockHashesBatchSize))
|
max := int(math.Min(float64(len(blockHashes)), blockHashesBatchSize))
|
||||||
var blocks []interface{}
|
var blocks []interface{}
|
||||||
|
|
@ -185,7 +185,7 @@ func (self *ethProtocol) handle() error {
|
||||||
if err == rlp.EOL {
|
if err == rlp.EOL {
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.blockPool.AddBlock(block, self.id)
|
self.blockPool.AddBlock(block, self.id)
|
||||||
|
|
@ -194,7 +194,7 @@ func (self *ethProtocol) handle() error {
|
||||||
case NewBlockMsg:
|
case NewBlockMsg:
|
||||||
var request newBlockMsgData
|
var request newBlockMsgData
|
||||||
if err := msg.Decode(&request); err != nil {
|
if err := msg.Decode(&request); err != nil {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
hash := request.Block.Hash()
|
hash := request.Block.Hash()
|
||||||
// to simplify backend interface adding a new block
|
// to simplify backend interface adding a new block
|
||||||
|
|
@ -215,7 +215,7 @@ func (self *ethProtocol) handle() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return ProtocolError(ErrInvalidMsgCode, "%v", msg.Code)
|
return self.protoError(ErrInvalidMsgCode, "%v", msg.Code)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -253,36 +253,35 @@ func (self *ethProtocol) handleStatus() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Code != StatusMsg {
|
if msg.Code != StatusMsg {
|
||||||
return ProtocolError(ErrNoStatusMsg, "first msg has code %x (!= %x)", msg.Code, StatusMsg)
|
return self.protoError(ErrNoStatusMsg, "first msg has code %x (!= %x)", msg.Code, StatusMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Size > ProtocolMaxMsgSize {
|
if msg.Size > ProtocolMaxMsgSize {
|
||||||
return ProtocolError(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
|
return self.protoError(ErrMsgTooLarge, "%v > %v", msg.Size, ProtocolMaxMsgSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
var status statusMsgData
|
var status statusMsgData
|
||||||
if err := msg.Decode(&status); err != nil {
|
if err := msg.Decode(&status); err != nil {
|
||||||
return ProtocolError(ErrDecode, "%v", err)
|
return self.protoError(ErrDecode, "%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, genesisBlock := self.chainManager.Status()
|
_, _, genesisBlock := self.chainManager.Status()
|
||||||
|
|
||||||
if bytes.Compare(status.GenesisBlock, genesisBlock) != 0 {
|
if bytes.Compare(status.GenesisBlock, genesisBlock) != 0 {
|
||||||
return ProtocolError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
|
return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.NetworkId != NetworkId {
|
if status.NetworkId != NetworkId {
|
||||||
return ProtocolError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, NetworkId)
|
return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, NetworkId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ProtocolVersion != status.ProtocolVersion {
|
if ProtocolVersion != status.ProtocolVersion {
|
||||||
return ProtocolError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, ProtocolVersion)
|
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, ProtocolVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
|
self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
|
||||||
|
|
||||||
//self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
|
self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
|
||||||
self.peer.Infoln("AddPeer(IGNORED)")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -300,9 +299,10 @@ func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
|
||||||
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *protocolError) {
|
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *protocolError) {
|
||||||
err = ProtocolError(code, format, params...)
|
err = ProtocolError(code, format, params...)
|
||||||
if err.Fatal() {
|
if err.Fatal() {
|
||||||
self.peer.Errorln(err)
|
self.peer.Errorln("err %v", err)
|
||||||
|
// disconnect
|
||||||
} else {
|
} else {
|
||||||
self.peer.Debugln(err)
|
self.peer.Debugf("fyi %v", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -310,10 +310,10 @@ func (self *ethProtocol) protoError(code int, format string, params ...interface
|
||||||
func (self *ethProtocol) protoErrorDisconnect(code int, format string, params ...interface{}) {
|
func (self *ethProtocol) protoErrorDisconnect(code int, format string, params ...interface{}) {
|
||||||
err := ProtocolError(code, format, params...)
|
err := ProtocolError(code, format, params...)
|
||||||
if err.Fatal() {
|
if err.Fatal() {
|
||||||
self.peer.Errorln(err)
|
self.peer.Errorln("err %v", err)
|
||||||
// disconnect
|
// disconnect
|
||||||
} else {
|
} else {
|
||||||
self.peer.Debugln(err)
|
self.peer.Debugf("fyi %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue