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

relay: making a reservation should emit an external address #4618

Closed
thomaseizinger opened this issue Oct 10, 2023 · 11 comments · Fixed by #4809
Closed

relay: making a reservation should emit an external address #4618

thomaseizinger opened this issue Oct 10, 2023 · 11 comments · Fixed by #4809
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@thomaseizinger
Copy link
Contributor

Description

When we make a reservation with a relay, we essentially now have an external address that other nodes can use to connect to us. We should emit a ToSwarm::ExternalAddrConfirmed event to let the Swarm know about this. Similarly, if our reservation expires, we should remove the external address again via ToSwarm::ExternalAddrExpired.

Motivation

Emitting these events allows protocols like libp2p-identify to pick up these addresses and advertise them to other nodes.

Current Implementation

Only the following ReservationReqAccepted event is emitted:

ReservationReqAccepted {
relay_peer_id: PeerId,
/// Indicates whether the request replaces an existing reservation.
renewal: bool,
limit: Option<protocol::Limit>,
},

Are you planning to do it yourself in a pull request ?

No

@thomaseizinger thomaseizinger added difficulty:easy help wanted decision-pending Marks issues where a decision is pending before we can move forward. labels Oct 10, 2023
@thomaseizinger
Copy link
Contributor Author

@mxinden Anything you can think of why we shouldn't do this?

@mxinden
Copy link
Member

mxinden commented Oct 10, 2023

Proposal sounds good to me! I don't see any blockers.

@mxinden mxinden added difficulty:easy help wanted getting-started Issues that can be tackled if you don't know the internals of libp2p very well and removed decision-pending Marks issues where a decision is pending before we can move forward. labels Oct 10, 2023
@thomaseizinger
Copy link
Contributor Author

In a similar vein, currently we make a reservation with every relay we connect to. Should we perhaps limit this e.g. 10? That sounds plenty 😁

@mxinden
Copy link
Member

mxinden commented Oct 10, 2023

we make a reservation with every relay we connect to

Oh, that is news to me. Can you point me to the code?

As far as I can tell, we don't react to it at all, no?

| ConnectionEvent::RemoteProtocolsChange(_) => {}

@thomaseizinger
Copy link
Contributor Author

thomaseizinger commented Oct 10, 2023

we make a reservation with every relay we connect to

Oh, that is news to me. Can you point me to the code?

I thought we did but maybe that is not true. I guess we only do it when the users explicitly requests listen_on, right? That is all fine then. I thought we had a similar AutoRelay functionality as go-libp2p.

cc @dariusc93 I remember you building an auto-relay like functionality, correct? What was your experience with it?

@mxinden
Copy link
Member

mxinden commented Oct 11, 2023

I guess we only do it when the users explicitly requests listen_on, right?

Correct.

@dariusc93
Copy link
Member

cc @dariusc93 I remember you building an auto-relay like functionality, correct? What was your experience with it?

I did have to backtrack on some of the functionality since it was going to get overly complex (eg emitting events to swarm to find relays over DHT, etc), but one thing I have done is emit an event to provide an external addr after the reservation is made. This, honestly should be in rust-libp2p and should be simple to do

@thomaseizinger
Copy link
Contributor Author

cc @dariusc93 I remember you building an auto-relay like functionality, correct? What was your experience with it?

I did have to backtrack on some of the functionality since it was going to get overly complex (eg emitting events to swarm to find relays over DHT, etc)

I haven't thought much about it so perhaps there is a flaw but I was imagining something like:

  • auto_relay::Behaviour
  • Has a config for how many relayed connections we want to aim for (something like 10 as a default)
  • On each new (outgoing?) connection, examine the supported protocols of the remote and report to Behaviour whether relay is supported
  • If we are < than our desired reservation count, use ToSwarm::ListenOn to make a new reservation using one of the supported relays

@dariusc93
Copy link
Member

I haven't thought much about it so perhaps there is a flaw but I was imagining something like:

* `auto_relay::Behaviour`

* Has a config for how many relayed connections we want to aim for (something like 10 as a default)

* On each new (outgoing?) connection, examine the supported protocols of the remote and report to `Behaviour` whether relay is supported

* If we are < than our desired reservation count, use `ToSwarm::ListenOn` to make a new reservation using one of the supported relays

Minus the reservation count, thats one way i have it setup currently (which might be best for rust-libp2p too), though disabled by default (since some nodes may advertise the hop protocol but may also be sitting behind a relay themselves - see #4260 on how to possibly resolve that) so right now, one can manually adding peers and their addrs, then they can either select a specific relay, or let it randomly select, in which we would connect, validate their protocol in the handler and pass that status to the behaviour, for that peer move on from there.

@thomaseizinger
Copy link
Contributor Author

Oh yeah, forgot about #4260. We should get that fixed. I'll open a separate issue for an Auto-Relay like functionality.

@thomaseizinger
Copy link
Contributor Author

I'll open a separate issue for an Auto-Relay like functionality.

Done here: #4651

@mergify mergify bot closed this as completed in #4809 Nov 14, 2023
mergify bot pushed a commit that referenced this issue Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants