aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-01-18 22:22:07 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 21:32:56 +0800
commit9c9bf2e717af53640833b898c7a319b2f4803242 (patch)
tree4857d9b7bee64d0fa9be9e734262d8e76765c2c3 /p2p/peer.go
parent5f47911fd3f9f98c69fc585bce64d27f924c90df (diff)
downloaddexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar.gz
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar.bz2
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar.lz
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar.xz
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.tar.zst
dexon-9c9bf2e717af53640833b898c7a319b2f4803242.zip
p2p: report latency and relative latency to datadog (#162)
Diffstat (limited to 'p2p/peer.go')
-rw-r--r--p2p/peer.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/p2p/peer.go b/p2p/peer.go
index 3d6ce9dcd..9183082a1 100644
--- a/p2p/peer.go
+++ b/p2p/peer.go
@@ -260,7 +260,7 @@ func (p *Peer) pingLoop() {
for {
select {
case <-ping.C:
- if err := SendItems(p.rw, pingMsg); err != nil {
+ if err := SendItems(p.rw, pingMsg, uint64(time.Now().UnixNano())); err != nil {
p.protoErr <- err
return
}
@@ -290,8 +290,14 @@ func (p *Peer) readLoop(errc chan<- error) {
func (p *Peer) handle(msg Msg) error {
switch {
case msg.Code == pingMsg:
- msg.Discard()
- go SendItems(p.rw, pongMsg)
+ var pingTime [1]uint64
+ rlp.Decode(msg.Payload, &pingTime)
+ peerRelativeLatency.Update((time.Now().UnixNano() - int64(pingTime[0])) / 1000)
+ go SendItems(p.rw, pongMsg, pingTime[0])
+ case msg.Code == pongMsg:
+ var pingTime [1]uint64
+ rlp.Decode(msg.Payload, &pingTime)
+ peerLatency.Update((time.Now().UnixNano() - int64(pingTime[0])) / 2 / 1000)
case msg.Code == discMsg:
var reason [1]DiscReason
// This is the last message. We don't need to discard or