|
|
@ -24,9 +24,11 @@ const ( |
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
// The size of the output buffer for writing messages
|
|
|
|
outputBufferSize = 50 |
|
|
|
outputBufferSize = 50 |
|
|
|
// Current protocol version
|
|
|
|
// Current protocol version
|
|
|
|
ProtocolVersion = 32 |
|
|
|
ProtocolVersion = 33 |
|
|
|
// Current P2P version
|
|
|
|
// Current P2P version
|
|
|
|
P2PVersion = 0 |
|
|
|
P2PVersion = 0 |
|
|
|
|
|
|
|
// Ethereum network version
|
|
|
|
|
|
|
|
NetVersion = 0 |
|
|
|
// Interval for ping/pong message
|
|
|
|
// Interval for ping/pong message
|
|
|
|
pingPongTimer = 2 * time.Second |
|
|
|
pingPongTimer = 2 * time.Second |
|
|
|
) |
|
|
|
) |
|
|
@ -72,7 +74,7 @@ func (d DiscReason) String() string { |
|
|
|
type Caps byte |
|
|
|
type Caps byte |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
CapPeerDiscTy = 1 << iota |
|
|
|
CapPeerDiscTy Caps = 1 << iota |
|
|
|
CapTxTy |
|
|
|
CapTxTy |
|
|
|
CapChainTy |
|
|
|
CapChainTy |
|
|
|
|
|
|
|
|
|
|
@ -309,6 +311,14 @@ out: |
|
|
|
select { |
|
|
|
select { |
|
|
|
// Main message queue. All outbound messages are processed through here
|
|
|
|
// Main message queue. All outbound messages are processed through here
|
|
|
|
case msg := <-p.outputQueue: |
|
|
|
case msg := <-p.outputQueue: |
|
|
|
|
|
|
|
if !p.statusKnown { |
|
|
|
|
|
|
|
switch msg.Type { |
|
|
|
|
|
|
|
case ethwire.MsgGetTxsTy, ethwire.MsgGetBlockHashesTy, ethwire.MsgGetBlocksTy, ethwire.MsgBlockHashesTy, ethwire.MsgBlockTy: |
|
|
|
|
|
|
|
peerlogger.Debugln("Blocked outgoing [eth] message to peer without the [eth] cap.") |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p.writeMessage(msg) |
|
|
|
p.writeMessage(msg) |
|
|
|
p.lastSend = time.Now() |
|
|
|
p.lastSend = time.Now() |
|
|
|
|
|
|
|
|
|
|
@ -435,6 +445,11 @@ func (p *Peer) HandleInbound() { |
|
|
|
case ethwire.MsgStatusTy: |
|
|
|
case ethwire.MsgStatusTy: |
|
|
|
// Handle peer's status msg
|
|
|
|
// Handle peer's status msg
|
|
|
|
p.handleStatus(msg) |
|
|
|
p.handleStatus(msg) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TMP
|
|
|
|
|
|
|
|
if p.statusKnown { |
|
|
|
|
|
|
|
switch msg.Type { |
|
|
|
case ethwire.MsgGetTxsTy: |
|
|
|
case ethwire.MsgGetTxsTy: |
|
|
|
// Get the current transactions of the pool
|
|
|
|
// Get the current transactions of the pool
|
|
|
|
txs := p.ethereum.TxPool().CurrentTransactions() |
|
|
|
txs := p.ethereum.TxPool().CurrentTransactions() |
|
|
@ -534,6 +549,7 @@ func (p *Peer) HandleInbound() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p.Stop() |
|
|
|
p.Stop() |
|
|
|
} |
|
|
|
} |
|
|
@ -645,10 +661,9 @@ func (p *Peer) pushPeers() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (self *Peer) pushStatus() { |
|
|
|
func (self *Peer) pushStatus() { |
|
|
|
const netVersion = 0 |
|
|
|
|
|
|
|
msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{ |
|
|
|
msg := ethwire.NewMessage(ethwire.MsgStatusTy, []interface{}{ |
|
|
|
uint32(ProtocolVersion), |
|
|
|
uint32(ProtocolVersion), |
|
|
|
uint32(netVersion), |
|
|
|
uint32(NetVersion), |
|
|
|
self.ethereum.BlockChain().TD, |
|
|
|
self.ethereum.BlockChain().TD, |
|
|
|
self.ethereum.BlockChain().CurrentBlock.Hash(), |
|
|
|
self.ethereum.BlockChain().CurrentBlock.Hash(), |
|
|
|
self.ethereum.BlockChain().Genesis().Hash(), |
|
|
|
self.ethereum.BlockChain().Genesis().Hash(), |
|
|
@ -669,7 +684,17 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) { |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if bytes.Compare(self.ethereum.BlockChain().Genesis().Hash(), genesis) != 0 { |
|
|
|
if bytes.Compare(self.ethereum.BlockChain().Genesis().Hash(), genesis) != 0 { |
|
|
|
ethlogger.Warnf("Invalid genisis hash %x. Disabling [ETH]\n", genesis) |
|
|
|
ethlogger.Warnf("Invalid genisis hash %x. Disabling [eth]\n", genesis) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if netVersion != NetVersion { |
|
|
|
|
|
|
|
ethlogger.Warnf("Invalid network version %d. Disabling [eth]\n", netVersion) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if protoVersion != ProtocolVersion { |
|
|
|
|
|
|
|
ethlogger.Warnf("Invalid protocol version %d. Disabling [eth]\n", protoVersion) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -687,7 +712,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) { |
|
|
|
self.FetchHashes() |
|
|
|
self.FetchHashes() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ethlogger.Infof("Peer is [ETH] capable. (TD = %v ~ %x) %d / %d", self.td, self.bestHash, protoVersion, netVersion) |
|
|
|
ethlogger.Infof("Peer is [eth] capable. (TD = %v ~ %x) %d / %d", self.td, self.bestHash, protoVersion, netVersion) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|