Konubinix' opinionated web of thoughts

Hole Punching

Fleeting

If the remote accepts the reservation request, B can advertise itself as being reachable through the remote Relay node. In other words, instead of advertising its own IP address (which is useless given that B is not publicly dialable), B advertises a “relayed” address, which contains the IP address of the remote relay node plus its own peer ID. /<RELAY_ADDR>/p2p-circuit/<PEER_ID_B>

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

let’s imagine node A got a hold of B’s relayed address through some mechanism. One possible scenario in the IPFS world could be that B is advertising the availability of a specific chunk of data, and A discovered the data provider B on the Kademlia DHT. Given the relayed address, A would now like to establish a direct connection to B. As B is advertising a relayed address and not a direct address, A knows that B is not directly dialable but only dialable through a relay node.

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

Using the information contained in B’s advertised address, A first establishes a direct connection to the relay node and then requests a relayed connection to B from the relay. The relay forwards said request to B, which accepts the request. The relay once more forwards the acceptance to A. From now on, A and B can use the bi-directional channel over the relay to communicate.

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

A and B upgrade the relayed connection with a security protocol like TLS. Thus the relay cannot eavesdrop on the connection between the two

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

A and B can now coordinate the hole punch, ultimately leading to a direct connection between A and B.

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

two stages to do a direct connection upgrade through a relay, exchanging Connect messages and sending a single Sync message

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

A sends a Sync message to B on the relayed connection. Once sent out, A waits for half the round trip time, then it dials B via the addresses received in B’s Connect. This is a direct dial not using the relayed connection. On the other end, as soon as B receives A’s Sync message, it immediately directly dials A with the addresses provided in A’s Connect message.

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/

Now, if you do the math, A starts after half the round trip time between A and B via the relay, and B starts once it receives the Sync. This should roughly account to the same point in time. # Hole

https://blog.ipfs.io/2022-01-20-libp2p-hole-punching/