-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
The Direct Connection Upgrade through Relay protocol (#2076) tries to establish a connection between two peers by synchronizing the two such that they can simultaneously attempt to establish a connection. Steps required by the two peers differ by transport protocol (e.g. TCP and QUIC) and role (client and server). See excerpt from the specification below:
- Simultaneous Connect. The two nodes follow the steps below in parallel for
every address obtained from theConnectmessage:
- For a TCP address:
- Upon receiving the
Sync,Aimmediately dials the address toB.- Upon expiry of the timer,
Bdials the address toA.- This will result in a TCP Simultaneous Connect. For the purpose of all
protocols run on top of this TCP connection,Ais assumed to be the
client andBthe server.- For a QUIC address:
- Upon receiving the
Sync,Aimmediately dials the address toB.- Upon expiry of the timer,
Bstarts to send UDP packets filled with
random bytes toA's address. Packets should be sent repeatedly in
random intervals between 10 and 200 ms.- This will result in a QUIC connection where
Ais the client andBis
the server.
https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
In the case of TCP B needs to act as a listener once a connection is successfully established. Note that the TCP stack will treat both A and B as dialers as the connection will be a simultaneous TCP connection.
In the case of QUIC B needs to send random bytes instead of a connection attempt and then once a connection is established needs to act as a listener just like in the case of TCP.
Code in and based on libp2p-swarm does not need to be concerned with these implementation details. Instead, a single flag on NetworkBehaviourAction::Dial, indicating to the Swarm and libp2p-core that the conection to be established should be treated from the role of a listener, is sufficient.
To reduce conflicts, I would suggest tackling this once #2249 is fixed.