How the handshake process works in hyperdht
mainA handshake establishes a connection between a client node and a server node using two intermediary relay nodes: one chosen by the client and one chosen by the server. The client and server do not interact directly during this phase; instead, they communicate through these relays to navigate firewalls.
The Handshake Workflow
- Discovery: The client issues a DHT query to find the server node. If the chosen client relay doesn't know the server, it forwards the query through the DHT until the server is located.
- Initiation: Once the server and its relay are identified, the client sends a
PEER_HANDSHAKEcommand to the server's relay node. - Relay Chain: The server's relay forwards the command to the server, which then forwards it to the client's relay, which finally replies to the client.
- Optimization: If a relay node is also the server node, it skips the intermediate steps and replies directly.
Resulting State
After a successful handshake:
- The client node maintains firewall sessions with its own relay and the server's relay.
- The server node maintains firewall sessions with its own relay and the client's relay.
- The client node obtains the server's address, allowing it to begin direct holepunching.