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: Implement circuit relay v2 protocol #2059

Merged
merged 129 commits into from
Jan 14, 2022

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Apr 26, 2021

This pull request adds an implementation for the circuit relay v2 protocol to be used as a relay server and client, i.e. it supports incoming/outgoing HOP requests and incoming/outgoing STOP requests. The circuit relay v2 protocol is an integral part of Project Flare - bringing NAT / Firewall hole punching to libp2p.

You can find an example in protocols/relay/examples/relay_v2.rs and a full relay server implementation in https://github.com/mxinden/rust-libp2p-relay-server.

The existing circuit relay v1 protocol implementation is moved to protocols/relay/src/v1.

This commit adds an implementation for the circuit relay v2 protocol to
be used as a relay server, i.e. it supports incoming HOP requests and
outgoing STOP requests. Future commits will add support for clients,
i.e. outgoing HOP requests and incoming STOP requests.

The existing circuit relay v1 protocol implementation is moved to
protocols/relay/src/v1.
@mxinden
Copy link
Member Author

mxinden commented Jan 10, 2022

@thomaseizinger @elenaf9 @MarcoPolo if I am not mistaken I addressed all comments. Any other suggestions from your side?

@mxinden
Copy link
Member Author

mxinden commented Jan 13, 2022

Unless there are any further suggestions, I will merge here tomorrow.

Copy link
Contributor

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

I took another pass at this, and it looks great! Excited to see this in. I had two comments but they are small nit/question. Feel free to ignore or do in a separate PR.

assert!(pool.run_until(wait_for_dial(&mut client, relay_peer_id)));

client.listen_on(client_addr.clone()).unwrap();
pool.run_until(wait_for_reservation(
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't exactly check that it resuses the connection right? Should this instead use a modified version of wait_for_reservation that panics if it tries dialing/connectionestablished?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nicely spotted. Thanks. Fixed with 80a9e76.

}

self.queued_events.push_back(ProtocolsHandlerEvent::Custom(
Event::OutboundCircuitEstablished { limit },
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still want to push this event if the send_back.send failed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Fixed in b1cb684.

@mxinden mxinden merged commit 17ee504 into libp2p:master Jan 14, 2022
@mxinden
Copy link
Member Author

mxinden commented Jan 14, 2022

Wow, 232 comments. Definitely a record for me. Thank you all for the help on this effort! The many thorough reviews really show the power of open source. ❤️

mxinden added a commit to mxinden/rust-libp2p that referenced this pull request Jan 15, 2022
This commit adds an implementation for the circuit relay v2 protocol to be used
as a relay server, i.e. it supports incoming HOP requests and outgoing STOP
requests and used as a relay clients, i.e. outgoing HOP requests and incoming
STOP requests.

The existing circuit relay v1 protocol implementation is moved to
protocols/relay/src/v1.

Co-authored-by: ronzigelman <ronzigelman@gmail.com>
Co-authored-by: Marco Munizaga <git@marcopolo.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Elena Frank <57632201+elenaf9@users.noreply.github.com>
@mxinden mxinden mentioned this pull request Apr 9, 2023
4 tasks
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.

None yet

10 participants