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(p2p): implement hole punching #126

Merged
merged 2 commits into from
Jun 19, 2022
Merged

feat(p2p): implement hole punching #126

merged 2 commits into from
Jun 19, 2022

Conversation

dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Jun 18, 2022

  • integrate libp2p::autonat
  • integrate libp2p::dcutr and libp2p::relay::v2

Closes n0-computer/beetle#240

@dignifiedquire dignifiedquire marked this pull request as draft June 18, 2022 19:40
@dignifiedquire dignifiedquire changed the title feat(p2p): integrate autonat protocol feat(p2p): implement hole punching Jun 18, 2022
@dignifiedquire dignifiedquire marked this pull request as ready for review June 19, 2022 11:52
Copy link
Collaborator

@Arqu Arqu left a comment

Choose a reason for hiding this comment

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

Did a quick skim, pretty small surface and LGTM, let's get this merged and gather some data

@dignifiedquire dignifiedquire merged commit 684e6d9 into main Jun 19, 2022
@dignifiedquire dignifiedquire deleted the feat-autonat branch June 19, 2022 15:27
@mxinden
Copy link

mxinden commented Jun 20, 2022

🚀 I will take a closer look.

Copy link

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Let me know how well this is working. Also let me know in case you need any additional infrastructure to test this against.

(Hole punching client side is slowly rolling out on IPFS, thus you might as well already be able to punch with a Golang client.)

Again, happy to see this happening!

Comment on lines +41 to +42
relay_client: Toggle<relay::v2::client::Client>,
dcutr: Toggle<dcutr::behaviour::Behaviour>,
Copy link

Choose a reason for hiding this comment

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

Ideally we would have an AndBehaviour, that way you could do:

hole_punching_client: Toggle<AndBehaviour<relay::v2::client::Client, dcutr::behaviour::Behaviour>>`

That way it is enforced at compile time that you always either enable both or disable both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that would would be nice

Copy link

Choose a reason for hiding this comment

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

👍 Tracked here: libp2p/rust-libp2p#2719

// TODO: should we remove them at some point?
if protocols
.iter()
.any(|p| p.as_bytes() == b"/libp2p/autonat/1.0.0")
Copy link

Choose a reason for hiding this comment

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

How about exposing the protocol ID as a constant from libp2p-autonat and using that here instead?

https://github.com/libp2p/rust-libp2p/blob/ea487aebfe6eb672b05d2bec2d9d79bbd92450ba/protocols/autonat/src/protocol.rs#L34

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, that's the todo above, I can make a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

yep, that's the todo above

Uuups 🤦

Thanks!

.as_mut()
.map(|k| k.add_address(&peer_id, addr));
if let Some(autonat) = self.swarm.behaviour_mut().autonat.as_mut() {
autonat.add_server(peer_id, Some(addr));
Copy link

Choose a reason for hiding this comment

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

As mentioned elsewhere, using autonat::Config::use_connected might be good enough. Though adding them explicitly and thus knowing for sure that they support the autonat protocol is likely the better bet.

For the record, this would be simplified with libp2p/rust-libp2p#2680.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to be sure 😅 so did both for now

let transport = transport
.upgrade(core::upgrade::Version::V1Lazy)
.authenticate(auth_config)
.multiplex(mplex_config)
Copy link

Choose a reason for hiding this comment

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

Not related to this pull request, though very relevant in general, why use mplex and not yamux or both with a preference on yamux?

libp2p/specs#402

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if you look a little above it is actually both mplex and yamux just the name is wrong 😅

Copy link

Choose a reason for hiding this comment

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

👍 Please keep prioritizing Yamux over Mplex.

.boxed()
if config.relay_client {
let (relay_transport, relay_client) =
libp2p::relay::v2::client::Client::new_transport_and_behaviour(
Copy link

Choose a reason for hiding this comment

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

Hope the creation of the NetworkBehaviour and the Transport was OK to follow. Tried to make it impossible to missuse at compile time, likely at the expense of being easy to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, a little unfortunate to have to pass these around, but was quite clear from the types and the example, what needed to be done 👍

@dignifiedquire
Copy link
Contributor Author

Let me know how well this is working. Also let me know in case you need any additional infrastructure to test this against.

First indicators are good, suggesting an increase in addrs we are able to dial succesfully

@dignifiedquire
Copy link
Contributor Author

@mxinden currently there is no metrics implementation for relay::client::Event, would probably be good to add so we can record data about that as well.

dignifiedquire pushed a commit that referenced this pull request Feb 20, 2023
refactor: make on_collection take a reference
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.

feat(p2p): add hole punching
3 participants