From dca3cb764272aa43c994d38bb1d23ba269a3e3ea Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 29 Apr 2020 20:18:19 -0700 Subject: [PATCH] fix: a type switch nit --- autonat.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/autonat.go b/autonat.go index cfde8b2..a11f940 100644 --- a/autonat.go +++ b/autonat.go @@ -171,8 +171,6 @@ func (as *AmbientAutoNAT) background() { timer := time.NewTimer(delay) defer timer.Stop() timerRunning := true - var peer peer.ID - for { select { // new inbound connection. @@ -188,7 +186,7 @@ func (as *AmbientAutoNAT) background() { } case e := <-subChan: - switch e.(type) { + switch e := e.(type) { case event.EvtLocalAddressesUpdated: if !lastAddrUpdated.Add(time.Second).After(time.Now()) { lastAddrUpdated = time.Now() @@ -197,13 +195,14 @@ func (as *AmbientAutoNAT) background() { } } case event.EvtPeerIdentificationCompleted: - peer = e.(event.EvtPeerIdentificationCompleted).Peer - if s, err := as.host.Peerstore().SupportsProtocols(peer, AutoNATProto); err == nil && len(s) > 0 { + if s, err := as.host.Peerstore().SupportsProtocols(e.Peer, AutoNATProto); err == nil && len(s) > 0 { currentStatus := as.status.Load().(autoNATResult) if currentStatus.Reachability == network.ReachabilityUnknown { - as.tryProbe(peer) + as.tryProbe(e.Peer) } } + default: + log.Errorf("unknown event type: %T", e) } // probe finished. @@ -213,7 +212,7 @@ func (as *AmbientAutoNAT) background() { } as.recordObservation(result) case <-timer.C: - peer = as.getPeerToProbe() + peer := as.getPeerToProbe() as.tryProbe(peer) timerRunning = false case <-as.ctx.Done():