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

feat(autonat): Implement AutoNATv2 #5526

Merged
merged 248 commits into from
Aug 8, 2024

Conversation

umgefahren
Copy link
Contributor

@umgefahren umgefahren commented Aug 4, 2024

Description

Closes: #4524

This is the implementation of the evolved AutoNAT protocol, named AutonatV2 as defined in the spec.
The stabilization PR for the spec can be found under libp2p/specs#538.

The work on the Rust implementation can be found in the PR to my fork: umgefahren#1.

The implementation has been smoke-tested with the Go implementation (PR: libp2p/go-libp2p#2469).

The new protocol addresses shortcomings of the original AutoNAT protocol:

  • Since the server now always dials back over a newly allocated port, this made refactor(*): Transport redesign #4568 necessary; the client can be sure of the reachability state for other peers, even if the connection to the server was made through a hole punch.
  • The server can now test addresses different from the observed address (i.e., the connection to the server was made through a p2p-circuit). To mitigate against DDoS attacks, the client has to send more data to the server than the dial-back costs.

Notes & open questions

Notes

IPv4 & IPv6

There are open questions on how to handle cases where a client is only reachable over IPv4 or IPv6, but the server is connected to a network with an incompatible IP family.

Relevant comments in the other PR:

The decision was made to ship the improvement in a later version, when we know more about the issue. It's still an improvement over AutoNATv1.

Handling these cases would be easier once rust-lang/rust#86442 is merged.

Picking algorithm

The spec proposes a picking algorithm for the address tested by the server. At the moment, the server is just using the first address sent by the client. An improvement to this algorithm can be implemented later.

Open questions

  • Should we replace the deprecated v1 version in libp2p-server?

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

This work was sponsored by the Filecoin grant program: filecoin-project/devgrants#1421

…n if we already have a listener for outgoing connections.
@umgefahren umgefahren marked this pull request as ready for review August 4, 2024 15:02
@umgefahren umgefahren mentioned this pull request Aug 4, 2024
4 tasks
@umgefahren
Copy link
Contributor Author

@jxs this already got an approving review over on umgefahren#1 but it wouldn't hurt if you took a look at it before merging.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Nice work @umgefahren ! This has been vetted extensively in your fork already, so good to go from my end.

examples/autonatv2/src/lib.rs Outdated Show resolved Hide resolved
protocols/autonat/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/autonat/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work Hannes, and again Thomas for the review! ❤️

examples/autonat/src/bin/autonat_client.rs Outdated Show resolved Hide resolved
examples/autonatv2/src/lib.rs Outdated Show resolved Hide resolved
@jxs jxs added the send-it label Aug 8, 2024
@umgefahren
Copy link
Contributor Author

Thanks for all the hard work Hannes, and again Thomas for the review! ❤️

It was a pleasure and I'm so grateful we are here.

@mergify mergify bot merged commit 848e2e9 into libp2p:master Aug 8, 2024
72 checks passed
TimTinkers pushed a commit to unattended-backpack/rust-libp2p that referenced this pull request Sep 14, 2024
Closes: libp2p#4524

This is the implementation of the evolved AutoNAT protocol, named AutonatV2 as defined in the [spec](https://github.com/libp2p/specs/blob/03718ef0f2dea4a756a85ba716ee33f97e4a6d6c/autonat/autonat-v2.md).
The stabilization PR for the spec can be found under libp2p/specs#538.

The work on the Rust implementation can be found in the PR to my fork: umgefahren#1.

The implementation has been smoke-tested with the Go implementation (PR: libp2p/go-libp2p#2469).

The new protocol addresses shortcomings of the original AutoNAT protocol:

- Since the server now always dials back over a newly allocated port, this made libp2p#4568 necessary; the client can be sure of the reachability state for other peers, even if the connection to the server was made through a hole punch.
- The server can now test addresses different from the observed address (i.e., the connection to the server was made through a `p2p-circuit`). To mitigate against DDoS attacks, the client has to send more data to the server than the dial-back costs.

Pull-Request: libp2p#5526.
@b-zee
Copy link
Contributor

b-zee commented Nov 17, 2024

I've been testing out this v2 protocol. When testing locally I see that my loopback address is being confirmed as external address. I'm curious if this is designed on purpose like that. E.g. would I need to remove the external address in logic for ExternalAddrConfirmed? Or is there a way to prevent the loopback address to be confirmed/probed at all?

I'd happily make an issue for this, but perhaps I am using the behaviour wrong as there isn't a lot of surface documentation on the usage. (The v1 protocol has built-in confidence logic, which I reckon we're supposed to implement ourselves in v2, which I fully stand behind, but just wondering how this is supposed to work.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AutoNAT v2
5 participants