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

protocols/{relay,dcutr}: Replace std::time::SystemTime with instant::SystemTime #2991

Merged
merged 8 commits into from
Oct 12, 2022

Conversation

thomaseizinger
Copy link
Contributor

@thomaseizinger thomaseizinger commented Oct 6, 2022

Description

I tried to safeguard against this by banning std::time::SystemTime::now via clippy.toml but unfortunately, it doesn't work because instant re-exports std when not compiling for wasm so it still gets flagged.

Links to any relevant issues

Open Questions

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

@fgimenez
Copy link

fgimenez commented Oct 7, 2022

Thanks for taking care @thomaseizinger I'm getting panics bc of this one too https://github.com/libp2p/rust-libp2p/blob/master/protocols/dcutr/src/protocol/outbound.rs#L29

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.

Just one small nit.

Thanks @thomaseizinger for the fix.

@fgimenez I am not sure how your WASM setup looks like. In case your local WASM node can not listen for incoming connections, I don't see a way how you can succeed in hole punching and thus I don't see the need for libp2p-dcutr. I am not saying we shouldn't do this change. Just a heads up. This will e.g. change for the browser world once we have WebRTC support. See libp2p/specs#412.

protocols/dcutr/src/protocol/outbound.rs Show resolved Hide resolved
@fgimenez
Copy link

fgimenez commented Oct 10, 2022

@fgimenez I am not sure how your WASM setup looks like.

Thanks for the heads up @mxinden, let me explain a bit the setup I've come up with, please don't hesitate to let me know if anything is wrong or should be done in a different way. My goal was to verify connectivity between WASM browser nodes through a relay v2 node, I was aiming to achieve something similar to what was described in this comment libp2p/js-libp2p-webrtc-direct#98 (comment). I have a wasm-pack based test case that spins up 2 browser nodes and a backend relay node, the setup looks like this:

Regarding the test case itself:

  • One of the browsers dials on the relayed multiaddr of the other, something like: /ip4/127.0.0.1/tcp/38615/ws/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN/p2p-circuit/p2p/12D3KooWP285Hw3CSTdr9oU6Ezz4hDoi6XS5vfDjjNeTJ1uFMGvp
  • each browser node checks that it receives a ping from the other.

The test is passing with the changes in this PR, I've attached logs for the 3 nodes
node-logs.zip

In case your local WASM node can not listen for incoming connections, I don't see a way how you can succeed in hole punching and thus I don't see the need for libp2p-dcutr. I am not saying we shouldn't do this change. Just a heads up. This will e.g. change for the browser world once we have WebRTC support. See libp2p/specs#412.

As explained above, this setup is working fine just with websockets, and as I understand it, it requires libp2p-dcutr to work, is that correct? please let me know if I'm missing something, or if this is not the right approach.

@thomaseizinger thomaseizinger changed the title protocols/relay: Replace std::time::SystemTime with instant::SystemTime protocols/{relay,dctur}: Replace std::time::SystemTime with instant::SystemTime Oct 11, 2022
@thomaseizinger thomaseizinger changed the title protocols/{relay,dctur}: Replace std::time::SystemTime with instant::SystemTime protocols/{relay,dcutr}: Replace std::time::SystemTime with instant::SystemTime Oct 11, 2022
@mxinden mxinden merged commit eb10af7 into master Oct 12, 2022
@mxinden
Copy link
Member

mxinden commented Oct 14, 2022

As explained above, this setup is working fine just with websockets, and as I understand it, it requires libp2p-dcutr to work, is that correct? please let me know if I'm missing something, or if this is not the right approach.

@fgimenez I am not sure I am following. Is the final connection between the two nodes a relayed or a direct connection?

DCUtR upgrades a relayed connection to a direct connection. In case you can not establish a direct connection (between two browsers), I don't see how DCUtR can help you.

libp2p/specs#412 will give you browser-to-server connectivity. For your WASM node you would need to adapt ExtTransport for the browser's WebRTC stack. This is a medium size undertaking. Contributions would be greatly appreciated.

Long term, libp2p/specs#412 will give you browser-to-browser connectivity including hole punching.

@fgimenez
Copy link

fgimenez commented Oct 14, 2022

@fgimenez I am not sure I am following. Is the final connection between the two nodes a relayed or a direct connection?

DCUtR upgrades a relayed connection to a direct connection. In case you can not establish a direct connection (between two browsers), I don't see how DCUtR can help you.

@mxinden you are right, one of the browsers is dialing the other on the relayed address, following the hole-punching example I added the DCUtR behaviour but I can see in the logs how the upgrade fails, the error comes from https://github.com/libp2p/rust-libp2p/blob/master/protocols/dcutr/src/protocol/inbound.rs#L57
I was confused because the test just checks for ping events, and each browser is able to receive a ping from the other one, will check more deeply how this works.

libp2p/specs#412 will give you browser-to-server connectivity. For your WASM node you would need to adapt ExtTransport for the browser's WebRTC stack. This is a medium size undertaking. Contributions would be greatly appreciated.

Awesome, would love to work on it, should be similar to what is done here for websockets right? https://github.com/libp2p/rust-libp2p/tree/master/transports/wasm-ext/src

Long term, libp2p/specs#412 will give you browser-to-browser connectivity including hole punching.

Very cool 👍

@mxinden
Copy link
Member

mxinden commented Oct 19, 2022

libp2p/specs#412 will give you browser-to-server connectivity. For your WASM node you would need to adapt ExtTransport for the browser's WebRTC stack. This is a medium size undertaking. Contributions would be greatly appreciated.

Awesome, would love to work on it, should be similar to what is done here for websockets right? https://github.com/libp2p/rust-libp2p/tree/master/transports/wasm-ext/src

Yes. Correct. Though it does include an additional Noise handshake and message framing. See libp2p/specs#412.

@thomaseizinger thomaseizinger deleted the 2984-fix-wasm-time branch November 17, 2022 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment