royalnet.network¶
Royalnet (websocket) related classes.
-
class
royalnet.network.
RoyalnetLink
(master_uri: str, secret: str, link_type: str, request_handler, *, loop: asyncio.events.AbstractEventLoop = <_WindowsSelectorEventLoop running=False closed=False debug=False>)¶ -
connect
()¶ Connect to the
royalnet.network.RoyalnetServer
atself.master_uri
.
-
identify
() → None¶
-
receive
() → royalnet.network.package.Package¶ Recieve a
Package
from theroyalnet.network.RoyalnetServer
.- Raises
royalnet.network.royalnetlink.ConnectionClosedError –
-
request
(message, destination)¶
-
run
(loops: numbers.Real = inf)¶ Blockingly run the Link.
-
send
(package: royalnet.network.package.Package)¶
-
-
exception
royalnet.network.
NetworkError
(error_data: dict, *args)¶
-
exception
royalnet.network.
NotConnectedError
¶ The
royalnet.network.RoyalnetLink
is not connected to aroyalnet.network.RoyalnetServer
.
-
exception
royalnet.network.
NotIdentifiedError
¶ The
royalnet.network.RoyalnetLink
has not identified yet to aroyalnet.network.RoyalnetServer
.
-
class
royalnet.network.
Package
(data: dict, *, source: str, destination: str, source_conv_id: Optional[str] = None, destination_conv_id: Optional[str] = None)¶ A Royalnet package, the data type with which a
royalnet.network.RoyalnetLink
communicates with aroyalnet.network.RoyalnetServer
or another link. Contains info about the source and the destination.-
__init__
(data: dict, *, source: str, destination: str, source_conv_id: Optional[str] = None, destination_conv_id: Optional[str] = None)¶ Create a Package.
- Parameters
data – The data that should be sent. Usually a
royalnet.network.Message
.source – The
nid
of the node that created this Package.destination – The
link_type
of the destination node, or alternatively, thenid
of the node. Can also be theNULL
value to send the message to nobody.source_conv_id – The conversation id of the node that created this package. Akin to the sequence number on IP packets.
destination_conv_id – The conversation id of the node that this Package is a reply to.
-
static
from_dict
(d) → royalnet.network.package.Package¶ Create a Package from a dictionary.
-
static
from_json_bytes
(b: bytes) → royalnet.network.package.Package¶ Create a Package from UTF8-encoded JSON bytes.
-
static
from_json_string
(string: str) → royalnet.network.package.Package¶ Create a Package from a JSON string.
-
reply
(data) → royalnet.network.package.Package¶ Reply to this Package with another Package.
- Parameters
data – The data that should be sent. Usually a
royalnet.network.Message
.- Returns
The reply Package.
-
to_dict
() → dict¶ Convert the Package into a dictionary.
-
to_json_bytes
() → bytes¶ Convert the Package into UTF8-encoded JSON bytes.
-
to_json_string
() → str¶ Convert the Package into a JSON string.
-
-
class
royalnet.network.
RoyalnetServer
(address: str, port: int, required_secret: str, *, loop: asyncio.events.AbstractEventLoop = <_WindowsSelectorEventLoop running=False closed=False debug=False>)¶ -
find_client
(*, nid: str = None, link_type: str = None) → List[royalnet.network.royalnetserver.ConnectedClient]¶
-
find_destination
(package: royalnet.network.package.Package) → List[royalnet.network.royalnetserver.ConnectedClient]¶ Find a list of destinations for the package.
- Parameters
package – The package to find the destination of.
- Returns
A
list
ofConnectedClients
to send the package to.
-
listener
(websocket: websockets.server.WebSocketServerProtocol, path)¶
-
route_package
(package: royalnet.network.package.Package) → None¶ Executed every time a package is received and must be routed somewhere.
-
serve
()¶
-
start
()¶
-
-
class
royalnet.network.
RoyalnetConfig
(master_uri: str, master_secret: str)¶
-
exception
royalnet.network.
ConnectionClosedError
¶ The
royalnet.network.RoyalnetLink
’s connection was closed unexpectedly. The link can’t be used anymore.
-
class
royalnet.network.
Request
(handler: str, data: dict)¶ A request sent from a
royalnet.network.RoyalnetLink
to another.It contains the name of the requested handler, in addition to the data.
-
static
from_dict
(d: dict)¶
-
to_dict
()¶
-
static
-
class
royalnet.network.
Response
¶ A base class to be inherited by all other response types.
-
class
royalnet.network.
ResponseSuccess
(data: Optional[dict] = None)¶ A response to a successful
royalnet.network.Request
.
-
class
royalnet.network.
ResponseError
(name: str, description: str, extra_info: Optional[dict] = None)¶ A response to a invalid
royalnet.network.Request
.