pyndn.transport package¶
Submodules¶
pyndn.transport.async_socket_transport module¶
This module defines the AsyncSocketTransport class which extends Transport and is a helper base class for AsyncTcpTransport and AsyncUnixTransport to implement common socket communication tasks using Python’s asyncio.
-
class
pyndn.transport.async_socket_transport.
AsyncSocketTransport
(loop)[source]¶ Bases:
pyndn.transport.transport.Transport
Create a new AsyncSocketTransport in the unconnected state. This will use the asyncio loop to create the connection and communicate asynchronously.
Parameters: loop – The event loop, for example from asyncio.get_event_loop(). It is the responsibility of the application to start and stop the loop.
pyndn.transport.async_tcp_transport module¶
This module defines the AsyncTcpTransport class which extends AsyncSocketTransport for async communication over TCP using Python’s asyncio. This only uses asyncio for communication. To make this thread-safe, you must dispatch calls to send(), etc. to the asyncio loop using, e.g., call_soon_threadsafe, as is done by ThreadsafeFace. To use this, you do not need to call processEvents.
-
class
pyndn.transport.async_tcp_transport.
AsyncTcpTransport
(loop)[source]¶ Bases:
pyndn.transport.async_socket_transport.AsyncSocketTransport
Create a new AsyncTcpTransport in the unconnected state. This will use the asyncio loop to create the connection and communicate asynchronously.
Parameters: loop – The event loop, for example from asyncio.get_event_loop(). It is the responsibility of the application to start and stop the loop. -
class
ConnectionInfo
(host, port=6363)[source]¶ Bases:
pyndn.transport.transport.ConnectionInfo
Create a new AsyncTcpTransport.ConnectionInfo which extends Transport.ConnectionInfo to hold the host and port info for the TCP connection.
Parameters: - host (str) – The host for the connection.
- port (int) – (optional) The port number for the connection. If omitted, use 6363.
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in connectionInfo, and use elementListener. To be thread-safe, this must be called from a dispatch to the loop which was given to the constructor, as is done by ThreadsafeFace.
Parameters: - connectionInfo (AsyncTcpTransport.ConnectionInfo) – An AsyncTcpTransport.ConnectionInfo.
- elementListener (An object with onReceivedElement) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
-
isAsync
()[source]¶ Override to return true since connect needs to use the onConnected callback.
Returns: True Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine; results are cached. According to http://redmine.named-data.net/projects/nfd/wiki/ScopeControl#local-face, TCP transports with a loopback address are local. If connectionInfo contains a host name, this will do a blocking DNS lookup; otherwise this will parse the IP address and examine the first octet to determine if it is a loopback address (e.g. the first IPv4 octet is 127 or IPv6 is “::1”).
Parameters: connectionInfo (TcpTransport.ConnectionInfo) – A TcpTransport.ConnectionInfo with the host to check. Returns: True if the host is local, False if not. Rtype bool:
-
class
pyndn.transport.async_unix_transport module¶
This module defines the AsyncUnixTransport class which extends AsyncSocketTransport for async communication over a Unix socket using Python’s asyncio. This only uses asyncio for communication. To make this thread-safe, you must dispatch calls to send(), etc. to the asyncio loop using, e.g., call_soon_threadsafe, as is done by ThreadsafeFace. To use this, you do not need to call processEvents.
-
class
pyndn.transport.async_unix_transport.
AsyncUnixTransport
(loop)[source]¶ Bases:
pyndn.transport.async_socket_transport.AsyncSocketTransport
Create a new AsyncUnixTransport in the unconnected state. This will use the asyncio loop to create the connection and communicate asynchronously.
Parameters: loop – The event loop, for example from asyncio.get_event_loop(). It is the responsibility of the application to start and stop the loop. -
class
ConnectionInfo
(filePath)[source]¶ Bases:
pyndn.transport.transport.ConnectionInfo
Create a new AsyncUnixTransport.ConnectionInfo which extends Transport.ConnectionInfo to hold the socket file path for the Unix socket connection.
Parameters: filePath (str) – The file path of the Unix socket file.
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in connectionInfo, and use elementListener. To be thread-safe, this must be called from a dispatch to the loop which was given to the constructor, as is done by ThreadsafeFace.
Parameters: - connectionInfo (AsyncUnixTransport.ConnectionInfo) – An AsyncUnixTransport.ConnectionInfo.
- elementListener (An object with onReceivedElement) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
-
isAsync
()[source]¶ Override to return true since connect needs to use the onConnected callback.
Returns: True Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine. Unix transports are always local.
Parameters: connectionInfo (UnixTransport.ConnectionInfo) – This is ignored. Returns: True because Unix transports are always local. Return type: bool
-
class
pyndn.transport.socket_poller module¶
This module defines the SocketPoller class which is used by the socket-based Transport classes to poll a socket on various platforms.
pyndn.transport.tcp_transport module¶
This module defines the TcpTransport class which extends Transport for communication over TCP.
-
class
pyndn.transport.tcp_transport.
TcpTransport
[source]¶ Bases:
pyndn.transport.transport.Transport
Create a new TcpTransport in the unconnected state.
-
class
ConnectionInfo
(host, port=6363)[source]¶ Bases:
pyndn.transport.transport.ConnectionInfo
Create a new TcpTransport.ConnectionInfo which extends Transport.ConnectionInfo to hold the host and port info for the TCP connection.
Parameters: - host (str) – The host for the connection.
- port (int) – (optional) The port number for the connection. If omitted, use 6363.
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in connectionInfo, and use elementListener.
Parameters: - connectionInfo (TcpTransport.ConnectionInfo) – A TcpTransport.ConnectionInfo.
- elementListener (An object with onReceivedElement) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
-
getIsConnected
()[source]¶ Check if the transport is connected.
Returns: True if connected. Return type: bool
-
static
getIsLocal
(host)[source]¶ A static method to determine whether the host is on the current machine. Results are not cached. http://redmine.named-data.net/projects/nfd/wiki/ScopeControl#local-face, TCP transports with a loopback address are local. If connectionInfo contains a host name, this will do a blocking DNS lookup; otherwise this will parse the IP address and examine the first octet to determine if it is a loopback address (e.g. the first IPv4 octet is 127 or IPv6 is “::1”).
Parameters: host (str) – The host to check. Returns: True if the host is local, False if not. Rtype bool:
-
isAsync
()[source]¶ Override to return false since connect does not need to use the onConnected callback.
Returns: False Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine; results are cached. According to http://redmine.named-data.net/projects/nfd/wiki/ScopeControl#local-face, TCP transports with a loopback address are local. If connectionInfo contains a host name, this will do a blocking DNS lookup; otherwise this will parse the IP address and examine the first octet to determine if it is a loopback address (e.g. the first IPv4 octet is 127 or IPv6 is “::1”).
Parameters: connectionInfo (TcpTransport.ConnectionInfo) – A TcpTransport.ConnectionInfo with the host to check. Returns: True if the host is local, False if not. Rtype bool:
-
processEvents
()[source]¶ Process any data to receive. For each element received, call elementListener.onReceivedElement. This is non-blocking and will silently time out after a brief period if there is no data to receive. You should repeatedly call this from an event loop. You should normally not call this directly since it is called by Face.processEvents. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
-
class
pyndn.transport.transport module¶
This module defines the Transport class which is used by Face to send packets and to listen for incoming packets. See connect() and processEvents() for more details.
-
class
pyndn.transport.transport.
Transport
[source]¶ Bases:
object
-
class
ConnectionInfo
[source]¶ Bases:
object
A Transport.ConnectionInfo is a base class for connection information used by subclasses of Transport.
-
close
()[source]¶ - Close the connection. This base class implementation does nothing, but
- your derived class can override.
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in ConnectionInfo, and use elementListener.
Parameters: - connectionInfo (A subclass of ConnectionInfo) – An object of a subclass of ConnectionInfo.
- elementListener (An object with onReceivedData) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
Raises: RuntimeError – for unimplemented if the derived class does not override.
-
getIsConnected
()[source]¶ Check if the transport is connected.
Returns: True if connected. Return type: bool Raises: RuntimeError – for unimplemented if the derived class does not override.
-
isAsync
()[source]¶ Check if this transport is async where connect needs to use the onConnected callback.
Returns: True if transport connect is async, False if not. Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine. This affects the processing of Face.registerPrefix(): if the NFD is local, registration occurs with the ‘/localhost/nfd…’ prefix; if non-local, the library will attempt to use remote prefix registration using ‘/localhop/nfd…’
Parameters: connectionInfo (A subclass of ConnectionInfo) – A ConnectionInfo with the host to check. Returns: True if the host is local, False if not. Rtype bool:
-
processEvents
()[source]¶ Process any data to receive. For each element received, call elementListener.onReceivedElement. This is non-blocking and will silently time out after a brief period if there is no data to receive. You should repeatedly call this from an event loop. You should normally not call this directly since it is called by Face.processEvents. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
Raises: RuntimeError – for unimplemented if the derived class does not override.
-
class
pyndn.transport.udp_transport module¶
This module defines the UdpTransport class which extends Transport for communication over UDP.
-
class
pyndn.transport.udp_transport.
UdpTransport
[source]¶ Bases:
pyndn.transport.transport.Transport
Create a new UdpTransport in the unconnected state.
-
class
ConnectionInfo
(host, port=6363, localPort=None)[source]¶ Bases:
pyndn.transport.transport.ConnectionInfo
Create a new UdpTransport.ConnectionInfo which extends Transport.ConnectionInfo to hold the host and port info for the UDP connection.
Parameters: - host (str) – The host for the connection.
- port (int) – (optional) The port number for the connection. If omitted, use 6363.
- localPort (int) – (optional) If specified, bind the socket to (“0.0.0.0”, localPort) . (If you omit the port parameter, call this constructor with a localPort named parameter.)
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in connectionInfo, and use elementListener.
Parameters: - connectionInfo (UdpTransport.ConnectionInfo) – A UdpTransport.ConnectionInfo.
- elementListener (An object with onReceivedElement) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
-
getIsConnected
()[source]¶ For UDP, there really is no connection, but just return True if connect has been called.
Returns: True if connected. Return type: bool
-
isAsync
()[source]¶ Override to return false since connect does not need to use the onConnected callback.
Returns: False Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine. UDP transports are always non-local.
Parameters: connectionInfo (UdpTransport.ConnectionInfo) – This is ignored. Returns: False because UDP transports are always non-local. Return type: bool
-
processEvents
()[source]¶ Process any data to receive. For each element received, call elementListener.onReceivedElement. This is non-blocking and will silently time out after a brief period if there is no data to receive. You should repeatedly call this from an event loop. You should normally not call this directly since it is called by Face.processEvents. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
-
class
pyndn.transport.unix_transport module¶
This module defines the UnixTransport class which extends Transport for communication over a Unix socket.
-
class
pyndn.transport.unix_transport.
UnixTransport
[source]¶ Bases:
pyndn.transport.transport.Transport
Create a new UnixTransport in the unconnected state.
-
class
ConnectionInfo
(filePath)[source]¶ Bases:
pyndn.transport.transport.ConnectionInfo
Create a new UnixTransport.ConnectionInfo which extends Transport.ConnectionInfo to hold the socket file path for the Unix socket connection.
Parameters: filePath (str) – The file path of the Unix socket file.
-
connect
(connectionInfo, elementListener, onConnected)[source]¶ Connect according to the info in connectionInfo, and use elementListener.
Parameters: - connectionInfo (UnixTransport.ConnectionInfo) – A UnixTransport.ConnectionInfo.
- elementListener (An object with onReceivedElement) – The elementListener must remain valid during the life of this object.
- onConnected (function object) – This calls onConnected() when the connection is established.
-
getIsConnected
()[source]¶ Check if the transport is connected.
Returns: True if connected. Return type: bool
-
isAsync
()[source]¶ Override to return false since connect does not need to use the onConnected callback.
Returns: False Rtype bool:
-
isLocal
(connectionInfo)[source]¶ Determine whether this transport connecting according to connectionInfo is to a node on the current machine. Unix transports are always local.
Parameters: connectionInfo (UnixTransport.ConnectionInfo) – This is ignored. Returns: True because Unix transports are always local. Return type: bool
-
processEvents
()[source]¶ Process any data to receive. For each element received, call elementListener.onReceivedElement. This is non-blocking and will silently time out after a brief period if there is no data to receive. You should repeatedly call this from an event loop. You should normally not call this directly since it is called by Face.processEvents. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
-
class