tcpcl package
The TCPCLv4 demonstration messaging and CL agent.
Subpackages
- tcpcl.test package
- Submodules
TestBundleGenbinaryCborTag()binaryCborseqTag()Blockrandtext()randbytes()randdtntime()randnodeid()randtimestamp()randstatus()randcboritem()Generatorbundle_iterable()agent_send_bundles()main()Workermain()TestContactTestUInt16FieldTestSdnvFieldTestSessionInitTestSessionTermTestKeepaliveTestRejectMsgTestTransferRefuseTestTransferSegmentTestTransferSegment.testSerializeStartNoExt()TestTransferSegment.testDeserializeStartNoExt()TestTransferSegment.testSerializeStartLengthExt()TestTransferSegment.testDeserializeStartLengthExt()TestTransferSegment.testSerializeMidData()TestTransferSegment.testDeserializeMidData()TestTransferSegment.testSerializeEndData()TestTransferSegment.testDeserializeEndData()
TestTransferAck
- Submodules
Submodules
Implementation of a symmetric TCPCL agent.
- class tcpcl.agent.AddressObject(text, proto=6)
Bases:
objectInterpret a text address as an ipaddress object.
- Parameters:
text (
Optional[str]) – The input to convert.
- class tcpcl.agent.Conversation(family=None, peer_address=None, peer_port=None, local_address=None, local_port=None)
Bases:
objectBookkeep parameters of a TCP conversation which is address-and-port for each side.
-
family:
Optional[int] = None
-
peer_address:
Optional[_BaseAddress] = None
-
peer_port:
Optional[int] = None
-
local_address:
Optional[_BaseAddress] = None
-
local_port:
Optional[int] = None
- property key
- make_socket()
Get a socket based on local requirements. :return: A TCP socket object.
-
family:
- class tcpcl.agent.Agent(config, bus_kwargs=None)
Bases:
ObjectOverall agent behavior.
- Parameters:
config (
Config) – The agent configuration object.bus_kwargs (dict or None) – Arguments to
dbus.service.Objectconstructor. If not provided the default dbus configuration is used.
- DBUS_IFACE = 'org.ietf.dtn.tcpcl.Agent'
- set_on_stop(func)
Set a callback to be run when this agent is stopped.
- Parameters:
func – The callback, which takes no arguments.
- get_connections()
Get all connections for this agent. :return: List of object paths.
- connection_opened(*args, **keywords)
Emitted when a connection is opened.
- connection_closed(*args, **keywords)
Emitted when a connection is closed.
- shutdown()
Gracefully terminate all open sessions. Once the sessions are closed then the agent may stop.
- Returns:
True if the agent is stopped immediately or False if a wait is needed.
- stop()
Immediately stop the agent and disconnect any sessions.
- exec_loop()
Run this agent in an event loop. The on_stop callback is replaced to quit the event loop.
- listen(address, port)
Begin listening for incoming connections and defer handling connections to glib event loop.
- listen_stop(address, port)
Stop listening for connections on an existing port binding.
- connect(address, port)
Initiate an outgoing connection and defer handling state to glib event loop.
- Parameters:
address (
str) – The address to connect to.port (
int) – The port number to connect to.
- Return type:
str- Returns:
The new contact object path.
- handler_for_path(path)
Look up a contact by its object path.
Command entry points.
- tcpcl.cmd.root_logging(log_level)
Initialize logging.
- tcpcl.cmd.main()
Agent command entry point.
Agent configuration data.
- class tcpcl.config.Config(log_level=None, enable_test=<factory>, bus_addr=None, bus_service=None, init_listen=<factory>, init_connect=<factory>, stop_on_close=False, tls_enable=True, tls_version=None, tls_ciphers=None, tls_ca_file=None, tls_cert_file=None, tls_key_file=None, tls_dhparam=None, require_tls=None, require_host_authn=False, require_node_authn=False, node_id='', keepalive_time=0, idle_time=0, segment_size_mru=10485760, segment_size_tx_initial=104857, modulate_target_ack_time=None)
Bases:
objectAgent configuration.
-
log_level:
Optional[str] = None
-
enable_test:
Set[str]
-
bus_addr:
Optional[str] = None
-
bus_service:
Optional[str] = None
-
init_listen:
List[ListenConfig]
-
init_connect:
List[ConnectConfig]
-
stop_on_close:
bool= False
-
tls_enable:
bool= True
-
tls_version:
Optional[str] = None
-
tls_ciphers:
Optional[Set[str]] = None
-
tls_ca_file:
Optional[str] = None
-
tls_cert_file:
Optional[str] = None
-
tls_key_file:
Optional[str] = None
-
tls_dhparam:
Optional[str] = None
-
require_tls:
Optional[bool] = None
-
require_host_authn:
bool= False
-
require_node_authn:
bool= False
-
node_id:
str= ''
-
keepalive_time:
int= 0
-
idle_time:
int= 0
-
segment_size_mru:
int= 10485760
-
segment_size_tx_initial:
int= 104857
-
modulate_target_ack_time:
Optional[int] = None
- from_file(fileobj)
Load configuration from a YAML file. :type fileobj: :param fileobj: The file to read from.
- property bus_conn
- get_ssl_context()
Get an
ssl.SSLContextobject configured for this peer.
-
log_level:
Items related to contact header and connection negotiation.
- class tcpcl.contact.Head(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
PacketFront elements common to the TCPCL contact headers.
- fields_desc: List[AnyField] = [<StrFixedLenField (Head).magic>, <UInt8Field (Head).version>]
- aliastypes = [<class 'tcpcl.contact.Head'>, <class 'scapy.packet.Packet'>]
- payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'version': 3}, <class 'tcpcl.contact.ContactV3'>), ({'version': 4}, <class 'tcpcl.contact.ContactV4'>)]
- class tcpcl.contact.ContactV3(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketTCPCLv3 contact header pseudo-message.
- fields_desc: List[AnyField] = [<FlagsField (ContactV3).flags>, <UInt16Field (ContactV3).keepalive>, <SdnvFieldLenField (ContactV3).nodeid_length>, <StrLenField (ContactV3).nodeid_data>]
- post_dissection(pkt)
Verify consistency of packet.
- aliastypes = [<class 'tcpcl.contact.ContactV3'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.contact.ContactV4(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketTCPCLv4 Contact header pseudo-message.
- SIZE_MAX = 18446744073709551615
- fields_desc: List[AnyField] = [<FlagsField (ContactV4).flags>]
- aliastypes = [<class 'tcpcl.contact.ContactV4'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
Session and Transfer extension type definitions.
- class tcpcl.extend.SessionPrivateDummy(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketExample of session extension.
- fields_desc: List[AnyField] = [<UInt64Field (SessionPrivateDummy).largeval>, <UInt16Field (SessionPrivateDummy).smallval>]
- aliastypes = [<class 'tcpcl.extend.SessionPrivateDummy'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.extend.TransferPrivateDummy(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketExample of session extension.
- fields_desc: List[AnyField] = [<UInt64Field (TransferPrivateDummy).largeval>, <UInt16Field (TransferPrivateDummy).smallval>]
- aliastypes = [<class 'tcpcl.extend.TransferPrivateDummy'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.extend.TransferTotalLength(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketIdentify total transfer (bundle) length.
- fields_desc: List[AnyField] = [<UInt64Field (TransferTotalLength).total_length>]
- aliastypes = [<class 'tcpcl.extend.TransferTotalLength'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
Created on May 29, 2016
@author: bsipos
- class tcpcl.formats.UInt8Field(name, default)
Bases:
FieldUnsigned 8-bit value.
- class tcpcl.formats.UInt16Field(name, default)
Bases:
FieldUnsigned 16-bit value.
- class tcpcl.formats.UInt64Field(name, default)
Bases:
FieldUnsigned 64-bit value.
- class tcpcl.formats.UInt16FieldLenField(*args, **kwargs)
Bases:
FieldLenFieldUnsigned 16-bit value.
- class tcpcl.formats.UInt32FieldLenField(*args, **kwargs)
Bases:
FieldLenFieldUnsigned 32-bit value.
- class tcpcl.formats.UInt64FieldLenField(*args, **kwargs)
Bases:
FieldLenFieldUnsigned 64-bit value.
- class tcpcl.formats.UInt16PayloadLenField(*args, **kwargs)
Bases:
LenFieldUnsigned 16-bit value.
- class tcpcl.formats.SdnvField(name, default, fmt='H')
Bases:
SDNV2Represent a single independent SDNV-encoded integer.
- class tcpcl.formats.SdnvFieldLenField(name, default, length_of=None, fmt='H', count_of=None, adjust=<function FieldLenField.<lambda>>)
Bases:
SDNV2FieldLenFieldAn SDNV value which represents a count/length of another field.
- class tcpcl.formats.SdnvPayloadLenField(name, default, fmt='H', adjust=<function LenField.<lambda>>)
Bases:
SDNV2LenFieldAn SDNV value which represents the octet length of the payload data.
- class tcpcl.formats.ExtensionListField(name, default, pkt_cls=None, count_from=None, length_from=None, next_cls_cb=None, max_count=None)
Bases:
PacketListFieldProvide useful randval() that fixes scapy behavior.
- randval()
Return a volatile object whose value is both random and suitable for this field
- class tcpcl.formats.StrLenFieldUtf8(name, default, length_from=None, max_length=None)
Bases:
StrLenFieldA UTF-8 safe text string.
- h2i(pkt, x)
Convert human value to internal value
- i2h(pkt, x)
Convert internal value to human value
- randval()
Return a volatile object whose value is both random and suitable for this field
- class tcpcl.formats.BlobField(name, default, length_from=None, max_length=None)
Bases:
StrLenFieldOverload i2h and i2repr to hide the actual data contents.
- i2h(pkt, x)
Convert internal value to human value
- i2repr(pkt, x)
Convert internal value to a nice representation
- class tcpcl.formats.NoPayloadPacket(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
PacketA packet which never contains payload data.
- extract_padding(s)
No payload, all extra data is padding
- aliastypes = [<class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- tcpcl.formats.remove_padding(pkt)
Traverse a packet and remove any trailing padding payload.
- Parameters:
pkt (
Packet) – The root packet to traverse.
- exception tcpcl.formats.VerifyError
Bases:
RuntimeErrorAn exception to indicate a read verification error.
- tcpcl.formats.verify_sized_item(length, item)
Verify consistency of reading a sized item. :type length:
Optional[int] :param length: The expected size of the field/packet. :type item:Packet:param item: The field or packet to take size of. :raise VerifyError: if inconsistent.- Return type:
None
Items related to established connection messaging.
- class tcpcl.messages.MessageHead(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
PacketThe common message header.
- fields_desc: List[AnyField] = [<UInt8Field (MessageHead).msg_id>]
- post_dissection(pkt)
remove padding from payload list after disect() completes
- aliastypes = [<class 'tcpcl.messages.MessageHead'>, <class 'scapy.packet.Packet'>]
- payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'msg_id': 1}, <class 'tcpcl.messages.TransferSegment'>), ({'msg_id': 2}, <class 'tcpcl.messages.TransferAck'>), ({'msg_id': 3}, <class 'tcpcl.messages.TransferRefuse'>), ({'msg_id': 4}, <class 'tcpcl.messages.Keepalive'>), ({'msg_id': 5}, <class 'tcpcl.messages.SessionTerm'>), ({'msg_id': 6}, <class 'tcpcl.messages.RejectMsg'>), ({'msg_id': 7}, <class 'tcpcl.messages.SessionInit'>)]
- class tcpcl.messages.TlvHead(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
PacketGeneric TLV header with data as payload.
- classmethod bind_extension(ext_id)
Bind an extension class to a derived header class. This decorator should be applied to extension type classes.
- Parameters:
cls – The header class to extend.
ext_id – The extension type ID number.
- class Flag(*values)
Bases:
IntEnumMessage flags. Flags must be in LSbit-first order.
- CRITICAL = 1
- fields_desc: List[AnyField] = [<FlagsField (TlvHead,SessionExtendHeader,TransferExtendHeader).flags>, <UInt16Field (TlvHead,SessionExtendHeader,TransferExtendHeader).type>, <UInt16PayloadLenField (TlvHead,SessionExtendHeader,TransferExtendHeader).length>]
- post_dissection(pkt)
Verify consistency of packet.
- aliastypes = [<class 'tcpcl.messages.TlvHead'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.SessionExtendHeader(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
TlvHeadSession Extension Item header with data as payload.
- aliastypes = [<class 'tcpcl.messages.SessionExtendHeader'>, <class 'tcpcl.messages.TlvHead'>, <class 'scapy.packet.Packet'>]
- fields_desc: List[AnyField] = [<FlagsField (TlvHead,SessionExtendHeader,TransferExtendHeader).flags>, <UInt16Field (TlvHead,SessionExtendHeader,TransferExtendHeader).type>, <UInt16PayloadLenField (TlvHead,SessionExtendHeader,TransferExtendHeader).length>]
- payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'type': 255}, <class 'tcpcl.extend.SessionPrivateDummy'>)]
- class tcpcl.messages.SessionInit(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketAn SESS_INIT with no payload.
- SIZE_MAX = 18446744073709551615
- fields_desc: List[AnyField] = [<UInt16Field (SessionInit).keepalive>, <UInt64Field (SessionInit).segment_mru>, <UInt64Field (SessionInit).transfer_mru>, <UInt16FieldLenField (SessionInit).nodeid_length>, <StrLenFieldUtf8 (SessionInit).nodeid_data>, <UInt32FieldLenField (SessionInit).ext_size>, <ExtensionListField (SessionInit).ext_items>]
- post_dissection(pkt)
Verify consistency of packet.
- aliastypes = [<class 'tcpcl.messages.SessionInit'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.SessionTerm(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketAn flag-dependent SESS_TERM message.
- class Reason(*values)
Bases:
IntEnumReason code points.
- UNKNOWN = 0
- IDLE_TIMEOUT = 1
- VERSION_MISMATCH = 2
- BUSY = 3
- CONTACT_FAILURE = 4
- RESOURCE_EXHAUSTION = 5
- fields_desc: List[AnyField] = [<FlagsField (SessionTerm).flags>, <ByteEnumField (SessionTerm).reason>]
- aliastypes = [<class 'tcpcl.messages.SessionTerm'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.Keepalive(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketAn empty KEEPALIVE message.
- aliastypes = [<class 'tcpcl.messages.Keepalive'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.RejectMsg(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketA REJECT with no payload.
- class Reason(*values)
Bases:
IntEnumReason code points.
- UNKNOWN = 1
- UNSUPPORTED = 2
- UNEXPECTED = 3
- fields_desc: List[AnyField] = [<UInt8Field (RejectMsg).rej_msg_id>, <ByteEnumField (RejectMsg).reason>]
- aliastypes = [<class 'tcpcl.messages.RejectMsg'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.TransferExtendHeader(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
TlvHeadTransfer Extension Item header with data as payload.
- aliastypes = [<class 'tcpcl.messages.TransferExtendHeader'>, <class 'tcpcl.messages.TlvHead'>, <class 'scapy.packet.Packet'>]
- fields_desc: List[AnyField] = [<FlagsField (TlvHead,SessionExtendHeader,TransferExtendHeader).flags>, <UInt16Field (TlvHead,SessionExtendHeader,TransferExtendHeader).type>, <UInt16PayloadLenField (TlvHead,SessionExtendHeader,TransferExtendHeader).length>]
- payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'type': 255}, <class 'tcpcl.extend.TransferPrivateDummy'>), ({'type': 1}, <class 'tcpcl.extend.TransferTotalLength'>)]
- class tcpcl.messages.TransferRefuse(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketAn XFER_REFUSE with no payload.
- class Reason(*values)
Bases:
IntEnumReason code points.
- UNKNOWN = 0
- COMPLETED = 1
- NO_RESOURCES = 2
- RETRANSMIT = 3
- NOT_ACCEPTABLE = 4
- EXT_FAILURE = 5
- fields_desc: List[AnyField] = [<ByteEnumField (TransferRefuse).reason>, <UInt64Field (TransferRefuse).transfer_id>]
- aliastypes = [<class 'tcpcl.messages.TransferRefuse'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.TransferSegment(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketA XFER_SEGMENT with bundle data as field.
- class Flag(*values)
Bases:
IntEnumMessage flags. Flags must be in LSbit-first order.
- END = 1
- START = 2
- fields_desc: List[AnyField] = [<FlagsField (TransferSegment).flags>, <UInt64Field (TransferSegment).transfer_id>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <UInt64FieldLenField (TransferSegment).length>, <BlobField (TransferSegment).data>]
- post_dissection(pkt)
Verify consistency of packet.
- aliastypes = [<class 'tcpcl.messages.TransferSegment'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
- class tcpcl.messages.TransferAck(_pkt=b'', post_transform=None, _internal=0, _underlayer=None, _parent=None, stop_dissection_after=None, **fields)
Bases:
NoPayloadPacketAn XFER_ACK with no payload.
- fields_desc: List[AnyField] = [<FlagsField (TransferAck).flags>, <UInt64Field (TransferAck).transfer_id>, <UInt64Field (TransferAck).length>]
- aliastypes = [<class 'tcpcl.messages.TransferAck'>, <class 'tcpcl.formats.NoPayloadPacket'>, <class 'scapy.packet.Packet'>]
TCPCL session keeping and message sequencing.
- tcpcl.session.match_id(ref_id, cert, san_key, logger, log_name)
Match a certificate identifier. :type san_key: :param san_key: A SAN type to match, or an OID of an OtherName to match. :return: The matched ID URI, or False if present but failed, or None if no identifier present in the certificate.
- class tcpcl.session.Connection(sock, as_passive, peer_name)
Bases:
objectOptionally secured socket connection. This handles octet-level buffering and queuing.
- Parameters:
sock (
socket.socket) – The unsecured socket to wrap.as_passive (bool) – True if this is the passive side of the connection.
peer_name (str) – The name of the socket peer.
- is_secure()
Determine if TLS is established.
- Returns:
True if operating with TLS.
- get_app_socket()
Get the socket object used for TCPCL traffic.
- Returns:
The socket object.
- get_secure_socket()
Get the secure socket object if available.
- Returns:
The socket object or None.
- set_on_close(func)
Set a callback to be run when this connection is closed.
- Parameters:
func – The callback, which takes no arguments.
- close()
Close the entire connection cleanly.
- secure(ssl_ctx)
Add a TLS connection layer (if not present).
- Parameters:
ssl_ctx (
ssl.SSLContext) – The context to use for security.- Raises:
ssl.SSLError – If the negotiation fails.
- unsecure()
Remove any TLS connection layer (if present).
- CHUNK_SIZE = 10240
- DO_DEBUG_DATA = False
- recv_raw(data)
Handler for a received block of data. Derived classes must overload this method to handle RX data.
- Parameters:
data (str) – The received data.
- send_ready()
Called to indicate that
send_raw()will return non-empty. This will attempt immediate transmit of chunks if available, and queue the rest for later.
- send_raw(size)
Obtain a block of data to send. Derived classes must overload this method to return TX data.
- Parameters:
size (int) – The maximum size to obtain.
- Returns:
The to-be-transmitted data.
- Return type:
str
- exception tcpcl.session.RejectError(reason=None)
Bases:
ExceptionAllow recv_* handlers to reject the message.
- Parameters:
reason (
Optional[int]) – The rejection reason. Should be one of themessages.RejectMsg.Reasonvalues.
- exception tcpcl.session.TerminateError(reason=None)
Bases:
ExceptionAllow recv_* handlers to terminate a session.
- Parameters:
reason (
Optional[int]) – The termination reason. Should be one of themessages.SessionTerm.Reasonvalues.
- class tcpcl.session.Messenger(config, sock, fromaddr=None, toaddr=None)
Bases:
ConnectionMessaging layer of TCPCL. This handles message-level buffering and queuing. Messages are variable-length individually.
- Parameters:
config (
Config) – The messenger configuration struct.sock (
socket.socket) – The (unsecured) connection socket to operate on.
- set_on_state_change(func)
Set a callback to be run when this session state changes.
- Parameters:
func – The callback, which takes argument of the new state name.
- is_passive()
Determine if this is the passive side of the session.
- is_sess_idle()
Determine if the session is idle.
- Returns:
True if there are no data being processed RX or TX side.
- set_on_session_start(func)
Set a callback to be run when this session is started.
- Parameters:
func – The callback, which takes no arguments.
- set_on_session_terminate(func)
Set a callback to be run when this session is terminated.
- Parameters:
func – The callback, which takes no arguments.
- recv_buffer_used()
Get the number of octets waiting in the receive buffer.
- Returns:
The buffer use (octets).
- Return type:
int.
- send_buffer_used()
Get the number of octets waiting in the transmit buffer.
- Returns:
The buffer use (octets).
- Return type:
int.
- send_buffer_decreased(buf_use)
A handler function to be used when message buffer data is transmitted.
- Parameters:
buf_use (int) – The current buffer use (octets).
- close()
Close the entire connection cleanly.
- recv_raw(data)
Attempt to extract a message from the current read buffer.
- recv_message(pkt)
Handle a received full message (or contact header).
- Parameters:
pkt – The message packet received.
- send_contact_header()
Send the initial Contact Header non-message. Parameters are based on current configuration.
- merge_contact_params()
Combine local and peer contact headers to contact configuration.
- send_sess_init()
Send the initial SESS_INIT message. Parameters are based on current configuration.
- merge_session_params()
Combine local and peer SESS_INIT parameters. The result is kept in
_sess_parameters.- Raises:
TerminateError – If there is some failure to negotiate.
- send_raw(size)
Pop some data from the TX queue.
- Parameters:
size – The maximum size to pop from the queue.
- Returns:
The chunk of data popped from the queue.
- Return type:
bytes
- send_message(pkt)
Send a full message (or contact header).
- Parameters:
pkt – The message packet to send.
- send_reject(reason, pkt=None)
Send a message rejection response.
- Parameters:
reason (int) – The reject reason code.
pkt (The orignal
MessageHeadpacket.) – The message being rejected (optional).
- send_sess_term(reason, is_reply)
Send the SESS_TERM message. After calling this method no further transfers can be started.
- start()
Main state machine of the agent contact.
- recv_sess_term(reason)
Handle reception of SESS_TERM message.
- Parameters:
reason (int) – The termination reason.
- recv_xfer_data(transfer_id, flags, data, ext_items)
Handle reception of XFER_DATA message.
- Parameters:
transfer_id (int) – The bundle ID number.
flags (int) – The transfer flags.
data (str) – The segment data.
ext_items (array) – Extension items which may be in the start segment.
- recv_xfer_ack(transfer_id, flags, length)
Handle reception of XFER_ACK message.
- Parameters:
transfer_id (int) – The bundle ID number.
flags (int) – The transfer flags.
length (int) – The acknowledged length.
- recv_xfer_refuse(transfer_id, reason)
Handle reception of XFER_REFUSE message.
- Parameters:
transfer_id (int) – The bundle ID number.
reason (int) – The refusal reason code.
- send_xfer_data(transfer_id, data, flg, ext_items=None)
Send a XFER_DATA message.
- Parameters:
transfer_id (int) – The bundle ID number.
data (str) – The segment data.
flg (int) – Data flags for
TransferSegmentext_items (list or None) – Extension items for the starting segment only.
- send_xfer_ack(transfer_id, length, flg)
Send a XFER_ACK message.
- Parameters:
transfer_id (int) – The bundle ID number.
length (int) – The acknowledged length.
flg (int) – Data flags for
TransferAck
- send_xfer_refuse(transfer_id, reason)
Send a XFER_REFUSE message.
- Parameters:
transfer_id (int) – The bundle ID number.
reason (int) – The refusal reason code.
- class tcpcl.session.BundleItem
Bases:
objectState for RX and TX full bundles.
- transfer_id The unique transfer ID number.
- total_length The length from the file (sender) or
- known from the Transfer Length extension (receiver)
- ack_length The total acknowledged length.
- class tcpcl.session.ContactHandler(hdl_kwargs, bus_kwargs)
Bases:
Messenger,ObjectA bus interface to the contact message handler.
- Parameters:
hdl_kwargs (dict) – Arguments to
Messengerconstructor.bus_kwargs (dict) – Arguments to
dbus.service.Objectconstructor.
- DBUS_IFACE = 'org.ietf.dtn.tcpcl.Contact'
- get_session_state()
- session_state_changed(*args, **keywords)
- get_session_parameters()
- next_id()
Get the next available transfer ID number.
- Returns:
A valid transfer ID.
- Return type:
int
- recv_sess_term(reason)
Handle reception of SESS_TERM message.
- Parameters:
reason (int) – The termination reason.
- recv_xfer_data(transfer_id, flags, data, ext_items)
Handle reception of XFER_DATA message.
- Parameters:
transfer_id (int) – The bundle ID number.
flags (int) – The transfer flags.
data (str) – The segment data.
ext_items (array) – Extension items which may be in the start segment.
- recv_xfer_ack(transfer_id, flags, length)
Handle reception of XFER_ACK message.
- Parameters:
transfer_id (int) – The bundle ID number.
flags (int) – The transfer flags.
length (int) – The acknowledged length.
- recv_xfer_refuse(transfer_id, reason)
Handle reception of XFER_REFUSE message.
- Parameters:
transfer_id (int) – The bundle ID number.
reason (int) – The refusal reason code.
- is_secure()
Determine if TLS is established.
- Returns:
True if operating with TLS.
- is_sess_idle()
Determine if the session is idle.
- Returns:
True if there are no data being processed RX or TX side.
- terminate(reason_code=None)
Perform the termination procedure.
- Parameters:
reason_code (
Optional[int]) – The termination reason. Should be one of themessages.SessionTerm.Reasonvalues.
- close()
Close the TCP connection immediately.
- send_bundle_fileobj(file)
Send bundle from a file-like object.
- Parameters:
file (file-like) – The file to send.
- Returns:
The new transfer ID.
- Return type:
int
- send_bundle_data(data)
Send bundle data directly.
- send_bundle_file(filepath)
Send a bundle from the filesystem.
- send_bundle_get_queue()
- send_bundle_started(*args, **keywords)
- send_bundle_intermediate(*args, **keywords)
- send_bundle_finished(*args, **keywords)
- recv_bundle_started(*args, **keywords)
- recv_bundle_intermediate(*args, **keywords)
- recv_bundle_finished(*args, **keywords)
- recv_bundle_get_queue()
- recv_bundle_pop_data(bid)
- recv_bundle_pop_file(bid, filepath)
- send_buffer_decreased(buf_use)
A handler function to be used when message buffer data is transmitted.
- Parameters:
buf_use (int) – The current buffer use (octets).