edri.switch package

Submodules

edri.switch.connection module

class edri.switch.connection.Connection(mailbox: edri.switch.mailbox.Mailbox, channel: edri.protocol.channel.SecureChannel | None, demands: bytes | None = None, key_index: int = 0, stop: threading.Event = <factory>)[source]

Bases: object

demands: bytes | None = None
disconnect() → None[source]
key_index: int = 0
property queue: Mailbox

Compatibility alias for the old connection queue.

edri.switch.forwarder module

class edri.switch.forwarder.ForwardMessage(router_id: uuid.UUID, kind: edri.switch.forwarder.ForwardType, payload: bytes, source: uuid.UUID | None = None, delivery_id: uuid.UUID | None = None, source_connection: edri.switch.connection.Connection | None = None)[source]

Bases: object

delivery_id: UUID | None = None
source: UUID | None = None
source_connection: Connection | None = None
class edri.switch.forwarder.ForwardType(*values)[source]

Bases: IntEnum

OTHERS = 2
SPECIFIC = 1
class edri.switch.forwarder.Forwarder(forwarder_queue: Queue[ForwardMessage], connections: dict[UUID, Connection])[source]

Bases: Thread

run() → None[source]

Method representing the thread's activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

edri.switch.mailbox module

Per-router in-memory mailbox retained across TCP reconnections.

edri.switch.receiver module

class edri.switch.receiver.Receiver(forwarder_queue: Queue[ForwardMessage], router_id: UUID, connection: Connection, connections: dict[UUID, Connection])[source]

Bases: Thread

run() → None[source]

Method representing the thread's activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

edri.switch.sender module

Switch -> Connector sender. The mailbox owns all unacknowledged frames.

class edri.switch.sender.Sender(connection: Connection, router_id: UUID)[source]

Bases: Thread

run() → None[source]

Method representing the thread's activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object's constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

edri.switch.status module

Thin, read-only HTTP status endpoint for the Switch.

The Switch lives outside EDRI's router/manager/event topology — it only forwards raw bytes between connected routers over a binary TCP protocol, so the API @api health-check machinery cannot be reused here. This module exposes the same kind of operational snapshot (connections, backpressure, process vitals) through a minimal stdlib HTTP server running in a daemon thread.

It is deliberately tiny: one route (GET /status), JSON only, zero new dependencies, and read-only — it never mutates the structures it reads, so it needs no locking.

edri.switch.status.serve_status(switch: Switch, host: str, port: int, logger: Logger | None = None) → _StatusServer[source]

Start the status HTTP server in a daemon thread and return it.

Parameters:
  • switch -- the running Switch to introspect.

  • host -- bind host.

  • port -- bind port.

  • logger -- optional logger for the startup line.

Returns:

the running server instance.

edri.switch.switch module

class edri.switch.switch.Switch[source]

Bases: object

handle_new_connection(connection_socket: socket) → None[source]
run() → None[source]
status() → dict[str, Any][source]

Read-only operational snapshot of the Switch, returned as JSON-able dict.

Mirrors the kind of information the Router exposes at /edri/health-check-status: one record per connected router plus process-level vitals. Reads live structures without locking — fine for best-effort telemetry, where a momentarily stale count is acceptable.

Module contents