Service
elva.apps.service
ELVA local service app.
Classes:
-
WebsocketMetaProvider
–Broker routing Y updates from and to local and remote connections.
Functions:
-
missing_identifier
–Check a request for a missing Y document identifier.
-
get_websocket_identifier
–Get an identifier of a websocket connection object.
-
get_uuid_from_local_websocket
–Get the Y document UUID from the connection path.
-
main
–Main routine of the service app.
-
cli
–Launch a relay to an ELVA websocket server.
WebsocketMetaProvider(user, password, uri)
Bases: WebsocketConnection
Broker routing Y updates from and to local and remote connections.
Parameters:
-
user
(str
) –the user name to login with.
-
password
(str
) –the password to login with.
-
uri
(str
) –the URI to connect to remotely.
Methods:
-
on_recv
–Hook called on receiving data from remote.
-
create_uuid_message
–Create a message with a UUID message prepended.
-
process_uuid_message
–Decode a UUID message.
-
serve
–Handler for new websocket connections.
-
on_exception
–Hook called on an exception raised during the connection setup.
Attributes:
-
LOCAL_SOCKETS
(dict[UUID, set[Websocket]]
) –Mapping of Y document identifiers to their corresponding set of websocket connections.
Source code in src/elva/apps/service.py
LOCAL_SOCKETS = dict()
instance-attribute
Mapping of Y document identifiers to their corresponding set of websocket connections.
on_recv(message)
async
Hook called on receiving data from remote.
This method routes messages to local connections.
Parameters:
-
message
(bytes
) –the received message.
Source code in src/elva/apps/service.py
create_uuid_message(message, uuid)
Create a message with a UUID message prepended.
Parameters:
-
message
(bytes
) –the payload to attach to the UUID message.
-
uuid
(str
) –the UUID to prepend before the message.
Returns:
-
bytes
–the UUID message and the given payload concatenated.
Source code in src/elva/apps/service.py
_send(message, uuid, origin_ws=None)
async
Forward a message to local or remote connections depending on the message's origin.
Parameters:
-
message
(bytes
) –the message to forward.
-
uuid
(str
) –the uuid of the Y document the message belongs to.
-
origin_ws
(Websocket | None
, default:None
) –the websocket connection from which the message came.
Source code in src/elva/apps/service.py
_send_to_remote(message, uuid, origin_ws, origin_name)
async
Send a message over the remote connection.
Parameters:
-
message
(str
) –the message to send.
-
uuid
(UUID
) –the UUID of the Y document the message belongs to.
-
origin_ws
(Websocket | None
) –the websocket connection from which the message came.
-
origin_name
(str
) –the identifier of the websocket connection the message came from.
Source code in src/elva/apps/service.py
_send_to_local(message, uuid, origin_ws, origin_name)
async
Send a message to local connections.
Parameters:
-
message
(str
) –the message to send.
-
uuid
(UUID
) –the UUID of the Y document the message belongs to.
-
origin_ws
(Websocket | None
) –the websocket connection from which the message came.
-
origin_name
(str
) –the identifier of the websocket connection the message came from.
Source code in src/elva/apps/service.py
process_uuid_message(message)
Decode a UUID message.
Parameters:
-
message
(bytes
) –the message to decode.
Returns:
Source code in src/elva/apps/service.py
serve(local)
async
Handler for new websocket connections.
Parameters:
-
local
(Websocket
) –new local websocket connection.
_send_from_local(local, uuid)
async
Routine listening for incoming messages from local websocket connections.
Parameters:
-
local
(Websocket
) –local websocket connection.
-
uuid
(str
) –UUID of the Y document to which incoming messages belong.
Source code in src/elva/apps/service.py
on_exception(exc)
async
Hook called on an exception raised during the connection setup.
Parameters:
-
exc
(Exception
) –the exception raised from the connection setup.
Source code in src/elva/apps/service.py
missing_identifier(path, request)
Check a request for a missing Y document identifier.
Parameters:
Returns:
-
tuple[StatusLike, HeadersLike, bytes] | None
–None
to continue the request normally or a tuple with cancel information.
Source code in src/elva/apps/service.py
get_websocket_identifier(websocket)
Get an identifier of a websocket connection object.
Parameters:
-
websocket
(Websocket
) –the websocket connection to get an identifier for.
Returns:
-
str
–the identifier of the given websocket connection.
Source code in src/elva/apps/service.py
get_uuid_from_local_websocket(websocket)
Get the Y document UUID from the connection path.
Parameters:
-
websocket
(Websocket
) –the websocket connection from which to extract the Y document UUID.
Returns:
-
UUID
–the path of the websocket connection, which should be the Y document UUID.
Source code in src/elva/apps/service.py
main(server, host, port)
async
Main routine of the service app.
Parameters:
-
server
(WebsocketMetaProvider
) –the broker component routing messages between local and remote connections.
-
host
(str
) –the host address to listen on for new connections.
-
port
(int
) –the port to listen on for new connections.
Source code in src/elva/apps/service.py
cli(ctx, host, port)
Launch a relay to an ELVA websocket server.
Parameters:
-
ctx
(Context
) –the click context holding the configuration parameter object.
-
host
(str
) –the host address to listen on for new connections.
-
port
(int
) –the port to listen on for new connections.