From f8345d38fb04ce45f5a984d0ec8eecc3f56cbb0d Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 22 Apr 2019 16:05:10 -0700 Subject: [PATCH] peer: only set ping time once As a preliminary step to integrating the separated WriteMessage and Flush calls in the peer, we'll modify the peer to only set a timestamp on Ping messages once. This makes sense for two reasons, 1) if the message has already been partially written, we have already committed to a ping time, and 2) a ciphertext containing the first ping time will already be buffered in the connection, and we will only be attempting to Flush on timeout errors. --- peer.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/peer.go b/peer.go index e227d141d..9a5edc057 100644 --- a/peer.go +++ b/peer.go @@ -1468,6 +1468,17 @@ out: for { select { case outMsg := <-p.sendQueue: + // If we're about to send a ping message, then log the + // exact time in which we send the message so we can + // use the delay as a rough estimate of latency to the + // remote peer. + if _, ok := outMsg.msg.(*lnwire.Ping); ok { + // TODO(roasbeef): do this before the write? + // possibly account for processing within func? + now := time.Now().UnixNano() + atomic.StoreInt64(&p.pingLastSend, now) + } + // Record the time at which we first attempt to send the // message. startTime := time.Now() @@ -1491,17 +1502,6 @@ out: } } - // If we're about to send a ping message, then log the - // exact time in which we send the message so we can - // use the delay as a rough estimate of latency to the - // remote peer. - if _, ok := outMsg.msg.(*lnwire.Ping); ok { - // TODO(roasbeef): do this before the write? - // possibly account for processing within func? - now := time.Now().UnixNano() - atomic.StoreInt64(&p.pingLastSend, now) - } - // Write out the message to the socket. If a timeout // error is encountered, we will catch this and retry // after backing off in case the remote peer is just