Skip to content
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

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Feb 14, 2023

fixes: #2046

@marten-seemann I've changed:

  1. No events are emitted if only the observed address is changed.
  2. All observations with reachability = Public and addr = nil are ignored.
    • previously this caused an increase in confidence.
  3. transition from unknown to private now begins with confidence = 0.
    • previously this begin with confidence = 1

@sukunrt sukunrt changed the title don't emit reachability changed events on address change autonat: don't emit reachability changed events on address change Feb 14, 2023
Copy link
Contributor

@marten-seemann marten-seemann left a 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?

@@ -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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@sukunrt
Copy link
Member Author

sukunrt commented Feb 15, 2023

Is there any reason to keep the address field on the autoNATresult?

It's used in the PublicAddr method which is used by host.AllAddrs.
This seems to me that it is mostly redundant information with information received from the ObservedAddressManager.

Copy link
Contributor

@marten-seemann marten-seemann left a 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.

}
select {
case e := <-s.Out():
_, ok := e.(event.EvtLocalReachabilityChanged)
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @sukunrt!

@marten-seemann marten-seemann merged commit 84f2278 into libp2p:master Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autonat (?): node frequently changes its mind about its reachability status
2 participants