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

autonatv2: implement autonatv2 spec #2469

Merged
merged 10 commits into from
Jun 21, 2024
Merged

autonatv2: implement autonatv2 spec #2469

merged 10 commits into from
Jun 21, 2024

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Aug 10, 2023

closes: #2422

Will add metrics for this in a separate PR.

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.

Partial review. I might be missing something, but where is the logic which address to check next? Or is that left for the implementation of the address pipeline?

p2p/host/basic/basic_host.go Outdated Show resolved Hide resolved
p2p/host/eventbus/basic.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
@sukunrt
Copy link
Member Author

sukunrt commented Aug 13, 2023

Partial review. I might be missing something, but where is the logic which address to check next? Or is that left for the implementation of the address pipeline?

Yes, that part will go in the address pipeline.

@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 2 times, most recently from e09ef04 to c55e2af Compare August 14, 2023 17:07
@sukunrt sukunrt marked this pull request as ready for review August 21, 2023 17:12
@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 5 times, most recently from 6149b00 to 83babed Compare August 27, 2023 10:10
@p-shahi p-shahi mentioned this pull request Aug 31, 2023
25 tasks
@p-shahi p-shahi removed the request for review from marten-seemann February 22, 2024 16:45
@sukunrt sukunrt marked this pull request as draft April 23, 2024 15:57
@sukunrt sukunrt marked this pull request as ready for review April 26, 2024 06:32
@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 5 times, most recently from 3ff9598 to a3138cf Compare May 23, 2024 18:26
@MarcoPolo MarcoPolo self-requested a review May 28, 2024 22:06
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

First pass. I think this is looks good! I want to think about any vulnerabilities here.

core/network/network.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/autonat.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/options.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

First pass. I think this is looks good! I want to think about any vulnerabilities here.

@sukunrt sukunrt force-pushed the sukun/autonat-v2-2 branch 2 times, most recently from f212a0f to 0aa1911 Compare June 5, 2024 18:10
@sukunrt sukunrt requested a review from MarcoPolo June 5, 2024 18:21
@MarcoPolo
Copy link
Collaborator

Can we default to having autonatv2 disabled initially? I want folks to opt-in to it at the start until we gain some more confidence with experience.

Copy link
Collaborator

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

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

Just a couple comments left. I think this is good after those are addressed and we change this to be opt-in.

core/network/network.go Show resolved Hide resolved
p2p/protocol/autonatv2/client.go Outdated Show resolved Hide resolved
p2p/net/swarm/black_hole_detector.go Outdated Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
@sukunrt sukunrt requested a review from MarcoPolo June 18, 2024 13:51
lenBuf = lenBuf[:n]

for remain := numBytes; remain > 0; {
_, err = w.Write(lenBuf)
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't this overshoot the amount of data to dial? The old version did ddResp.Data = ddResp.Data[:end].

fwiw, I think extra allocs on the client side matter less than on the server side. I would be okay if the code path on the client side was straightforward at the expense of a couple extra allocs (what we had before was fine.)

Copy link
Member Author

@sukunrt sukunrt Jun 19, 2024

Choose a reason for hiding this comment

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

I agree with the suggestion to remove this on the client. We can always add this side later on when we start using this from rest of the code.

won't this overshoot the amount of data to dial?

I think this is okay. Servers should handle this case. It's only 4kB more.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should update the spec if the client may send a bit more data.

p2p/protocol/autonatv2/server.go Show resolved Hide resolved
p2p/protocol/autonatv2/server.go Outdated Show resolved Hide resolved
@sukunrt sukunrt merged commit 87c4355 into master Jun 21, 2024
12 checks passed
mergify bot pushed a commit to libp2p/rust-libp2p that referenced this pull request Aug 8, 2024
Closes: #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 #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: #5526.
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.
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.

Implement AutoNATv2
3 participants