-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
autonat: don't emit reachability changed events on address change #2092
Conversation
97c8a2b
to
e7c7980
Compare
e7c7980
to
d3d3173
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to keep the address
field on the autoNATresult
?
p2p/host/autonat/autonat.go
Outdated
@@ -286,10 +286,18 @@ func (as *AmbientAutoNAT) scheduleProbe() time.Duration { | |||
// Update the current status based on an observed result. | |||
func (as *AmbientAutoNAT) recordObservation(observation autoNATResult) { | |||
currentStatus := as.status.Load() | |||
|
|||
// Ignore public observations with no address | |||
if observation.Reachability == network.ReachabilityPublic && observation.address == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, this can't really happen. A successful observation will always contain a multiaddress, and if the peer sends a multiaddress that we can't decode, we'd record this as a ReachabilityUnknown
observation. We shouldn't do that either, we should discard that measurement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked. It cannot happen. cli.DialBack(ctx, pi.ID) ensures that address is not nil when err is nil.
I added this because TestAutoNATObservationRecording specifically has a check for this case.
I'll remove both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
It's used in the PublicAddr method which is used by host.AllAddrs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recordObservation
logic looks correct, and is a nice simplication.
p2p/host/autonat/autonat_test.go
Outdated
} | ||
select { | ||
case e := <-s.Out(): | ||
_, ok := e.(event.EvtLocalReachabilityChanged) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove the ok
assertion here. It's ok to panic (especially since it's a test), and would make the test more robust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I removed the assertion completely. The subscription is for reachability change, any event received here is an error in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @sukunrt!
fixes: #2046
@marten-seemann I've changed: