Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #83 from libp2p/fix/switch-nit
Browse files Browse the repository at this point in the history
fix: a type switch nit
  • Loading branch information
Stebalien authored Apr 30, 2020
2 parents ee3e1b3 + dca3cb7 commit 31cf5b7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand All @@ -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.
Expand All @@ -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():
Expand Down

0 comments on commit 31cf5b7

Please sign in to comment.