<spanclass="target"id="module-royalnet.network"></span><p>Royalnet (websocket) related classes.</p>
<dlclass="class">
<dtid="royalnet.network.RoyalnetLink">
<emclass="property">class </em><codeclass="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">RoyalnetLink</code><spanclass="sig-paren">(</span><emclass="sig-param">master_uri: str</em>, <emclass="sig-param">secret: str</em>, <emclass="sig-param">link_type: str</em>, <emclass="sig-param">request_handler</em>, <emclass="sig-param">*</em>, <emclass="sig-param">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">
<emclass="property">async </em><codeclass="sig-name 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">
<emclass="property">async </em><codeclass="sig-name 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">
<emclass="property">async </em><codeclass="sig-name 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>
<emclass="property">async </em><codeclass="sig-name descname">request</code><spanclass="sig-paren">(</span><emclass="sig-param">message</em>, <emclass="sig-param">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">
<emclass="property">async </em><codeclass="sig-name descname">run</code><spanclass="sig-paren">(</span><emclass="sig-param">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">
<emclass="property">async </em><codeclass="sig-name descname">send</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">NetworkError</code><spanclass="sig-paren">(</span><emclass="sig-param">error_data: dict</em>, <emclass="sig-param">*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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name 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><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="sig-name descname">__init__</code><spanclass="sig-paren">(</span><emclass="sig-param">data: dict</em>, <emclass="sig-param">*</em>, <emclass="sig-param">source: str</em>, <emclass="sig-param">destination: str</em>, <emclass="sig-param">source_conv_id: Optional[str] = None</em>, <emclass="sig-param">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="method">
<dtid="royalnet.network.Package.from_dict">
<emclass="property">static </em><codeclass="sig-name descname">from_dict</code><spanclass="sig-paren">(</span><emclass="sig-param">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="method">
<dtid="royalnet.network.Package.from_json_bytes">
<emclass="property">static </em><codeclass="sig-name descname">from_json_bytes</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name descname">from_json_string</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name descname">reply</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name 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="sig-name 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="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">RoyalnetServer</code><spanclass="sig-paren">(</span><emclass="sig-param">address: str</em>, <emclass="sig-param">port: int</em>, <emclass="sig-param">required_secret: str</em>, <emclass="sig-param">*</em>, <emclass="sig-param">loop: asyncio.events.AbstractEventLoop = None</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">find_destination</code><spanclass="sig-paren">(</span><emclass="sig-param">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">
<emclass="property">async </em><codeclass="sig-name descname">listener</code><spanclass="sig-paren">(</span><emclass="sig-param">websocket: websockets.server.WebSocketServerProtocol</em>, <emclass="sig-param">path</em><spanclass="sig-paren">)</span><aclass="headerlink"href="#royalnet.network.RoyalnetServer.listener"title="Permalink to this definition">¶</a></dt>
<emclass="property">async </em><codeclass="sig-name descname">route_package</code><spanclass="sig-paren">(</span><emclass="sig-param">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">
<emclass="property">async </em><codeclass="sig-name 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">
<emclass="property">async </em><codeclass="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">RoyalnetConfig</code><spanclass="sig-paren">(</span><emclass="sig-param">master_uri: str</em>, <emclass="sig-param">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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">Request</code><spanclass="sig-paren">(</span><emclass="sig-param">handler: str</em>, <emclass="sig-param">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="method">
<dtid="royalnet.network.Request.from_dict">
<emclass="property">static </em><codeclass="sig-name descname">from_dict</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name 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="method">
<dtid="royalnet.network.Response.from_dict">
<emclass="property">classmethod </em><codeclass="sig-name descname">from_dict</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name 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="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">ResponseSuccess</code><spanclass="sig-paren">(</span><emclass="sig-param">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="sig-name 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="sig-prename descclassname">royalnet.network.</code><codeclass="sig-name descname">ResponseError</code><spanclass="sig-paren">(</span><emclass="sig-param">name: str</em>, <emclass="sig-param">description: str</em>, <emclass="sig-param">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="sig-name 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>.