mxcubecore.ipc.transports.base

Transport-agnostic interface used by mxcubecore.ipc.server.IPCServer.

A concrete transport is responsible for connection handling, TLS and message framing; it knows nothing about the raw JSONRPC 2.0 protocol or the whitelist. IPCServer owns the session/auth layer and all envelope handling on top of whatever raw JSON frames a transport delivers.

Classes

Transport()

Common interface for the JSON-RPC/TCP and NanoMQ transports.

class mxcubecore.ipc.transports.base.Transport[source]

Bases: ABC

Common interface for the JSON-RPC/TCP and NanoMQ transports.

abstract bind(session_id: str) → None[source]

Called by IPCServer once session_id has authenticated.

Transports that can’t tell clients apart by connection (NanoMQ) use this to reserve the single client slot.

Parameters:

session_id (str)

Return type:

None

abstract has_active_client() → bool[source]

Whether a client is currently connected.

Return type:

bool

abstract send(session_id: str, raw_json: str) → None[source]

Send one frame to the given session, if it is still connected.

Parameters:
  • session_id (str)

  • raw_json (str)

Return type:

None

abstract start(on_message: Callable[[str, str], None], on_connect: Callable[[str, str | None], None], on_disconnect: Callable[[str], None]) → None[source]

Start listening for (or connecting to) clients.

on_message(session_id, raw_json) is called for every inbound frame.

on_disconnect(session_id) when a client’s connection is torn down at the transport level

on_connect(session_id, peer) is called when a connection is established; peer is a human-readable “ip:port (hostname)” string for transports that have one (JSON-RPC/TCP), or None for transports that don’t (NanoMQ has no per-connection socket only a _client_id in each message).

Parameters:
Return type:

None

abstract stop() → None[source]

Stop the transport and release any resources (sockets, MQTT client loop etc.).

Return type:

None