Source code for edri.protocol.errors

from enum import IntEnum, unique

__all__ = ["ErrorReason", "ProtocolError"]


[docs] @unique class ErrorReason(IntEnum): """Why a frame or handshake was rejected. The value travels in the payload of an ``ERROR`` frame, so a peer can tell "wrong secret" from "unreachable" — something closing the socket cannot express. Values are part of the wire format: append, never renumber. """ BAD_VERSION = 1 BAD_MAC = 2 BAD_SEQ = 3 TOO_LARGE = 4 UNKNOWN_ROUTER = 5
[docs] class ProtocolError(Exception): """A frame could not be accepted. Always fatal for its connection.""" def __init__(self, message: str, reason: ErrorReason, *, transport: bool = False) -> None: super().__init__(message) self.reason = reason # True when the failure is the socket closing under the handshake - a # Switch restart, a TCP reset, a rescheduled container - rather than a # MAC that was checked and failed. The Switch drops the connection # instead of sending a reason, so the two look identical on the wire; # this flag carries the distinction the wire cannot. It never travels # anywhere - unlike ``reason`` it is not part of the frame format. self.transport = transport