From 5066b824a6ed9535c238496d6219ac0035e754ee Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 24 Jul 2020 11:18:35 -0700 Subject: [PATCH] wgengine/magicsock: don't log about disco ping timeouts if we have a working address Signed-off-by: Brad Fitzpatrick --- wgengine/magicsock/magicsock.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 82e4c219e..516ea0610 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -2969,6 +2969,19 @@ func (de *discoEndpoint) send(b []byte) error { return err } +func (de *discoEndpoint) pingTimeout(txid stun.TxID) { + de.mu.Lock() + defer de.mu.Unlock() + sp, ok := de.sentPing[txid] + if !ok { + return + } + if debugDisco || de.bestAddr.IsZero() || time.Now().After(de.trustBestAddrUntil) { + de.c.logf("magicsock: disco: timeout waiting for pong %x from %v (%v, %v)", txid[:6], sp.to, de.publicKey.ShortString(), de.discoShort) + } + de.removeSentPingLocked(txid, sp) +} + // forgetPing is called by a timer when a ping either fails to send or // has taken too long to get a pong reply. func (de *discoEndpoint) forgetPing(txid stun.TxID) { @@ -3022,12 +3035,9 @@ func (de *discoEndpoint) startPingLocked(ep netaddr.IPPort, now time.Time, purpo txid := stun.NewTxID() de.sentPing[txid] = sentPing{ - to: ep, - at: now, - timer: time.AfterFunc(pingTimeoutDuration, func() { - de.c.logf("magicsock: disco: timeout waiting for pong %x from %v (%v, %v)", txid[:6], ep, de.publicKey.ShortString(), de.discoShort) - de.forgetPing(txid) - }), + to: ep, + at: now, + timer: time.AfterFunc(pingTimeoutDuration, func() { de.pingTimeout(txid) }), purpose: purpose, } logLevel := discoLog