Removed peer disconnect on pong timeout. Fixes #106

This mechanism wasn't very accurate so it has been removed.
pull/150/head
obscuren 10 years ago
parent 1f9894c084
commit 42d47ecfb0
  1. 34
      peer.go

@ -294,12 +294,14 @@ out:
// Ping timer // Ping timer
case <-pingTimer.C: case <-pingTimer.C:
timeSince := time.Since(time.Unix(p.lastPong, 0)) /*
if !p.pingStartTime.IsZero() && p.lastPong != 0 && timeSince > (pingPongTimer+30*time.Second) { timeSince := time.Since(time.Unix(p.lastPong, 0))
peerlogger.Infof("Peer did not respond to latest pong fast enough, it took %s, disconnecting.\n", timeSince) if !p.pingStartTime.IsZero() && p.lastPong != 0 && timeSince > (pingPongTimer+30*time.Second) {
p.Stop() peerlogger.Infof("Peer did not respond to latest pong fast enough, it took %s, disconnecting.\n", timeSince)
return p.Stop()
} return
}
*/
p.writeMessage(ethwire.NewMessage(ethwire.MsgPingTy, "")) p.writeMessage(ethwire.NewMessage(ethwire.MsgPingTy, ""))
p.pingStartTime = time.Now() p.pingStartTime = time.Now()
@ -354,7 +356,7 @@ func (p *Peer) HandleInbound() {
} }
case ethwire.MsgDiscTy: case ethwire.MsgDiscTy:
p.Stop() p.Stop()
peerlogger.Infoln("Disconnect peer:", DiscReason(msg.Data.Get(0).Uint())) peerlogger.Infoln("Disconnect peer: ", DiscReason(msg.Data.Get(0).Uint()))
case ethwire.MsgPingTy: case ethwire.MsgPingTy:
// Respond back with pong // Respond back with pong
p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, "")) p.QueueMessage(ethwire.NewMessage(ethwire.MsgPongTy, ""))
@ -363,11 +365,17 @@ func (p *Peer) HandleInbound() {
// last pong so the peer handler knows this peer is still // last pong so the peer handler knows this peer is still
// active. // active.
p.lastPong = time.Now().Unix() p.lastPong = time.Now().Unix()
p.pingTime = time.Now().Sub(p.pingStartTime) p.pingTime = time.Since(p.pingStartTime)
case ethwire.MsgBlockTy: case ethwire.MsgBlockTy:
// Get all blocks and process them // Get all blocks and process them
var block, lastBlock *ethchain.Block //var block, lastBlock *ethchain.Block
var err error //var err error
var (
block, lastBlock *ethchain.Block
blockChain = p.ethereum.BlockChain()
err error
)
// Make sure we are actually receiving anything // Make sure we are actually receiving anything
if msg.Data.Len()-1 > 1 && p.diverted { if msg.Data.Len()-1 > 1 && p.diverted {
@ -383,11 +391,11 @@ func (p *Peer) HandleInbound() {
for i := msg.Data.Len() - 1; i >= 0; i-- { for i := msg.Data.Len() - 1; i >= 0; i-- {
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i)) block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
// Do we have this block on our chain? If so we can continue // Do we have this block on our chain? If so we can continue
if !p.ethereum.StateManager().BlockChain().HasBlock(block.Hash()) { if !blockChain.HasBlock(block.Hash()) {
// We don't have this block, but we do have a block with the same prevHash, diversion time! // We don't have this block, but we do have a block with the same prevHash, diversion time!
if p.ethereum.StateManager().BlockChain().HasBlockWithPrevHash(block.PrevHash) { if blockChain.HasBlockWithPrevHash(block.PrevHash) {
p.diverted = false p.diverted = false
if !p.ethereum.StateManager().BlockChain().FindCanonicalChainFromMsg(msg, block.PrevHash) { if !blockChain.FindCanonicalChainFromMsg(msg, block.PrevHash) {
p.SyncWithPeerToLastKnown() p.SyncWithPeerToLastKnown()
break nextMsg break nextMsg
} }

Loading…
Cancel
Save