aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-01-18 00:14:59 +0800
committerobscuren <geffobscura@gmail.com>2014-01-18 00:14:59 +0800
commit87434a09418e6cc2dd4b92d7e35afc6f155994bc (patch)
tree76914e772618c2d31050ef63fbc3ea589a6a30d1 /peer.go
parentddf82c333702e22d3cd7e5c693ad0603089a57a4 (diff)
downloaddexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar.gz
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar.bz2
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar.lz
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar.xz
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.tar.zst
dexon-87434a09418e6cc2dd4b92d7e35afc6f155994bc.zip
Ping pong message
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/peer.go b/peer.go
index d876205e2..76a810063 100644
--- a/peer.go
+++ b/peer.go
@@ -34,6 +34,9 @@ type Peer struct {
// This flag is used by writeMessage to check if messages are allowed
// to be send or not. If no version is known all messages are ignored.
versionKnown bool
+
+ // Last received pong message
+ lastPong int64
}
func NewPeer(conn net.Conn, server *Server, inbound bool) *Peer {
@@ -109,7 +112,7 @@ func (p *Peer) writeMessage(msg *ethwire.InOutMsg) {
// Outbound message handler. Outbound messages are handled here
func (p *Peer) HandleOutbound() {
// The ping timer. Makes sure that every 2 minutes a ping is send to the peer
- tickleTimer := time.NewTimer(2 * time.Minute)
+ tickleTimer := time.NewTicker(2 * time.Minute)
out:
for {
select {
@@ -173,7 +176,10 @@ out:
case ethwire.MsgGetPeersTy:
case ethwire.MsgPeersTy:
case ethwire.MsgPingTy:
+ // Respond back with pong
+ p.writeMessage(&ethwire.InOutMsg{Type: ethwire.MsgPongTy})
case ethwire.MsgPongTy:
+ p.lastPong = time.Now().Unix()
/*
case "blockmine":