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.
This commit is contained in:
parent
6bc32871fd
commit
f8345d38fb
22
peer.go
22
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
|
||||
|
Loading…
Reference in New Issue
Block a user