Handshake
April 10, 2023 ยท View on GitHub
The handshake procedure is used to find out whether two peers can communicate bidirectionally - that is, both of them can send and receive data from the other.
This is done by continuously sending packets to eachother, and change the packet's content based on the handshake's state. After a given interval, the handshake is either successful or times out.
Each peer can be in one of the following states during handshake:
- Empty
- Nothing is known about the other peer
- Received
- Data has been received from the other peer
- This means that we know their packets arrive
- Bidirectional
- Data has been received from the other peer, indicating they can read us
- This means that we know their packets arrive
- This also means that our packets arrive
- Waiting for handshake
- We already know that they can read us and we can read them
- We are waiting for the other peer to respond with a Bidirectional packet
- Receiving the bidirectional packet means that the handshake is complete, since both peers indicated connectivity