Net

Connection

bndl.net.connection.urlparse(address)[source]

Parse an address with urllib.parse.urlparse and checking validity in the context of bndl.

Parameters:address (str) – The address to parse
bndl.net.connection.gethostbyname[source]

A cached version of socket.gethostbyname

bndl.net.connection.getlocalhostname[source]

Provides a local hostname using gethostbyname() by attempting to get it from

  • gethostbyname(socket.getfqdn())
  • gethostbyname(socket.gethostname())
  • gethostbyname(‘localhost’)

If the above options fail, this method falls back to 127.0.0.1.

bndl.net.connection.filter_ip_addresses[source]

Filter out IP addresses from a list of addresses. IP addresses are only selected from addresses with the tcp:// scheme.

Parameters:*addresses (iterable) – URL strings (parsable by urlparse)
exception bndl.net.connection.NotConnected[source]

Bases: Exception

Raised when reading from or writing to a connection which is not / no longer connected.

class bndl.net.connection.Connection(loop, reader, writer)[source]

Bases: object

Connection object on top of an asyncio loop and a StreamReader and StreamWriter pair

send(msg, drain=True)[source]

Send a message on this connection.

Parameters:
  • msg (bndl.net.messages.Message) – The message to send.
  • drain (bool) – Whether to drain the socket after sending the message, defaults to True.
  • False there is no guarantee that the message will be sent unless more messages are (If) –
  • sent (due to watermarks at the level of the asyncio transport) –
recv(timeout=None)[source]

Receive a message from the connection.

Parameters:timeout (float) – timeout in seconds

Messages

class bndl.net.messages.Hello(**kwargs)[source]

Bases: bndl.net.messages.Message

Message shake hands with a peer node.

class bndl.net.messages.Discovered(**kwargs)[source]

Bases: bndl.net.messages.Message

Notify another node of the discovery of one or more peer nodes

class bndl.net.messages.Disconnect(**kwargs)[source]

Bases: bndl.net.messages.Message

Notify a node that the sending node is disconnecting.

class bndl.net.messages.Ping(**kwargs)[source]

Bases: bndl.net.messages.Message

Message sent to check if a node is ‘alive’.

class bndl.net.messages.Pong(**kwargs)[source]

Bases: bndl.net.messages.Message

Response to a Ping to indicate that the node is ‘alive’.