Arpan Kapoor cf3e4c6860
feat(quic): implement hole punching
Implement `Transport::dial_as_listener` for QUIC as specified by the [DCUtR spec](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md).

To facilitate hole punching in QUIC, one side needs to send random UDP packets to establish a mapping in the routing table of the NAT device. If successful, our listener will emit a new inbound connection. This connection needs to then be sent to the dialing task. We achieve this by storing a `HashMap` of hole punch attempts indexed by the remote's `SocketAddr`. A matching incoming connection is then sent via a oneshot channel to the dialing task which continues with upgrading the connection.

Related #2883.

Pull-Request: #3964.
2023-06-13 11:42:18 +00:00
..
2023-06-13 11:42:18 +00:00
2023-06-13 11:42:18 +00:00

Description

The "Direct Connection Upgrade through Relay" (DCUTR) protocol allows peers in a peer-to-peer network to establish direct connections with each other. In other words, DCUTR is libp2p's version of hole-punching. This example provides a basic usage of this protocol in libp2p.

Usage

To run the example, follow these steps:

  1. Run the example using Cargo:
    cargo run -- <OPTIONS>
    
    Replace <OPTIONS> with specific options (you can use the --help command to see the available options).

Example usage

  • Example usage in client-listen mode:

    cargo run -- --mode listen --secret-key-seed 42 --relay-address /ip4/127.0.0.1/tcp/12345
    
  • Example usage in client-dial mode:

    cargo run -- --mode dial --secret-key-seed 42 --relay-address /ip4/127.0.0.1/tcp/12345 --remote-peer-id <REMOTE_PEER_ID>
    

For this example to work, it is also necessary to turn on a relay server (you will find the related instructions in the example in the examples/relay-server folder).

Conclusion

The DCUTR protocol offers a solution for achieving direct connectivity between peers in a peer-to-peer network. By utilizing hole punching and eliminating the need for signaling servers, the protocol allows peers behind NATs to establish direct connections. This example provides instructions on running an example implementation of the protocol, allowing users to explore its functionality and benefits.