HandshakeHandler¶
veltix.handler.handshake_handler.HandshakeHandler
¶
Manage the version compatibility handshake for a single raw TCP connection. Uses a 3-way protocol to ensure both sides are synchronized:
- Server → Client : {"v", "meta"}
- Client → Server : {"v", "meta"}
- Server → Client : {"result": "ok"}
Server mode sends first, then validates client version before acking. Client mode reads server version, validates, sends its version, then waits for the server ack before returning.
__init__
¶
Initialise the handshake handler for a given role.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Mode
|
Whether this handler operates as |
required |
bus
|
VeltixBus
|
Event bus for emitting handshake events and logging. |
required |
id_window
|
int
|
The ID window size announced to the peer (server only). |
30000
|
do_server_handshake
¶
Perform the server-side 3-way handshake.
Steps
- Send
{"v": ..., "meta": {"id_window": ...}}to the client. - Receive the client's
{"v": ..., "meta": ...}response. - Validate the client's version against the compatibility table.
- Send
{"result": "ok"}to acknowledge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sock
|
RawSocket
|
A raw TCP socket conforming to :class: |
required |
timeout
|
float
|
Maximum seconds to wait for each recv. |
5.0
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the handshake succeeded, False on any failure. |
do_client_handshake
¶
Perform the client-side 3-way handshake.
Steps
- Receive the server's
{"v": ..., "meta": ...}payload. - Validate the server's version against the compatibility table.
- Send
{"v": ..., "meta": {}}to the server. - Wait for the server's
{"result": "ok"}acknowledgment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sock
|
RawSocket
|
A raw TCP socket conforming to :class: |
required |
Returns:
| Type | Description |
|---|---|
bool
|
A tuple of |
Optional[dict[str, Any]]
|
metadata dict on success, or |