Graceful shutdown of peers
This commit is contained in:
parent
1b7cba1878
commit
7931c6624c
27
peer.go
27
peer.go
@ -169,17 +169,26 @@ out:
|
|||||||
case ethwire.MsgHandshakeTy:
|
case ethwire.MsgHandshakeTy:
|
||||||
// Version message
|
// Version message
|
||||||
p.handleHandshake(msg)
|
p.handleHandshake(msg)
|
||||||
|
case ethwire.MsgDiscTy:
|
||||||
|
p.Stop()
|
||||||
|
case ethwire.MsgPingTy:
|
||||||
|
// Respond back with pong
|
||||||
|
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
|
||||||
|
case ethwire.MsgPongTy:
|
||||||
|
p.lastPong = time.Now().Unix()
|
||||||
case ethwire.MsgBlockTy:
|
case ethwire.MsgBlockTy:
|
||||||
block := ethchain.NewBlockFromRlpValue(msg.Data.Get(0))
|
for i := 0; i < msg.Data.Length(); i++ {
|
||||||
block.MakeContracts()
|
block := ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
|
||||||
err := p.ethereum.BlockManager.ProcessBlock(block)
|
err := p.ethereum.BlockManager.ProcessBlock(block)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case ethwire.MsgTxTy:
|
case ethwire.MsgTxTy:
|
||||||
//p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromData(msg.Data))
|
for i := 0; i < msg.Data.Length(); i++ {
|
||||||
p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromRlpValue(msg.Data.Get(0)))
|
p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromRlpValue(msg.Data.Get(i)))
|
||||||
case ethwire.MsgInvTy:
|
}
|
||||||
case ethwire.MsgGetPeersTy:
|
case ethwire.MsgGetPeersTy:
|
||||||
p.requestedPeerList = true
|
p.requestedPeerList = true
|
||||||
// Peer asked for list of connected peers
|
// Peer asked for list of connected peers
|
||||||
@ -201,11 +210,8 @@ out:
|
|||||||
// Mark unrequested again
|
// Mark unrequested again
|
||||||
p.requestedPeerList = false
|
p.requestedPeerList = false
|
||||||
}
|
}
|
||||||
case ethwire.MsgPingTy:
|
case ethwire.MsgGetChainTy:
|
||||||
// Respond back with pong
|
|
||||||
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
|
|
||||||
case ethwire.MsgPongTy:
|
|
||||||
p.lastPong = time.Now().Unix()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,6 +241,7 @@ func (p *Peer) Stop() {
|
|||||||
|
|
||||||
close(p.quit)
|
close(p.quit)
|
||||||
if atomic.LoadInt32(&p.connected) != 0 {
|
if atomic.LoadInt32(&p.connected) != 0 {
|
||||||
|
p.writeMessage(ethwire.NewMessage(ethwire.MsgDiscTy, ""))
|
||||||
p.conn.Close()
|
p.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user