<spanclass="target"id="module-royalnet.network"></span><p>Royalnet (websocket) related classes.</p>
<dlclass="class">
<dtid="royalnet.network.RoyalnetLink">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">RoyalnetLink</code><spanclass="sig-paren">(</span><em>master_uri: str</em>, <em>secret: str</em>, <em>link_type: str</em>, <em>request_handler</em>, <em>*</em>, <em>loop: asyncio.events.AbstractEventLoop = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetLink"title="Permalink to this definition">¶</a></dt>
<dd><dlclass="method">
<dtid="royalnet.network.RoyalnetLink.connect">
<codeclass="descname">connect</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetLink.connect"title="Permalink to this definition">¶</a></dt>
<dd><p>Connect to the <aclass="reference internal"href="#royalnet.network.RoyalnetServer"title="royalnet.network.RoyalnetServer"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetServer</span></code></a> at <codeclass="docutils literal notranslate"><spanclass="pre">self.master_uri</span></code>.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetLink.identify">
<codeclass="descname">identify</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#royalnet.network.RoyalnetLink.identify"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetLink.receive">
<codeclass="descname">receive</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ royalnet.network.package.Package<aclass="headerlink"href="#royalnet.network.RoyalnetLink.receive"title="Permalink to this definition">¶</a></dt>
<dd><p>Recieve a <aclass="reference internal"href="#royalnet.network.Package"title="royalnet.network.Package"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Package</span></code></a> from the <aclass="reference internal"href="#royalnet.network.RoyalnetServer"title="royalnet.network.RoyalnetServer"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetServer</span></code></a>.</p>
<codeclass="descname">request</code><spanclass="sig-paren">(</span><em>message</em>, <em>destination</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetLink.request"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetLink.run">
<codeclass="descname">run</code><spanclass="sig-paren">(</span><em>loops: numbers.Real = inf</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetLink.run"title="Permalink to this definition">¶</a></dt>
<dd><p>Blockingly run the Link.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetLink.send">
<codeclass="descname">send</code><spanclass="sig-paren">(</span><em>package: royalnet.network.package.Package</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetLink.send"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dlclass="exception">
<dtid="royalnet.network.NetworkError">
<emclass="property">exception </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">NetworkError</code><spanclass="sig-paren">(</span><em>error_data: dict</em>, <em>*args</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.NetworkError"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="exception">
<dtid="royalnet.network.NotConnectedError">
<emclass="property">exception </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">NotConnectedError</code><aclass="headerlink"href="#royalnet.network.NotConnectedError"title="Permalink to this definition">¶</a></dt>
<dd><p>The <aclass="reference internal"href="#royalnet.network.RoyalnetLink"title="royalnet.network.RoyalnetLink"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetLink</span></code></a> is not connected to a <aclass="reference internal"href="#royalnet.network.RoyalnetServer"title="royalnet.network.RoyalnetServer"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetServer</span></code></a>.</p>
</dd></dl>
<dlclass="exception">
<dtid="royalnet.network.NotIdentifiedError">
<emclass="property">exception </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">NotIdentifiedError</code><aclass="headerlink"href="#royalnet.network.NotIdentifiedError"title="Permalink to this definition">¶</a></dt>
<dd><p>The <aclass="reference internal"href="#royalnet.network.RoyalnetLink"title="royalnet.network.RoyalnetLink"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetLink</span></code></a> has not identified yet to a <aclass="reference internal"href="#royalnet.network.RoyalnetServer"title="royalnet.network.RoyalnetServer"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetServer</span></code></a>.</p>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.Package">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">Package</code><spanclass="sig-paren">(</span><em>data: dict</em>, <em>*</em>, <em>source: str</em>, <em>destination: str</em>, <em>source_conv_id: Optional[str] = None</em>, <em>destination_conv_id: Optional[str] = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Package"title="Permalink to this definition">¶</a></dt>
<dd><p>A Royalnet package, the data type with which a <aclass="reference internal"href="#royalnet.network.RoyalnetLink"title="royalnet.network.RoyalnetLink"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetLink</span></code></a> communicates with a <aclass="reference internal"href="#royalnet.network.RoyalnetServer"title="royalnet.network.RoyalnetServer"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetServer</span></code></a> or another link.
Contains info about the source and the destination.</p>
<dlclass="method">
<dtid="royalnet.network.Package.__init__">
<codeclass="descname">__init__</code><spanclass="sig-paren">(</span><em>data: dict</em>, <em>*</em>, <em>source: str</em>, <em>destination: str</em>, <em>source_conv_id: Optional[str] = None</em>, <em>destination_conv_id: Optional[str] = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Package.__init__"title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Package.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>data</strong>– The data that should be sent. Usually a <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.Message</span></code>.</p></li>
<li><p><strong>source</strong>– The <codeclass="docutils literal notranslate"><spanclass="pre">nid</span></code> of the node that created this Package.</p></li>
<li><p><strong>destination</strong>– The <codeclass="docutils literal notranslate"><spanclass="pre">link_type</span></code> of the destination node, or alternatively, the <codeclass="docutils literal notranslate"><spanclass="pre">nid</span></code> of the node. Can also be the <codeclass="docutils literal notranslate"><spanclass="pre">NULL</span></code> value to send the message to nobody.</p></li>
<li><p><strong>source_conv_id</strong>– The conversation id of the node that created this package. Akin to the sequence number on IP packets.</p></li>
<li><p><strong>destination_conv_id</strong>– The conversation id of the node that this Package is a reply to.</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dlclass="staticmethod">
<dtid="royalnet.network.Package.from_dict">
<emclass="property">static </em><codeclass="descname">from_dict</code><spanclass="sig-paren">(</span><em>d</em><spanclass="sig-paren">)</span>→ royalnet.network.package.Package<aclass="headerlink"href="#royalnet.network.Package.from_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Package from a dictionary.</p>
</dd></dl>
<dlclass="staticmethod">
<dtid="royalnet.network.Package.from_json_bytes">
<emclass="property">static </em><codeclass="descname">from_json_bytes</code><spanclass="sig-paren">(</span><em>b: bytes</em><spanclass="sig-paren">)</span>→ royalnet.network.package.Package<aclass="headerlink"href="#royalnet.network.Package.from_json_bytes"title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Package from UTF8-encoded JSON bytes.</p>
<emclass="property">static </em><codeclass="descname">from_json_string</code><spanclass="sig-paren">(</span><em>string: str</em><spanclass="sig-paren">)</span>→ royalnet.network.package.Package<aclass="headerlink"href="#royalnet.network.Package.from_json_string"title="Permalink to this definition">¶</a></dt>
<dd><p>Create a Package from a JSON string.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Package.reply">
<codeclass="descname">reply</code><spanclass="sig-paren">(</span><em>data</em><spanclass="sig-paren">)</span>→ royalnet.network.package.Package<aclass="headerlink"href="#royalnet.network.Package.reply"title="Permalink to this definition">¶</a></dt>
<dd><p>Reply to this Package with another Package.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>data</strong>– The data that should be sent. Usually a <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.Message</span></code>.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>The reply Package.</p>
</dd>
</dl>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Package.to_dict">
<codeclass="descname">to_dict</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ dict<aclass="headerlink"href="#royalnet.network.Package.to_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Package into a dictionary.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Package.to_json_bytes">
<codeclass="descname">to_json_bytes</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ bytes<aclass="headerlink"href="#royalnet.network.Package.to_json_bytes"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Package into UTF8-encoded JSON bytes.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Package.to_json_string">
<codeclass="descname">to_json_string</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ str<aclass="headerlink"href="#royalnet.network.Package.to_json_string"title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the Package into a JSON string.</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.RoyalnetServer">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">RoyalnetServer</code><spanclass="sig-paren">(</span><em>address: str</em>, <em>port: int</em>, <em>required_secret: str</em>, <em>*</em>, <em>loop: asyncio.events.AbstractEventLoop = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer"title="Permalink to this definition">¶</a></dt>
<codeclass="descname">find_destination</code><spanclass="sig-paren">(</span><em>package: royalnet.network.package.Package</em><spanclass="sig-paren">)</span>→ List[royalnet.network.royalnetserver.ConnectedClient]<aclass="headerlink"href="#royalnet.network.RoyalnetServer.find_destination"title="Permalink to this definition">¶</a></dt>
<dd><p>Find a list of destinations for the package.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>package</strong>– The package to find the destination of.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>A <aclass="reference external"href="https://docs.python.org/3.7/library/stdtypes.html#list"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">list</span></code></a> of <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">ConnectedClients</span></code> to send the package to.</p>
</dd>
</dl>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetServer.listener">
<codeclass="descname">listener</code><spanclass="sig-paren">(</span><em>websocket: websockets.server.WebSocketServerProtocol</em>, <em>path</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer.listener"title="Permalink to this definition">¶</a></dt>
<codeclass="descname">route_package</code><spanclass="sig-paren">(</span><em>package: royalnet.network.package.Package</em><spanclass="sig-paren">)</span>→ None<aclass="headerlink"href="#royalnet.network.RoyalnetServer.route_package"title="Permalink to this definition">¶</a></dt>
<dd><p>Executed every time a package is received and must be routed somewhere.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetServer.serve">
<codeclass="descname">serve</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer.serve"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="royalnet.network.RoyalnetServer.start">
<codeclass="descname">start</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer.start"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.RoyalnetConfig">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">RoyalnetConfig</code><spanclass="sig-paren">(</span><em>master_uri: str</em>, <em>master_secret: str</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetConfig"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="exception">
<dtid="royalnet.network.ConnectionClosedError">
<emclass="property">exception </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">ConnectionClosedError</code><aclass="headerlink"href="#royalnet.network.ConnectionClosedError"title="Permalink to this definition">¶</a></dt>
<dd><p>The <aclass="reference internal"href="#royalnet.network.RoyalnetLink"title="royalnet.network.RoyalnetLink"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetLink</span></code></a>’s connection was closed unexpectedly. The link can’t be used anymore.</p>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.Request">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">Request</code><spanclass="sig-paren">(</span><em>handler: str</em>, <em>data: dict</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Request"title="Permalink to this definition">¶</a></dt>
<dd><p>A request sent from a <aclass="reference internal"href="#royalnet.network.RoyalnetLink"title="royalnet.network.RoyalnetLink"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.RoyalnetLink</span></code></a> to another.</p>
<p>It contains the name of the requested handler, in addition to the data.</p>
<dlclass="staticmethod">
<dtid="royalnet.network.Request.from_dict">
<emclass="property">static </em><codeclass="descname">from_dict</code><spanclass="sig-paren">(</span><em>d: dict</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Request.from_dict"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="royalnet.network.Request.to_dict">
<codeclass="descname">to_dict</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Request.to_dict"title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.Response">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">Response</code><aclass="headerlink"href="#royalnet.network.Response"title="Permalink to this definition">¶</a></dt>
<dd><p>A base class to be inherited by all other response types.</p>
<dlclass="classmethod">
<dtid="royalnet.network.Response.from_dict">
<emclass="property">classmethod </em><codeclass="descname">from_dict</code><spanclass="sig-paren">(</span><em>d: dict</em><spanclass="sig-paren">)</span>→ royalnet.network.response.Response<aclass="headerlink"href="#royalnet.network.Response.from_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Recreate the response from a received <aclass="reference external"href="https://docs.python.org/3.7/library/stdtypes.html#dict"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">dict</span></code></a>.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Response.raise_on_error">
<codeclass="descname">raise_on_error</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.Response.raise_on_error"title="Permalink to this definition">¶</a></dt>
<dd><p>Raise an <aclass="reference external"href="https://docs.python.org/3.7/library/exceptions.html#Exception"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Exception</span></code></a> if the Response is an error, do nothing otherwise.</p>
</dd></dl>
<dlclass="method">
<dtid="royalnet.network.Response.to_dict">
<codeclass="descname">to_dict</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span>→ dict<aclass="headerlink"href="#royalnet.network.Response.to_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Prepare the Response to be sent by converting it to a JSONable <aclass="reference external"href="https://docs.python.org/3.7/library/stdtypes.html#dict"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">dict</span></code></a>.</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.ResponseSuccess">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">ResponseSuccess</code><spanclass="sig-paren">(</span><em>data: Optional[dict] = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.ResponseSuccess"title="Permalink to this definition">¶</a></dt>
<dd><p>A response to a successful <aclass="reference internal"href="#royalnet.network.Request"title="royalnet.network.Request"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.Request</span></code></a>.</p>
<codeclass="descname">raise_on_error</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.ResponseSuccess.raise_on_error"title="Permalink to this definition">¶</a></dt>
<dd><p>Raise an <aclass="reference external"href="https://docs.python.org/3.7/library/exceptions.html#Exception"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Exception</span></code></a> if the Response is an error, do nothing otherwise.</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="royalnet.network.ResponseError">
<emclass="property">class </em><codeclass="descclassname">royalnet.network.</code><codeclass="descname">ResponseError</code><spanclass="sig-paren">(</span><em>name: str</em>, <em>description: str</em>, <em>extra_info: Optional[dict] = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.ResponseError"title="Permalink to this definition">¶</a></dt>
<dd><p>A response to a invalid <aclass="reference internal"href="#royalnet.network.Request"title="royalnet.network.Request"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">royalnet.network.Request</span></code></a>.</p>
<codeclass="descname">raise_on_error</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.ResponseError.raise_on_error"title="Permalink to this definition">¶</a></dt>
<dd><p>Raise an <aclass="reference external"href="https://docs.python.org/3.7/library/exceptions.html#Exception"title="(in Python v3.7)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Exception</span></code></a> if the Response is an error, do nothing otherwise.</p>
Built with <ahref="http://sphinx-doc.org/">Sphinx</a> using a <ahref="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <ahref="https://readthedocs.org">Read the Docs</a>.