libp2p / rust-libp2p

The Rust Implementation of the libp2p networking stack.
https://libp2p.io
MIT License
4.49k stars 930 forks source link

relay: Enable and disable advertisment of protocol #4260

Open dariusc93 opened 1 year ago

dariusc93 commented 1 year ago

Description

Add a feature to [automatically and manually] enable and disable the relay v2 HOP protocol advertisement.

Motivation

Currently, when a local node runs with the relay v2 HOP behaviour, it would advertise its protocol regardless of if the node can be connected to or not, including if the node itself is connected to a relay where itself cannot be use the HOP protocol (though not sure if this will ever happen in the future if spec calls for this). Example would be if the node doesnt have an external address that the protocol would not be advertised until one is available (eg waiting for upnp or port mapping, autonat, etc)

Another reason would be if a node who is serving as a relay v2 HOP decides for whatever reason that they no longer wish to serve as a relay, they can disable its services at runtime without needing to reboot the node itself to disable it, giving more flexibility to the node itself.

Open questions

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

Maybe, if nobody else is interested in doing this

thomaseizinger commented 1 year ago

This sounds like a great idea! We can follow the design in libp2p-kad and - by default - do this automatically based on our external addresses with an option to override it.

Thoughts @mxinden @dariusc93 ?

thomaseizinger commented 1 year ago

@dariusc93 Can you investigate what go-libp2p does here? Would you mind discussing this on the specs level? I think it would make sense to include this in an "implementation considerations" section.

mxinden commented 1 year ago

General note, I am in favor of this proposal. Thank you @dariusc93 for suggesting it.

Seems like go-libp2p disables the relaysvc (I am guessing the server side), when its reachability changes to private:

https://github.com/libp2p/go-libp2p/blob/f6fb4f555ba26ada855b10506e156e39896b670f/p2p/host/relaysvc/relay.go#L65-L90