aea.connections.base
The base connection package.
ConnectionStates Objects
class ConnectionStates(Enum)
Connection states enum.
Connection Objects
class Connection(Component, ABC)
Abstract definition of a connection.
connection_
id
type: PublicId
__
init__
def __init__(configuration: ConnectionConfig,
data_dir: str,
identity: Optional[Identity] = None,
crypto_store: Optional[CryptoStore] = None,
restricted_to_protocols: Optional[Set[PublicId]] = None,
excluded_protocols: Optional[Set[PublicId]] = None,
**kwargs: Any) -> None
Initialize the connection.
The configuration must be specified if and only if the following parameters are None: connection_id, excluded_protocols or restricted_to_protocols.
Arguments:
configuration
: the connection configuration.data_dir
: directory where to put local files.identity
: the identity object held by the agent.crypto_store
: the crypto store for encrypted communication.restricted_to_protocols
: the set of protocols ids of the only supported protocols for this connection.excluded_protocols
: the set of protocols ids that we want to exclude for this connection.kwargs
: keyword arguments passed to component base
loop
@property
def loop() -> asyncio.AbstractEventLoop
Get the event loop.
address
@property
def address() -> "Address"
Get the address.
crypto_
store
@property
def crypto_store() -> CryptoStore
Get the crypto store.
has_
crypto_
store
@property
def has_crypto_store() -> bool
Check if the connection has the crypto store.
data_
dir
@property
def data_dir() -> str
Get the data directory.
component_
type
@property
def component_type() -> ComponentType
Get the component type.
configuration
@property
def configuration() -> ConnectionConfig
Get the connection configuration.
restricted_
to_
protocols
@property
def restricted_to_protocols() -> Set[PublicId]
Get the ids of the protocols this connection is restricted to.
excluded_
protocols
@property
def excluded_protocols() -> Set[PublicId]
Get the ids of the excluded protocols for this connection.
state
@property
def state() -> ConnectionStates
Get the connection status.
state
@state.setter
def state(value: ConnectionStates) -> None
Set the connection status.
connect
@abstractmethod
async def connect() -> None
Set up the connection.
disconnect
@abstractmethod
async def disconnect() -> None
Tear down the connection.
send
@abstractmethod
async def send(envelope: "Envelope") -> None
Send an envelope.
Arguments:
envelope
: the envelope to send.
Returns:
None
receive
@abstractmethod
async def receive(*args: Any, **kwargs: Any) -> Optional["Envelope"]
Receive an envelope.
Arguments:
args
: positional argumentskwargs
: keyword arguments
Returns:
the received envelope, or None if an error occurred.
from_
dir
@classmethod
def from_dir(cls, directory: str, identity: Identity,
crypto_store: CryptoStore, data_dir: str,
**kwargs: Any) -> "Connection"
Load the connection from a directory.
Arguments:
directory
: the directory to the connection package.identity
: the identity object.crypto_store
: object to access the connection crypto objects.data_dir
: the assets directory.kwargs
: keyword arguments passed to connection base
Returns:
the connection object.
from_
config
@classmethod
def from_config(cls, configuration: ConnectionConfig, identity: Identity,
crypto_store: CryptoStore, data_dir: str,
**kwargs: Any) -> "Connection"
Load a connection from a configuration.
Arguments:
configuration
: the connection configuration.identity
: the identity object.crypto_store
: object to access the connection crypto objects.data_dir
: the directory of the AEA project data.kwargs
: keyword arguments passed to component base
Returns:
an instance of the concrete connection class.
is_
connected
@property
def is_connected() -> bool
Return is connected state.
is_
connecting
@property
def is_connecting() -> bool
Return is connecting state.
is_
disconnected
@property
def is_disconnected() -> bool
Return is disconnected state.
BaseSyncConnection Objects
class BaseSyncConnection(Connection)
Base sync connection class to write connections with sync code.
__
init__
def __init__(configuration: ConnectionConfig,
data_dir: str,
identity: Optional[Identity] = None,
crypto_store: Optional[CryptoStore] = None,
restricted_to_protocols: Optional[Set[PublicId]] = None,
excluded_protocols: Optional[Set[PublicId]] = None,
**kwargs: Any) -> None
Initialize the connection.
The configuration must be specified if and only if the following parameters are None: connection_id, excluded_protocols or restricted_to_protocols.
Arguments:
configuration
: the connection configuration.data_dir
: directory where to put local files.identity
: the identity object held by the agent.crypto_store
: the crypto store for encrypted communication.restricted_to_protocols
: the set of protocols ids of the only supported protocols for this connection.excluded_protocols
: the set of protocols ids that we want to exclude for this connection.kwargs
: keyword arguments passed to connection base
put_
envelope
def put_envelope(envelope: Optional["Envelope"]) -> None
Put envelope in to the incoming queue.
connect
async def connect() -> None
Connect connection.
disconnect
async def disconnect() -> None
Disconnect connection.
send
async def send(envelope: "Envelope") -> None
Send envelope to connection.
receive
async def receive(*args: Any, **kwargs: Any) -> Optional["Envelope"]
Get an envelope from the connection.
start_
main
def start_main() -> None
Start main function of the connection.
main
def main() -> None
Run main body of the connection in dedicated thread.
on_
connect
@abstractmethod
def on_connect() -> None
Run on connect method called.
on_
disconnect
@abstractmethod
def on_disconnect() -> None
Run on disconnect method called.
on_
send
@abstractmethod
def on_send(envelope: "Envelope") -> None
Run on send method called.