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(upnp): add implementation based on IGD protocol #4156

Merged
merged 66 commits into from Sep 12, 2023

Conversation

jxs
Copy link
Member

@jxs jxs commented Jul 4, 2023

Description

Implements UPnP via the IGD protocol. The usage of IGD is an implementation detail and is planned to be extended to support NATpnp.

Resolves: #3903.

Notes & open questions

As discussed, this hasn't yet any type of tests, since we need a network with a gateway with igd support. Feel free to suggest any ideas for testing.

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

@jxs jxs requested a review from thomaseizinger July 4, 2023 15:34
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.

Great work! I left some comments :)

protocols/upnp/Cargo.toml Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
protocols/upnp/src/provider.rs Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
@thomaseizinger
Copy link
Contributor

You will need to exclude this from WASM to have CI pass.

@dariusc93
Copy link
Contributor

As discussed, this hasn't yet any type of tests, since we need a network with a gateway with igd support. Feel free to suggest any ideas for testing.

Something i was going to do in the future for testing was write a small server that would emulate a gateway for igd. Maybe this is something you could do is have a server and run test against that?

protocols/upnp/Cargo.toml Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Outdated Show resolved Hide resolved
@jxs
Copy link
Member Author

jxs commented Jul 5, 2023

You will need to exclude this from WASM to have CI pass.

there's also the libssl-dev dependency on ubuntu, should we add it to the ci?

@thomaseizinger
Copy link
Contributor

You will need to exclude this from WASM to have CI pass.

there's also the libssl-dev dependency on ubuntu, should we add it to the ci?

Is there an option to use a different SSL stack?

@jxs
Copy link
Member Author

jxs commented Jul 6, 2023

You will need to exclude this from WASM to have CI pass.

there's also the libssl-dev dependency on ubuntu, should we add it to the ci?

Is there an option to use a different SSL stack?

unfortunately the async-std upstream library doesn't expose that. surf exposes rustls as a feature thou

Copy link
Member

@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.

Excited for this to land. Only drive-by comments.

Cargo.lock Show resolved Hide resolved
libp2p/Cargo.toml Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Outdated Show resolved Hide resolved
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.

Some more questions!

protocols/upnp/src/gateway.rs Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/upnp/src/gateway.rs Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
@thomaseizinger thomaseizinger changed the title feat(protocols): Add initial UPnP protocol feat(upnp): add implementation based on IGD protocol Jul 9, 2023
@mergify
Copy link

mergify bot commented Jul 9, 2023

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

@mergify
Copy link

mergify bot commented Sep 4, 2023

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

@jxs
Copy link
Member Author

jxs commented Sep 4, 2023

surf and consequently The async-std version is super flaky, running 10 times the example, in 6 I get this error:

Could this be the result of some form of garbage-collection? Are we dropping something somewhere and thus get connection resets?

hum, how could that be possible? We spawn the search_gateway task on the async-std executor and then wait for its output, it should be self contained no?

@thomaseizinger
Copy link
Contributor

surf and consequently The async-std version is super flaky, running 10 times the example, in 6 I get this error:

Could this be the result of some form of garbage-collection? Are we dropping something somewhere and thus get connection resets?

hum, how could that be possible? We spawn the search_gateway task on the async-std executor and then wait for its output, it should be self contained no?

Yeah that is what I would expect. I know that async-std does implicitly spawn new worker threads and also the reactor but I'd be surprised if that causes flakiness.

@mergify
Copy link

mergify bot commented Sep 5, 2023

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

Copy link
Member

@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.

I am fine moving forward here, i.e. merge. In case there is anything we can do to reduce the dependency footprint, that would be very much appreciated.

Cargo.lock Outdated Show resolved Hide resolved
examples/upnp/src/main.rs Outdated Show resolved Hide resolved
protocols/upnp/src/behaviour.rs Show resolved Hide resolved
@mergify
Copy link

mergify bot commented Sep 6, 2023

This pull request has merge conflicts. Could you please resolve them @jxs? 🙏

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.

Thank you for your patience @jxs! I think this is the right path forward :)

Cargo.lock Outdated Show resolved Hide resolved
libp2p/Cargo.toml Outdated Show resolved Hide resolved
libp2p/Cargo.toml Outdated Show resolved Hide resolved
protocols/upnp/Cargo.toml Outdated Show resolved Hide resolved
protocols/upnp/src/lib.rs Outdated Show resolved Hide resolved
examples/upnp/src/main.rs Outdated Show resolved Hide resolved
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.

Looks great! Well done and sorry for so much back and forth :)

@thomaseizinger
Copy link
Contributor

Let's go!

@thomaseizinger
Copy link
Contributor

@jxs can you go through the open conversations and resolve them if they are addressed? Github won't let us merge otherwise :)

@mergify mergify bot merged commit 411a049 into libp2p:master Sep 12, 2023
68 of 69 checks passed
@jxs
Copy link
Member Author

jxs commented Sep 12, 2023

@jxs can you go through the open conversations and resolve them if they are addressed? Github won't let us merge otherwise :)

done Thomas, thanks! Merged 🎉

@thomaseizinger
Copy link
Contributor

@jxs Mind updating the roadmap? https://github.com/libp2p/rust-libp2p/blob/master/ROADMAP.md#automate-port-forwarding-eg-via-upnp

@jxs
Copy link
Member Author

jxs commented Sep 20, 2023

btw, can we release libp2p-upnp 0.1?

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.

feat: automate port-forwarding e.g. via UPnP
6 participants