dariusc93 / rust-ipfs

The InterPlanetary File System (IPFS), implemented in Rust.
Apache License 2.0
42 stars 8 forks source link

Auto relay connection #4

Open dariusc93 opened 2 years ago

dariusc93 commented 2 years ago

Should add a option to add listen on a relay automatically while behind a NAT. This would allow us to walk through DHT and find any peers that has the relay v2 protocol in which case we would then listen to it automatically. There are a couple of things that might need to be done

  1. Build up a map to keep track of active peers with the relay protocol
  2. Determine the max number we can and should listen on (eg does it do anything to listen on multiple relays as been done manually?).
  3. Only use relays when behind a nat or firewall, otherwise dont use relays unless connection is being blocked in some way.
  4. Track the ListenId after doing Swarm::listen_on and use it to remove the listener when there is an issue related to it

Draft should be first implemented into this crate and once its figured out to split it out into its own crate (or implement directly into libp2p?).

dariusc93 commented 1 year ago

This will be done inside of a behaviour which would allow static relays (one users can add themselves) as well as an option to add relays while walking DHT.

Thought: (WIP - not exactly final and may not reflect actual implementation)

Overall:

Static Relays:

Dynamic (or auto) Relays:

Questions:

  1. In the event of peers not using DHT, should we allow peers to share their relays with each other? Possibly through request-response protocol? Not really needed in the short or long term though but might be a nice thing to have for exchanging relays and building up one own list in the event of DHT not being used.
  2. Should we allow both static and dynamic relays or have it so one or the other (but not both) could be used?
  3. Should we build on top of relay protocol or should be keep this separate from the protocol and incorporate it into the swarm at specific events points?
  4. Should a single candidate limit be per peer id (which would contains multiple addresses) or per address?
  5. Although should not be relied on, should we have the default relays set for ipfs/libp2p bootstrap?
    • Note that while this is possible, there may be times where they may not be suitable for being used as relays so maybe we shouldnt default to them.
  6. How would connection limits impact relay usage? libp2p does not have a connection manager at this time (see https://github.com/libp2p/rust-libp2p/issues/2824) but should probably give the relays a higher priority connection over others so if the connection limit is ever reached, we could drop unnecessary connections to try to sustain the relay list (may have to have our own form of connection manager until one is implemented upstream)
  7. What will the impact be in regards to bitswap? Max block size is 2MB but relay v2 may have much lower data restrictions and unless DCUtR is used (and hole punching has been successful in the case of use), would likely drop packets.

Reference: https://github.com/libp2p/rust-libp2p/discussions/2944 https://github.com/libp2p/go-libp2p/blob/031ec50a04507cb2def993ef0ad15cf95eb98922/p2p/host/autorelay/options.go#L37-L45 (Thanks mxinden) https://github.com/libp2p/go-libp2p/blob/031ec50a04507cb2def993ef0ad15cf95eb98922/p2p/host/autorelay/relay_finder.go#L71-L73

dariusc93 commented 1 year ago

autorelay was moved to https://github.com/dariusc93/libp2p-autorelay though will leave this issue open for the time being since there is still more to do.