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.
close()[source]
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.
processEvents()[source]

Do nothing since the async loop reads the socket.

send(data)[source]

Send data to the host. 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:data (An array type accepted by Transport.write.) – The buffer of data to send.

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.
getHost()[source]

Get the host given to the constructor.

Returns:The host.
Return type:str
getPort()[source]

Get the port given to the constructor.

Returns:The port.
Return type:int
AsyncTcpTransport.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.
AsyncTcpTransport.isAsync()[source]

Override to return true since connect needs to use the onConnected callback.

Returns:True
Rtype bool:
AsyncTcpTransport.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:

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.
getFilePath()[source]

Get the filePath given to the constructor.

Returns:The file path.
Return type:str
AsyncUnixTransport.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.
AsyncUnixTransport.isAsync()[source]

Override to return true since connect needs to use the onConnected callback.

Returns:True
Rtype bool:
AsyncUnixTransport.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

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.

class pyndn.transport.socket_poller.SocketPoller(sock)[source]

Bases: object

Create a new SocketPoller and register with the given sock

Parameters:sock (socket) – The socket to register with.
close()[source]

Unregister with the socket given to the constructor.

isReady()[source]

Check if the socket given to the constructor has data to receive.

Returns:True if there is data ready to receive, otherwise False.
Return type:bool

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.
getHost()[source]

Get the host given to the constructor.

Returns:The host.
Return type:str
getPort()[source]

Get the port given to the constructor.

Returns:The port.
Return type:int
TcpTransport.close()[source]

Close the connection. If not connected, this does nothing.

TcpTransport.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.
TcpTransport.getIsConnected()[source]

Check if the transport is connected.

Returns:True if connected.
Return type:bool
static TcpTransport.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:
TcpTransport.isAsync()[source]

Override to return false since connect does not need to use the onConnected callback.

Returns:False
Rtype bool:
TcpTransport.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:
TcpTransport.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.

TcpTransport.send(data)[source]

Send data to the host.

Parameters:data (An array type accepted by socket.send) – The buffer of data to send.

pyndn.transport.transport module

This module defines the Transport class which is a base class for specific transport classes such as UnixTransport.

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.

Transport.close()[source]

Close the connection. This base class implementation does nothing, but your derived class can override.

Transport.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.

Transport.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.
Transport.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:
Transport.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:
Transport.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.
Transport.send(data)[source]

Send data to the host.

Parameters:data (An array type) – The buffer of data to send.
Raises RuntimeError:
 for unimplemented if the derived class does not override.

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)[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.
getHost()[source]

Get the host given to the constructor.

Returns:The host.
Return type:str
getPort()[source]

Get the port given to the constructor.

Returns:The port.
Return type:int
UdpTransport.close()[source]

Close the connection. If not connected, this does nothing.

UdpTransport.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.
UdpTransport.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
UdpTransport.isAsync()[source]

Override to return false since connect does not need to use the onConnected callback.

Returns:False
Rtype bool:
UdpTransport.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
UdpTransport.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.

UdpTransport.send(data)[source]

Send data to the host.

Parameters:data (An array type accepted by socket.send) – The buffer of data to send.

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.
getFilePath()[source]

Get the filePath given to the constructor.

Returns:The file path.
Return type:str
UnixTransport.close()[source]

Close the connection. If not connected, this does nothing.

UnixTransport.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.
UnixTransport.getIsConnected()[source]

Check if the transport is connected.

Returns:True if connected.
Return type:bool
UnixTransport.isAsync()[source]

Override to return false since connect does not need to use the onConnected callback.

Returns:False
Rtype bool:
UnixTransport.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
UnixTransport.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.

UnixTransport.send(data)[source]

Send data to the host.

Parameters:data (An array type accepted by socket.send) – The buffer of data to send.

Module contents