TCP Convergence Layer (TCPCL)¶
The tcpcl module provides tools for parsing and creating TCP Convergence
Layer packets as defined in RFC 7242 and RFC 9174.
Constants¶
MAGIC¶
A byte string sentinel (b"dtn!") used to identify the start of a TCPCL packet
in a byte stream.
Data Structures¶
MESSAGE_MAP¶
A dictionary used to map a combination of TCPCL version and message type to its corresponding message class.
Type: dict[tuple[TCPCLVersion, int], type[TCPCLMessage]]
Classes¶
TCPCL¶
The TCPCL class encapsulates a TCPCL packet and handles version-based
dispatch to specific message types. It extends dpkt.Packet.
Attributes¶
version(TCPCLVersion | None): The version of the TCPCL packet.message_type(int | None): The type identifier of the TCPCL message.message(TCPCLMessage | None): The unpacked message object containing the actual payload and semantics.
Methods¶
__init__(*args, **kwargs): Initializes the TCPCL packet with optional version and message attributes.unpack(buf: bytes): Unpacks raw bytes into aTCPCLpacket. Validates theMAGICsentinel, version, and length. RaisesValueErrorif the buffer is too short or the format is invalid.__bytes__(): Serializes theTCPCLpacket back into bytes. Performs a reverse lookup inMESSAGE_MAPto determine the message type. RaisesAttributeErrorif the version or type cannot be determined.__str__(): Returns a human-readable string representation of the packet.__repr__(): Returns a developer-friendly string representation of the packet.
TCPCLStreamParser¶
A helper class designed to extract TCPCL packets from a continuous byte
stream, handling partial packets and split-packet recovery.
Attributes¶
buffer(bytearray): An internal buffer that stores incoming data until a complete packet can be parsed.
Methods¶
feed(data: bytes) -> list[TCPCL]: Appends new data to the internal buffer and attempts to extract all completeTCPCLpackets. It searches for theMAGICsentinel and verifies the length header before attempting to unpack. Returns a list of successfully parsedTCPCLinstances.