Skip to content

HandshakeHandler

veltix.handler.handshake_handler.HandshakeHandler

Handles the HELLO / HELLO_ACK exchange for a single connection.

SERVER side
  1. prepare_hello() — creates HELLO request (call before register()!)
  2. send_hello() — sends the prepared HELLO
  3. handle_hello_ack() — validates the HELLO_ACK
CLIENT side
  1. handle_hello() — receives and validates the HELLO
  2. send_hello_ack() — sends HELLO_ACK back to the server

__init__

__init__(sender: Sender, mode: Mode) -> None

Initialize the handshake handler.

Parameters:

Name Type Description Default
sender Sender

Sender instance for outgoing messages

required
mode Mode

Mode.SERVER or Mode.CLIENT

required

prepare_hello

prepare_hello() -> tuple[str, Request]

SERVER: Prepare a HELLO request without sending it.

Must be called BEFORE register() and send_hello() to avoid the race condition where HELLO_ACK arrives before the queue is registered.

Returns:

Type Description
tuple[str, Request]

(request_id, hello_request) — register request_id, then call send_hello()

send_hello

send_hello(hello: Request, client_conn=None) -> None

SERVER: Send a previously prepared HELLO request.

Must be called AFTER register() to avoid race conditions.

Parameters:

Name Type Description Default
hello Request

The Request object returned by prepare_hello()

required
client_conn

Raw socket of the target client (server mode only)

None

handle_hello_ack

handle_hello_ack(response: Response) -> bool

SERVER: Validate an incoming HELLO_ACK from the client.

Parameters:

Name Type Description Default
response Response

Incoming HELLO_ACK Response object

required

Returns:

Type Description
bool

True if handshake accepted, False otherwise

handle_hello

handle_hello(response: Response) -> bool

CLIENT: Validate an incoming HELLO from the server.

Parameters:

Name Type Description Default
response Response

Incoming HELLO Response object

required

Returns:

Type Description
bool

True if HELLO is valid, False otherwise

send_hello_ack

send_hello_ack(request_id: str) -> None

CLIENT: Send HELLO_ACK back to the server.

Parameters:

Name Type Description Default
request_id str

The request_id from the received HELLO — used for correlation

required