communication.pool module¶
This module contains the Pool class used to communicate between parties
- class communication.pool.Pool(key=None, cert=None, ca_cert=None)[source]¶
Bases:
object
Facilitates a communication pool that enables communication between us (server) and others (clients).
- __init__(key=None, cert=None, ca_cert=None)[source]¶
Initalises a pool
- Parameters:
key (
Optional
[str
]) – path to the key to use in the ssl contextcert (
Optional
[str
]) – path to the certificate to use in the ssl contextca_cert (
Optional
[str
]) – path to the certificate authority (CA) certificate to use in the ssl context
- add_http_client(name, addr, port=None)[source]¶
Add an HTTP Client to the pool. addr can be either an IP address or a hostname.
- Parameters:
name (
str
) – name of the clientaddr (
str
) – (ip) address of the clientport (
Optional
[int
]) – port of the client
- Return type:
None
- add_http_server(port=None, addr='0.0.0.0')[source]¶
Add an HTTP Server to the pool.
- Parameters:
addr (
str
) – (ip) address of the serverport (
Optional
[int
]) – port of the server
- Return type:
None
- arecv(handler_name, msg_id=None)[source]¶
Receive a message synchronously from a peer.
- Parameters:
handler_name (
str
) – the name of the pool handler to receive a message frommsg_id (
Optional
[str
]) – an optional string identifying the message to collect
- Return type:
Future
[Any
]- Returns:
the message from peer or a Future.
- asend(handler_name, message, msg_id=None)[source]¶
Send a message to peer asynchronously. Schedules the sending of the message and returns immediately. There is no assurance of feedback about the message being delivered.
- Parameters:
handler_name (
str
) – the name of the pool handler to send a message tomessage (
Any
) – the message to sendmsg_id (
Optional
[str
]) – an optional string identifying the message to send
- Return type:
None
- static create_ssl_context(key, cert, ca_cert=None, server=False)[source]¶
Create an SSL context.
- Parameters:
key (
Optional
[str
]) – path to the key to use in the ssl contextcert (
Optional
[str
]) – path to the certificate to use in the ssl contextca_cert (
Optional
[str
]) – path to the certificate authority (CA) certificate to use in the ssl contextserver (
bool
) – boolean stating whether we need a server context or not (client)
- Return type:
Optional
[SSLContext
]- Returns:
an SSL context or None
- static get_port(ssl_ctx)[source]¶
Returns a port number based on whether an ssl context is provided, or not.
- Parameters:
ssl_ctx (
Optional
[SSLContext
]) – an ssl context- Return type:
int
- Returns:
a port number
- async recv(handler_name, msg_id=None)[source]¶
Receive a message asynchronously from a peer. Ensures result.
- Parameters:
handler_name (
str
) – the name of the pool handler to receive a message frommsg_id (
Optional
[str
]) – an optional string identifying the message to collect
- Return type:
Any
- Returns:
the message from peer.
- async send(handler_name, message, msg_id=None)[source]¶
Send a message to peer synchronously.
- Parameters:
handler_name (
str
) – the name of the pool handler to send a message tomessage (
Any
) – the message to sendmsg_id (
Optional
[str
]) – an optional string identifying the message to send
- Return type:
None