Update README.md, add heartbeat packets to detect dead or hanging connections.
This commit is contained in:
39
README.md
39
README.md
@@ -10,11 +10,44 @@ It operates on port **48042** for both TCP and UDP.
|
||||
|
||||
### Handshake Procedure
|
||||
|
||||
*wip*
|
||||
The handshake between the client and server is done over **TCP**. This is to ensure delivery without much hassle.
|
||||
|
||||
The procedure will be described packet per packet (line per line) with a **C** or **S** prefix for the client and server, respectfully. After the prefix will be the **Packet ID** and then the data in **<>** tags. Lines without a prefix describe the use / reasoning of the above packet.
|
||||
|
||||
```
|
||||
C: HANDSHAKE_INIT <Client Identity Public Key>
|
||||
S: HANDSHAKE_IDENTIFY <Server Identity Public Key>
|
||||
C: HANDSHAKE_CHALLENGE <Random Nonce (32 bytes)>
|
||||
S: HANDSHAKE_CHALLENGE_RESPONSE <Signed Nonce (Gotten from Previous Packet)>
|
||||
|
||||
The Client now generates a random aesKey (32 bytes long)
|
||||
|
||||
C: HANDSHAKE_EXCHANGE_KEY <aesKey Encrypted with Server Public Key>
|
||||
|
||||
The Server now assigns a local 8 byte session ID in the Session Registry.
|
||||
|
||||
S: HANDSHAKE_EXCHANGE_KEY_CONFIRM <Assigned SessionID>
|
||||
```
|
||||
|
||||
The **Client** and **Server** have now securely exchanged a symmetric **AES Key** that they'll use to **encrypt all traffic** sent further out.
|
||||
|
||||
### Packet Exchange
|
||||
|
||||
*wip*
|
||||
Packet exchange and the general data tunneling is done via **Standard UDP** (*see the **UDP Packet** in **Data***).
|
||||
|
||||
The **header** of the sent packet always includes a **random 12 byte nonce** used to obscure the **encrypted payload / data** and the **Session ID** assigned by the server to the client (8 bytes). This makes the header **20 bytes long**.
|
||||
|
||||
The **payload / data** of the sent packet is **always encrypted** using the exchanged **AES Key** and obscured using the **random nonce**.
|
||||
|
||||
*The AES key used is according to the **ChaCha20-Poly1305** algorithm.*
|
||||
|
||||
### Connection Termination
|
||||
|
||||
The lifetime of a connection is determined based on the lifetime of the **TCP connection** and **Heartbeat packets**.
|
||||
|
||||
As soon as the TCP connection terminates, either due to a lost connection, **TCP RST**, **GRACEFUL_DISCONNECT** or **KILL_CONNECTION** packet, etc., the client and server will **stop sending UDP data**. The server will also remove the terminated client from its **Session Registry**.
|
||||
|
||||
Additionally, if either party misses **3 of the sent heartbeat packets**, the other party will treat them as dead and remove them.
|
||||
|
||||
## Packet Structure
|
||||
|
||||
@@ -33,7 +66,7 @@ TCP Packets generally follow the structure **Packet ID + Data**. They're only us
|
||||
|
||||
The **Packet ID** is an **8 bit unsigned integer** that is predefined from either the **Client to Server** or **Server to Client** enum set, however they are uniquely numbered as to not collide with each other.
|
||||
|
||||
**Server to Client** IDs are always below **0xA0** (exclusive) and **Client to Server** IDs are always above **0xA0** (exclusive). **0xFE** and **OxFF** are shared for **GRACEFUL_DISCONNECT** and **KILL_CONNECTION** respectively.
|
||||
**Server to Client** IDs are always below **0xA0** (exclusive) and **Client to Server** IDs are always above **0xA0** (exclusive). **0xF0**, **0xF1**, **0xFE** and **OxFF** are shared for **HEARTBEAT**, **HEARTBEAT_ACK**, **GRACEFUL_DISCONNECT** and **KILL_CONNECTION** respectively.
|
||||
|
||||
#### Data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user