@ -5,9 +5,9 @@ import (
"fmt"
"fmt"
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
@ -66,6 +66,8 @@ type ethProtocol struct {
id string
id string
rw p2p . MsgReadWriter
rw p2p . MsgReadWriter
errors * errs . Errors
errors * errs . Errors
protocolVersion int
networkId int
}
}
// backend is the interface the ethereum protocol backend should implement
// backend is the interface the ethereum protocol backend should implement
@ -102,20 +104,20 @@ type getBlockHashesMsgData struct {
// main entrypoint, wrappers starting a server running the eth protocol
// main entrypoint, wrappers starting a server running the eth protocol
// use this constructor to attach the protocol ("class") to server caps
// use this constructor to attach the protocol ("class") to server caps
// the Dev p2p layer then runs the protocol instance on each peer
// the Dev p2p layer then runs the protocol instance on each peer
func EthProtocol ( txPool txPool , chainManager chainManager , blockPool blockPool ) p2p . Protocol {
func EthProtocol ( protocolVersion , networkId int , txPool txPool , chainManager chainManager , blockPool blockPool ) p2p . Protocol {
return p2p . Protocol {
return p2p . Protocol {
Name : "eth" ,
Name : "eth" ,
Version : ProtocolVersion ,
Version : uint ( protocolVersion ) ,
Length : ProtocolLength ,
Length : ProtocolLength ,
Run : func ( peer * p2p . Peer , rw p2p . MsgReadWriter ) error {
Run : func ( peer * p2p . Peer , rw p2p . MsgReadWriter ) error {
return runEthProtocol ( txPool , chainManager , blockPool , peer , rw )
return runEthProtocol ( protocolVersion , networkId , txPool , chainManager , blockPool , peer , rw )
} ,
} ,
}
}
}
}
// the main loop that handles incoming messages
// the main loop that handles incoming messages
// note RemovePeer in the post-disconnect hook
// note RemovePeer in the post-disconnect hook
func runEthProtocol ( txPool txPool , chainManager chainManager , blockPool blockPool , peer * p2p . Peer , rw p2p . MsgReadWriter ) ( err error ) {
func runEthProtocol ( protocolVersion , networkId int , txPool txPool , chainManager chainManager , blockPool blockPool , peer * p2p . Peer , rw p2p . MsgReadWriter ) ( err error ) {
id := peer . ID ( )
id := peer . ID ( )
self := & ethProtocol {
self := & ethProtocol {
txPool : txPool ,
txPool : txPool ,
@ -123,6 +125,8 @@ func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPoo
blockPool : blockPool ,
blockPool : blockPool ,
rw : rw ,
rw : rw ,
peer : peer ,
peer : peer ,
protocolVersion : protocolVersion ,
networkId : networkId ,
errors : & errs . Errors {
errors : & errs . Errors {
Package : "ETH" ,
Package : "ETH" ,
Errors : errorToString ,
Errors : errorToString ,
@ -290,8 +294,8 @@ func (self *ethProtocol) statusMsg() p2p.Msg {
td , currentBlock , genesisBlock := self . chainManager . Status ( )
td , currentBlock , genesisBlock := self . chainManager . Status ( )
return p2p . NewMsg ( StatusMsg ,
return p2p . NewMsg ( StatusMsg ,
uint32 ( P rotocolVersion) ,
uint32 ( self . p rotocolVersion) ,
uint32 ( N etworkId) ,
uint32 ( self . n etworkId) ,
td ,
td ,
currentBlock ,
currentBlock ,
genesisBlock ,
genesisBlock ,
@ -329,12 +333,12 @@ func (self *ethProtocol) handleStatus() error {
return self . protoError ( ErrGenesisBlockMismatch , "%x (!= %x)" , status . GenesisBlock , genesisBlock )
return self . protoError ( ErrGenesisBlockMismatch , "%x (!= %x)" , status . GenesisBlock , genesisBlock )
}
}
if status . NetworkId != N etworkId {
if int ( status . NetworkId ) != self . n etworkId {
return self . protoError ( ErrNetworkIdMismatch , "%d (!= %d)" , status . NetworkId , N etworkId)
return self . protoError ( ErrNetworkIdMismatch , "%d (!= %d)" , status . NetworkId , self . n etworkId)
}
}
if ProtocolVersion != status . P rotocolVersion {
if int ( status . ProtocolVersion ) != self . p rotocolVersion {
return self . protoError ( ErrProtocolVersionMismatch , "%d (!= %d)" , status . ProtocolVersion , P rotocolVersion)
return self . protoError ( ErrProtocolVersionMismatch , "%d (!= %d)" , status . ProtocolVersion , self . p rotocolVersion)
}
}
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 ] )