aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-26 00:13:33 +0800
committerobscuren <geffobscura@gmail.com>2014-01-26 00:13:33 +0800
commit7931c6624cca041b373e97e17e43318633633250 (patch)
tree1c6f6cbb8d75649da25eb19dcdba64a81aca1615 /peer.go
parent1b7cba18781ddd6ff262801057930367ea397c9e (diff)
downloaddexon-7931c6624cca041b373e97e17e43318633633250.tar
dexon-7931c6624cca041b373e97e17e43318633633250.tar.gz
dexon-7931c6624cca041b373e97e17e43318633633250.tar.bz2
dexon-7931c6624cca041b373e97e17e43318633633250.tar.lz
dexon-7931c6624cca041b373e97e17e43318633633250.tar.xz
dexon-7931c6624cca041b373e97e17e43318633633250.tar.zst
dexon-7931c6624cca041b373e97e17e43318633633250.zip
Graceful shutdown of peers
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go33
1 files changed, 20 insertions, 13 deletions
diff --git a/peer.go b/peer.go
index afbe728fe..f370580cf 100644
--- a/peer.go
+++ b/peer.go
@@ -169,17 +169,26 @@ out:
case ethwire.MsgHandshakeTy:
// Version message
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:
- block := ethchain.NewBlockFromRlpValue(msg.Data.Get(0))
- block.MakeContracts()
- err := p.ethereum.BlockManager.ProcessBlock(block)
- if err != nil {
- log.Println(err)
+ for i := 0; i < msg.Data.Length(); i++ {
+ block := ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
+ err := p.ethereum.BlockManager.ProcessBlock(block)
+
+ if err != nil {
+ log.Println(err)
+ }
}
case ethwire.MsgTxTy:
- //p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromData(msg.Data))
- p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromRlpValue(msg.Data.Get(0)))
- case ethwire.MsgInvTy:
+ for i := 0; i < msg.Data.Length(); i++ {
+ p.ethereum.TxPool.QueueTransaction(ethchain.NewTransactionFromRlpValue(msg.Data.Get(i)))
+ }
case ethwire.MsgGetPeersTy:
p.requestedPeerList = true
// Peer asked for list of connected peers
@@ -201,11 +210,8 @@ out:
// Mark unrequested again
p.requestedPeerList = false
}
- case ethwire.MsgPingTy:
- // Respond back with pong
- p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
- case ethwire.MsgPongTy:
- p.lastPong = time.Now().Unix()
+ case ethwire.MsgGetChainTy:
+
}
}
@@ -235,6 +241,7 @@ func (p *Peer) Stop() {
close(p.quit)
if atomic.LoadInt32(&p.connected) != 0 {
+ p.writeMessage(ethwire.NewMessage(ethwire.MsgDiscTy, ""))
p.conn.Close()
}