royalnet.network

Royalnet (websocket) related classes.

connect()

Connect to the royalnet.network.RoyalnetServer at self.master_uri.

identify() → None
receive() → royalnet.network.package.Package

Recieve a Package from the royalnet.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 a royalnet.network.RoyalnetServer.

exception royalnet.network.NotIdentifiedError

The royalnet.network.RoyalnetLink has not identified yet to a royalnet.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 a royalnet.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, the nid of the node. Can also be the NULL 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 of ConnectedClients 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()
class royalnet.network.Response

A base class to be inherited by all other response types.

classmethod from_dict(d: dict) → royalnet.network.response.Response

Recreate the response from a received dict.

raise_on_error()

Raise an Exception if the Response is an error, do nothing otherwise.

to_dict() → dict

Prepare the Response to be sent by converting it to a JSONable dict.

class royalnet.network.ResponseSuccess(data: Optional[dict] = None)

A response to a successful royalnet.network.Request.

raise_on_error()

Raise an Exception if the Response is an error, do nothing otherwise.

class royalnet.network.ResponseError(name: str, description: str, extra_info: Optional[dict] = None)

A response to a invalid royalnet.network.Request.

raise_on_error()

Raise an Exception if the Response is an error, do nothing otherwise.