@@ -1362,6 +1362,295 @@ the link has been established.</p>
</div>
<p>This example can also be found at <aclass="reference external"href="https://github.com/markqvist/Reticulum/blob/master/Examples/Identify.py">https://github.com/markqvist/Reticulum/blob/master/Examples/Identify.py</a>.</p>
</div>
<divclass="section"id="requests-responses">
<spanid="example-request"></span><h2>Requests & Responses<aclass="headerlink"href="#requests-responses"title="Permalink to this headline">¶</a></h2>
<p>The <em>Request</em> example explores sendig requests and receiving responses.</p>
<spanclass="n">texts</span><spanclass="o">=</span><spanclass="p">[</span><spanclass="s2">"They looked up"</span><spanclass="p">,</span><spanclass="s2">"On each full moon"</span><spanclass="p">,</span><spanclass="s2">"Becky was upset"</span><spanclass="p">,</span><spanclass="s2">"I’ll stay away from it"</span><spanclass="p">,</span><spanclass="s2">"The pet shop stocks everything"</span><spanclass="p">]</span>
<spanclass="s2">" running, waiting for a connection."</span>
<spanclass="p">)</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Hit enter to manually send an announce (Ctrl-C to quit)"</span><spanclass="p">)</span>
<spanclass="c1"># We enter a loop that runs until the users exits.</span>
<spanclass="c1"># If the user hits enter, we will announce our server</span>
<spanclass="c1"># destination on the network, which will let clients</span>
<spanclass="c1"># know how to create messages directed towards it.</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Sent announce from "</span><spanclass="o">+</span><spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">prettyhexrep</span><spanclass="p">(</span><spanclass="n">destination</span><spanclass="o">.</span><spanclass="n">hash</span><spanclass="p">))</span>
<spanclass="c1"># When a client establishes a link to our server</span>
<spanclass="c1"># destination, this function will be called with</span>
<spanclass="k">raise</span><spanclass="ne">ValueError</span><spanclass="p">(</span><spanclass="s2">"Destination length is invalid, must be 20 hexadecimal characters (10 bytes)"</span><spanclass="p">)</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Destination is not yet known. Requesting path and waiting for announce to arrive..."</span><spanclass="p">)</span>
<spanclass="c1"># Inform the user that we'll begin connecting</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Establishing link with server..."</span><spanclass="p">)</span>
<spanclass="c1"># When the server identity is known, we set</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Error while sending request over the link: "</span><spanclass="o">+</span><spanclass="nb">str</span><spanclass="p">(</span><spanclass="n">e</span><spanclass="p">))</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"The request "</span><spanclass="o">+</span><spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">prettyhexrep</span><spanclass="p">(</span><spanclass="n">request_receipt</span><spanclass="o">.</span><spanclass="n">request_id</span><spanclass="p">)</span><spanclass="o">+</span><spanclass="s2">" was received by the remote peer."</span><spanclass="p">)</span>
<spanclass="c1"># Inform the user that the server is</span>
<spanclass="c1"># connected</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"Link established with server, hit enter to perform a request, or type in </span><spanclass="se">\"</span><spanclass="s2">quit</span><spanclass="se">\"</span><spanclass="s2"> to quit"</span><spanclass="p">)</span>
<spanclass="c1"># When a link is closed, we'll inform the</span>
<spanclass="c1"># user, and exit the program</span>
<spanclass="n">RNS</span><spanclass="o">.</span><spanclass="n">log</span><spanclass="p">(</span><spanclass="s2">"The link was closed by the server, exiting now"</span><spanclass="p">)</span>
<spanclass="n">help</span><spanclass="o">=</span><spanclass="s2">"path to alternative Reticulum config directory"</span><spanclass="p">,</span>
<p>This example can also be found at <aclass="reference external"href="https://github.com/markqvist/Reticulum/blob/master/Examples/Request.py">https://github.com/markqvist/Reticulum/blob/master/Examples/Request.py</a>.</p>
</div>
<divclass="section"id="filetransfer">
<spanid="example-filetransfer"></span><h2>Filetransfer<aclass="headerlink"href="#filetransfer"title="Permalink to this headline">¶</a></h2>
<p>The <em>Filetransfer</em> example implements a basic file-server program that
@@ -1504,7 +1793,12 @@ interface to efficiently pass files of any size over a Reticulum <a class="refer
<spanclass="sig-name descname"><spanclass="pre">register_request_handler</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">path</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">response_generator</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">allow</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">0</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">allowed_list</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#RNS.Destination.register_request_handler"title="Permalink to this definition">¶</a></dt>
<dd><p>Registers a request handler.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong>– The path for the request handler to be registered.</p></li>
<li><p><strong>response_generator</strong>– A function or method with the signature <em>response_generator(path, data, remote_identity_hash, requested_at)</em> to be called. Whatever this funcion returns will be sent as a response to the requester. If the function returns <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>, no response will be sent.</p></li>
<li><p><strong>allow</strong>– One of <codeclass="docutils literal notranslate"><spanclass="pre">RNS.Destination.ALLOW_NONE</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">RNS.Destination.ALLOW_ALL</span></code> or <codeclass="docutils literal notranslate"><spanclass="pre">RNS.Destination.ALLOW_LIST</span></code>. If <codeclass="docutils literal notranslate"><spanclass="pre">RNS.Destination.ALLOW_LIST</span></code> is set, the request handler will only respond to requests for identified peers in the supplied list.</p></li>
<li><p><strong>allowed_list</strong>– A list of <em>bytes-like</em><aclass="reference internal"href="#api-identity"><spanclass="std std-ref">RNS.Identity</span></a> hashes.</p></li>
</ul>
</dd>
<dtclass="field-even">Raises</dt>
<ddclass="field-even"><p><codeclass="docutils literal notranslate"><spanclass="pre">ValueError</span></code> if any of the supplied arguments are invalid.</p>
<spanclass="sig-name descname"><spanclass="pre">deregister_request_handler</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">path</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#RNS.Destination.deregister_request_handler"title="Permalink to this definition">¶</a></dt>
<dd><p>Deregisters a request handler.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>path</strong>– The path for the request handler to be deregistered.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p>True if the handler was deregistered, otherwise False.</p>
<spanclass="sig-name descname"><spanclass="pre">create_keys</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#RNS.Destination.create_keys"title="Permalink to this definition">¶</a></dt>
@@ -785,6 +818,21 @@ thus preserved. This method can be used for authentication.</p>
<spanclass="sig-name descname"><spanclass="pre">request</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">path</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">data</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">response_callback</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">failed_callback</span></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><aclass="headerlink"href="#RNS.Link.request"title="Permalink to this definition">¶</a></dt>
<dd><p>Sends a request to the remote peer.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>path</strong>– The request path.</p></li>
<li><p><strong>response_callback</strong>– A function or method with the signature <em>response_callback(request_receipt)</em> to be called when a response is received. See the <aclass="reference internal"href="examples.html#example-request"><spanclass="std std-ref">Request Example</span></a> for more info.</p></li>
<li><p><strong>failed_callback</strong>– A function or method with the signature <em>failed_callback(request_receipt)</em> to be called when a request fails. See the <aclass="reference internal"href="examples.html#example-request"><spanclass="std std-ref">Request Example</span></a> for more info.</p></li>
<spanclass="sig-name descname"><spanclass="pre">no_inbound_for</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="headerlink"href="#RNS.Link.no_inbound_for"title="Permalink to this definition">¶</a></dt>
@@ -934,7 +982,7 @@ compression, coordination and checksumming.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>data</strong>– The data to be transferred. Can be <em>bytes</em> or an open <em>file handle</em>. See the <spanclass="xref std std-ref">Filetransfer Example</span> for details.</p></li>
<li><p><strong>data</strong>– The data to be transferred. Can be <em>bytes</em> or an open <em>file handle</em>. See the <aclass="reference internal"href="examples.html#example-filetransfer"><spanclass="std std-ref">Filetransfer Example</span></a> for details.</p></li>
<li><p><strong>link</strong>– The <aclass="reference internal"href="#api-link"><spanclass="std std-ref">RNS.Link</span></a> instance on which to transfer the data.</p></li>
<li><p><strong>advertise</strong>– Whether to automatically advertise the resource. Can be <em>True</em> or <em>False</em>.</p></li>
<li><p><strong>auto_compress</strong>– Whether to auto-compress the resource. Can be <em>True</em> or <em>False</em>.</p></li>
This example can also be found at `<https://github.com/markqvist/Reticulum/blob/master/Examples/Identify.py>`_.
.._example-request:
Requests & Responses
====================
The *Request* example explores sendig requests and receiving responses.
..literalinclude:: ../../Examples/Request.py
This example can also be found at `<https://github.com/markqvist/Reticulum/blob/master/Examples/Request.py>`_.
.._example-filetransfer:
Filetransfer
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.