|
|
@ -80,7 +80,13 @@ program.</p>
|
|
|
|
<span class="c1"># existence, which will let the network know they are reachable</span>
|
|
|
|
<span class="c1"># existence, which will let the network know they are reachable</span>
|
|
|
|
<span class="c1"># and autoomatically create paths to them, from anywhere else</span>
|
|
|
|
<span class="c1"># and autoomatically create paths to them, from anywhere else</span>
|
|
|
|
<span class="c1"># in the network.</span>
|
|
|
|
<span class="c1"># in the network.</span>
|
|
|
|
<span class="n">destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"minimalsample"</span><span class="p">)</span>
|
|
|
|
<span class="n">destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"minimalsample"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We configure the destination to automatically prove all</span>
|
|
|
|
<span class="c1"># We configure the destination to automatically prove all</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
@ -97,7 +103,11 @@ program.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">announceLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">announceLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Minimal example "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" running, hit enter to manually send an announce (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Minimal example "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" running, hit enter to manually send an announce (Ctrl-C to quit)"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will announce our server</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will announce our server</span>
|
|
|
@ -118,8 +128,18 @@ program.</p>
|
|
|
|
<span class="c1"># the desired program mode.</span>
|
|
|
|
<span class="c1"># the desired program mode.</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Bare minimum example to start Reticulum and create a destination"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="n">description</span><span class="o">=</span><span class="s2">"Minimal example to start Reticulum and create a destination"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
@ -158,7 +178,7 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
<span class="n">APP_NAME</span> <span class="o">=</span> <span class="s2">"example_utilities"</span>
|
|
|
|
<span class="n">APP_NAME</span> <span class="o">=</span> <span class="s2">"example_utilities"</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We initialise two lists of strings to use as app_data</span>
|
|
|
|
<span class="c1"># We initialise two lists of strings to use as app_data</span>
|
|
|
|
<span class="n">fruits</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Peach"</span><span class="p">,</span> <span class="s2">"Quince"</span><span class="p">,</span> <span class="s2">"Date palm"</span><span class="p">,</span> <span class="s2">"Tangerine"</span><span class="p">,</span> <span class="s2">"Pomelo"</span><span class="p">,</span> <span class="s2">"Carambola"</span><span class="p">,</span> <span class="s2">"Grape"</span><span class="p">,</span> <span class="s2">"Passion fruit"</span><span class="p">,</span> <span class="s2">"Prune"</span><span class="p">,</span> <span class="s2">"Cranberry"</span><span class="p">,</span> <span class="s2">"Strawberry"</span><span class="p">,</span> <span class="s2">"Papaya"</span><span class="p">,</span> <span class="s2">"Pomegranate"</span><span class="p">,</span> <span class="s2">"Avocado"</span><span class="p">,</span> <span class="s2">"Mango"</span><span class="p">]</span>
|
|
|
|
<span class="n">fruits</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Peach"</span><span class="p">,</span> <span class="s2">"Quince"</span><span class="p">,</span> <span class="s2">"Date palm"</span><span class="p">,</span> <span class="s2">"Tangerine"</span><span class="p">,</span> <span class="s2">"Pomelo"</span><span class="p">,</span> <span class="s2">"Carambola"</span><span class="p">,</span> <span class="s2">"Grape"</span><span class="p">]</span>
|
|
|
|
<span class="n">noble_gases</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Helium"</span><span class="p">,</span> <span class="s2">"Neon"</span><span class="p">,</span> <span class="s2">"Argon"</span><span class="p">,</span> <span class="s2">"Krypton"</span><span class="p">,</span> <span class="s2">"Xenon"</span><span class="p">,</span> <span class="s2">"Radon"</span><span class="p">,</span> <span class="s2">"Oganesson"</span><span class="p">]</span>
|
|
|
|
<span class="n">noble_gases</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"Helium"</span><span class="p">,</span> <span class="s2">"Neon"</span><span class="p">,</span> <span class="s2">"Argon"</span><span class="p">,</span> <span class="s2">"Krypton"</span><span class="p">,</span> <span class="s2">"Xenon"</span><span class="p">,</span> <span class="s2">"Radon"</span><span class="p">,</span> <span class="s2">"Oganesson"</span><span class="p">]</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># This initialisation is executed when the program is started</span>
|
|
|
|
<span class="c1"># This initialisation is executed when the program is started</span>
|
|
|
@ -177,8 +197,23 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
<span class="c1"># existence, which will let the network know they are reachable</span>
|
|
|
|
<span class="c1"># existence, which will let the network know they are reachable</span>
|
|
|
|
<span class="c1"># and autoomatically create paths to them, from anywhere else</span>
|
|
|
|
<span class="c1"># and autoomatically create paths to them, from anywhere else</span>
|
|
|
|
<span class="c1"># in the network.</span>
|
|
|
|
<span class="c1"># in the network.</span>
|
|
|
|
<span class="n">destination_1</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"announcesample"</span><span class="p">,</span> <span class="s2">"fruits"</span><span class="p">)</span>
|
|
|
|
<span class="n">destination_1</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
<span class="n">destination_2</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"announcesample"</span><span class="p">,</span> <span class="s2">"noble_gases"</span><span class="p">)</span>
|
|
|
|
<span class="n">identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"announcesample"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"fruits"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">destination_2</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"announcesample"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"noble_gases"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We configure the destinations to automatically prove all</span>
|
|
|
|
<span class="c1"># We configure the destinations to automatically prove all</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
@ -192,7 +227,9 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
<span class="c1"># We create an announce handler and configure it to only ask for</span>
|
|
|
|
<span class="c1"># We create an announce handler and configure it to only ask for</span>
|
|
|
|
<span class="c1"># announces from "example_utilities.announcesample.fruits".</span>
|
|
|
|
<span class="c1"># announces from "example_utilities.announcesample.fruits".</span>
|
|
|
|
<span class="c1"># Try changing the filter and see what happens.</span>
|
|
|
|
<span class="c1"># Try changing the filter and see what happens.</span>
|
|
|
|
<span class="n">announce_handler</span> <span class="o">=</span> <span class="n">ExampleAnnounceHandler</span><span class="p">(</span><span class="n">aspect_filter</span><span class="o">=</span><span class="s2">"example_utilities.announcesample.fruits"</span><span class="p">)</span>
|
|
|
|
<span class="n">announce_handler</span> <span class="o">=</span> <span class="n">ExampleAnnounceHandler</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">aspect_filter</span><span class="o">=</span><span class="s2">"example_utilities.announcesample.fruits"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We register the announce handler with Reticulum</span>
|
|
|
|
<span class="c1"># We register the announce handler with Reticulum</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Transport</span><span class="o">.</span><span class="n">register_announce_handler</span><span class="p">(</span><span class="n">announce_handler</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Transport</span><span class="o">.</span><span class="n">register_announce_handler</span><span class="p">(</span><span class="n">announce_handler</span><span class="p">)</span>
|
|
|
@ -218,14 +255,22 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Send the announce including the app data</span>
|
|
|
|
<span class="c1"># Send the announce including the app data</span>
|
|
|
|
<span class="n">destination_1</span><span class="o">.</span><span class="n">announce</span><span class="p">(</span><span class="n">app_data</span><span class="o">=</span><span class="n">fruit</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">))</span>
|
|
|
|
<span class="n">destination_1</span><span class="o">.</span><span class="n">announce</span><span class="p">(</span><span class="n">app_data</span><span class="o">=</span><span class="n">fruit</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">))</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Sent announce from "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_1</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" ("</span><span class="o">+</span><span class="n">destination_1</span><span class="o">.</span><span class="n">name</span><span class="o">+</span><span class="s2">")"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Sent announce from "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_1</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" ("</span><span class="o">+</span><span class="n">destination_1</span><span class="o">.</span><span class="n">name</span><span class="o">+</span><span class="s2">")"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Randomly select a noble gas</span>
|
|
|
|
<span class="c1"># Randomly select a noble gas</span>
|
|
|
|
<span class="n">noble_gas</span> <span class="o">=</span> <span class="n">noble_gases</span><span class="p">[</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">noble_gases</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">)]</span>
|
|
|
|
<span class="n">noble_gas</span> <span class="o">=</span> <span class="n">noble_gases</span><span class="p">[</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="nb">len</span><span class="p">(</span><span class="n">noble_gases</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span><span class="p">)]</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Send the announce including the app data</span>
|
|
|
|
<span class="c1"># Send the announce including the app data</span>
|
|
|
|
<span class="n">destination_2</span><span class="o">.</span><span class="n">announce</span><span class="p">(</span><span class="n">app_data</span><span class="o">=</span><span class="n">noble_gas</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">))</span>
|
|
|
|
<span class="n">destination_2</span><span class="o">.</span><span class="n">announce</span><span class="p">(</span><span class="n">app_data</span><span class="o">=</span><span class="n">noble_gas</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">))</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Sent announce from "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_2</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" ("</span><span class="o">+</span><span class="n">destination_2</span><span class="o">.</span><span class="n">name</span><span class="o">+</span><span class="s2">")"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Sent announce from "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_2</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" ("</span><span class="o">+</span><span class="n">destination_2</span><span class="o">.</span><span class="n">name</span><span class="o">+</span><span class="s2">")"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We will need to define an announce handler class that</span>
|
|
|
|
<span class="c1"># We will need to define an announce handler class that</span>
|
|
|
|
<span class="c1"># Reticulum can message when an announce arrives.</span>
|
|
|
|
<span class="c1"># Reticulum can message when an announce arrives.</span>
|
|
|
@ -243,8 +288,15 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
<span class="c1"># configured aspect filter. Filters must be specific,</span>
|
|
|
|
<span class="c1"># configured aspect filter. Filters must be specific,</span>
|
|
|
|
<span class="c1"># and cannot use wildcards.</span>
|
|
|
|
<span class="c1"># and cannot use wildcards.</span>
|
|
|
|
<span class="k">def</span> <span class="nf">received_announce</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">destination_hash</span><span class="p">,</span> <span class="n">announced_identity</span><span class="p">,</span> <span class="n">app_data</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">received_announce</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">destination_hash</span><span class="p">,</span> <span class="n">announced_identity</span><span class="p">,</span> <span class="n">app_data</span><span class="p">):</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Received an announce from "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_hash</span><span class="p">))</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"The announce contained the following app data: "</span><span class="o">+</span><span class="n">app_data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">))</span>
|
|
|
|
<span class="s2">"Received an announce from "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination_hash</span><span class="p">)</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"The announce contained the following app data: "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">app_data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">"utf-8"</span><span class="p">)</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1">##########################################################</span>
|
|
|
|
<span class="c1">##########################################################</span>
|
|
|
|
<span class="c1">#### Program Startup #####################################</span>
|
|
|
|
<span class="c1">#### Program Startup #####################################</span>
|
|
|
@ -255,8 +307,18 @@ notifications about announces from relevant destinations.</p>
|
|
|
|
<span class="c1"># the desired program mode.</span>
|
|
|
|
<span class="c1"># the desired program mode.</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Reticulum example that demonstrates announces and announce handlers"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="n">description</span><span class="o">=</span><span class="s2">"Reticulum example that demonstrates announces and announce handlers"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
@ -307,7 +369,14 @@ over the network.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We create a PLAIN destination. This is an uncencrypted endpoint</span>
|
|
|
|
<span class="c1"># We create a PLAIN destination. This is an uncencrypted endpoint</span>
|
|
|
|
<span class="c1"># that anyone can listen to and send information to.</span>
|
|
|
|
<span class="c1"># that anyone can listen to and send information to.</span>
|
|
|
|
<span class="n">broadcast_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">PLAIN</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"broadcast"</span><span class="p">,</span> <span class="n">channel</span><span class="p">)</span>
|
|
|
|
<span class="n">broadcast_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">PLAIN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"broadcast"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">channel</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We specify a callback that will get called every time</span>
|
|
|
|
<span class="c1"># We specify a callback that will get called every time</span>
|
|
|
|
<span class="c1"># the destination receives data.</span>
|
|
|
|
<span class="c1"># the destination receives data.</span>
|
|
|
@ -325,7 +394,11 @@ over the network.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">broadcastLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">broadcastLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Broadcast example "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" running, enter text and hit enter to broadcast (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Broadcast example "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" running, enter text and hit enter to broadcast (Ctrl-C to quit)"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will send the information</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will send the information</span>
|
|
|
@ -350,9 +423,26 @@ over the network.</p>
|
|
|
|
<span class="c1"># the program.</span>
|
|
|
|
<span class="c1"># the program.</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Reticulum example that demonstrates sending and receiving unencrypted broadcasts"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="n">description</span><span class="o">=</span><span class="s2">"Reticulum example demonstrating sending and receiving broadcasts"</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--channel"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"broadcast channel name"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--channel"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"broadcast channel name"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
@ -414,7 +504,14 @@ the Packet interface.</p>
|
|
|
|
<span class="c1"># messages. This way the client can send a request and be</span>
|
|
|
|
<span class="c1"># messages. This way the client can send a request and be</span>
|
|
|
|
<span class="c1"># certain that no-one else than this destination was able</span>
|
|
|
|
<span class="c1"># certain that no-one else than this destination was able</span>
|
|
|
|
<span class="c1"># to read it. </span>
|
|
|
|
<span class="c1"># to read it. </span>
|
|
|
|
<span class="n">echo_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"echo"</span><span class="p">,</span> <span class="s2">"request"</span><span class="p">)</span>
|
|
|
|
<span class="n">echo_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"echo"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"request"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We configure the destination to automatically prove all</span>
|
|
|
|
<span class="c1"># We configure the destination to automatically prove all</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
|
<span class="c1"># packets adressed to it. By doing this, RNS will automatically</span>
|
|
|
@ -434,7 +531,11 @@ the Packet interface.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">announceLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">announceLoop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Echo server "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" running, hit enter to manually send an announce (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Echo server "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" running, hit enter to manually send an announce (Ctrl-C to quit)"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will announce our server</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will announce our server</span>
|
|
|
@ -465,7 +566,10 @@ the Packet interface.</p>
|
|
|
|
<span class="c1"># hash that was entered on the command line</span>
|
|
|
|
<span class="c1"># hash that was entered on the command line</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">destination_hexhash</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">20</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">destination_hexhash</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">20</span><span class="p">:</span>
|
|
|
|
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">"Destination length is invalid, must be 20 hexadecimal characters (10 bytes)"</span><span class="p">)</span>
|
|
|
|
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Destination length is invalid, must be 20 hexadecimal characters (10 bytes)"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">destination_hash</span> <span class="o">=</span> <span class="nb">bytes</span><span class="o">.</span><span class="n">fromhex</span><span class="p">(</span><span class="n">destination_hexhash</span><span class="p">)</span>
|
|
|
|
<span class="n">destination_hash</span> <span class="o">=</span> <span class="nb">bytes</span><span class="o">.</span><span class="n">fromhex</span><span class="p">(</span><span class="n">destination_hexhash</span><span class="p">)</span>
|
|
|
|
<span class="k">except</span><span class="p">:</span>
|
|
|
|
<span class="k">except</span><span class="p">:</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Invalid destination entered. Check your input!</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Invalid destination entered. Check your input!</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
|
|
|
@ -480,7 +584,11 @@ the Packet interface.</p>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">loglevel</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">LOG_INFO</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">loglevel</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">LOG_INFO</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># Tell the user that the client is ready!</span>
|
|
|
|
<span class="c1"># Tell the user that the client is ready!</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Echo client ready, hit enter to send echo request to "</span><span class="o">+</span><span class="n">destination_hexhash</span><span class="o">+</span><span class="s2">" (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Echo client ready, hit enter to send echo request to "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">destination_hexhash</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" (Ctrl-C to quit)"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We enter a loop that runs until the user exits.</span>
|
|
|
|
<span class="c1"># We enter a loop that runs until the user exits.</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will try to send an</span>
|
|
|
|
<span class="c1"># If the user hits enter, we will try to send an</span>
|
|
|
@ -507,7 +615,14 @@ the Packet interface.</p>
|
|
|
|
<span class="c1"># example_utilities.echo.request</span>
|
|
|
|
<span class="c1"># example_utilities.echo.request</span>
|
|
|
|
<span class="c1"># This matches the naming we specified in the</span>
|
|
|
|
<span class="c1"># This matches the naming we specified in the</span>
|
|
|
|
<span class="c1"># server part of the code.</span>
|
|
|
|
<span class="c1"># server part of the code.</span>
|
|
|
|
<span class="n">request_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"echo"</span><span class="p">,</span> <span class="s2">"request"</span><span class="p">)</span>
|
|
|
|
<span class="n">request_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"echo"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"request"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># The destination is ready, so let's create a packet.</span>
|
|
|
|
<span class="c1"># The destination is ready, so let's create a packet.</span>
|
|
|
|
<span class="c1"># We set the destination to the request_destination</span>
|
|
|
|
<span class="c1"># We set the destination to the request_destination</span>
|
|
|
@ -552,7 +667,11 @@ the Packet interface.</p>
|
|
|
|
<span class="n">rtt</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">rtt</span><span class="o">*</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
|
|
|
|
<span class="n">rtt</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span><span class="n">rtt</span><span class="o">*</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
|
|
|
|
<span class="n">rttstring</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">rtt</span><span class="p">)</span><span class="o">+</span><span class="s2">" milliseconds"</span>
|
|
|
|
<span class="n">rttstring</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">rtt</span><span class="p">)</span><span class="o">+</span><span class="s2">" milliseconds"</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Valid reply received from "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">receipt</span><span class="o">.</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">", round-trip time is "</span><span class="o">+</span><span class="n">rttstring</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Valid reply received from "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">receipt</span><span class="o">.</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">", round-trip time is "</span><span class="o">+</span><span class="n">rttstring</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># This function is called if a packet times out.</span>
|
|
|
|
<span class="c1"># This function is called if a packet times out.</span>
|
|
|
|
<span class="k">def</span> <span class="nf">packet_timed_out</span><span class="p">(</span><span class="n">receipt</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">packet_timed_out</span><span class="p">(</span><span class="n">receipt</span><span class="p">):</span>
|
|
|
@ -570,10 +689,39 @@ the Packet interface.</p>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Simple echo server and client utility"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Simple echo server and client utility"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"-s"</span><span class="p">,</span> <span class="s2">"--server"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"wait for incoming packets from clients"</span><span class="p">)</span>
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"-t"</span><span class="p">,</span> <span class="s2">"--timeout"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">"s"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"set a reply timeout in seconds"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">float</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="s2">"-s"</span><span class="p">,</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"destination"</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="s2">"--server"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"wait for incoming packets from clients"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"-t"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"--timeout"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">metavar</span><span class="o">=</span><span class="s2">"s"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"set a reply timeout in seconds"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">float</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">server</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">server</span><span class="p">:</span>
|
|
|
@ -645,7 +793,13 @@ destination, and passing traffic back and forth over the link.</p>
|
|
|
|
<span class="c1"># We create a destination that clients can connect to. We</span>
|
|
|
|
<span class="c1"># We create a destination that clients can connect to. We</span>
|
|
|
|
<span class="c1"># want clients to create links to this destination, so we</span>
|
|
|
|
<span class="c1"># want clients to create links to this destination, so we</span>
|
|
|
|
<span class="c1"># need to create a "single" destination type.</span>
|
|
|
|
<span class="c1"># need to create a "single" destination type.</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"linkexample"</span><span class="p">)</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"linkexample"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We configure a function that will get called every time</span>
|
|
|
|
<span class="c1"># We configure a function that will get called every time</span>
|
|
|
|
<span class="c1"># a new client creates a link to this destination.</span>
|
|
|
|
<span class="c1"># a new client creates a link to this destination.</span>
|
|
|
@ -657,7 +811,12 @@ destination, and passing traffic back and forth over the link.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">def</span> <span class="nf">server_loop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="k">def</span> <span class="nf">server_loop</span><span class="p">(</span><span class="n">destination</span><span class="p">):</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="c1"># Let the user know that everything is ready</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Link example "</span><span class="o">+</span><span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span><span class="s2">" running, waiting for a connection."</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"Link example "</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">prettyhexrep</span><span class="p">(</span><span class="n">destination</span><span class="o">.</span><span class="n">hash</span><span class="p">)</span><span class="o">+</span>
|
|
|
|
|
|
|
|
<span class="s2">" running, waiting for a connection."</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Hit enter to manually send an announce (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Hit enter to manually send an announce (Ctrl-C to quit)"</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
|
<span class="c1"># We enter a loop that runs until the users exits.</span>
|
|
|
@ -735,7 +894,13 @@ destination, and passing traffic back and forth over the link.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># When the server identity is known, we set</span>
|
|
|
|
<span class="c1"># When the server identity is known, we set</span>
|
|
|
|
<span class="c1"># up a destination</span>
|
|
|
|
<span class="c1"># up a destination</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"linkexample"</span><span class="p">)</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"linkexample"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># And create a link</span>
|
|
|
|
<span class="c1"># And create a link</span>
|
|
|
|
<span class="n">link</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Link</span><span class="p">(</span><span class="n">server_destination</span><span class="p">)</span>
|
|
|
|
<span class="n">link</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Link</span><span class="p">(</span><span class="n">server_destination</span><span class="p">)</span>
|
|
|
@ -825,9 +990,30 @@ destination, and passing traffic back and forth over the link.</p>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Simple link example"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Simple link example"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"-s"</span><span class="p">,</span> <span class="s2">"--server"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"wait for incoming link requests from clients"</span><span class="p">)</span>
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"destination"</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="s2">"-s"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"--server"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store_true"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"wait for incoming link requests from clients"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
@ -913,7 +1099,14 @@ interface to efficiently pass files of any size over a Reticulum <a class="refer
|
|
|
|
<span class="c1"># We create a destination that clients can connect to. We</span>
|
|
|
|
<span class="c1"># We create a destination that clients can connect to. We</span>
|
|
|
|
<span class="c1"># want clients to create links to this destination, so we</span>
|
|
|
|
<span class="c1"># want clients to create links to this destination, so we</span>
|
|
|
|
<span class="c1"># need to create a "single" destination type.</span>
|
|
|
|
<span class="c1"># need to create a "single" destination type.</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"filetransfer"</span><span class="p">,</span> <span class="s2">"server"</span><span class="p">)</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">IN</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"filetransfer"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"server"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We configure a function that will get called every time</span>
|
|
|
|
<span class="c1"># We configure a function that will get called every time</span>
|
|
|
|
<span class="c1"># a new client creates a link to this destination.</span>
|
|
|
|
<span class="c1"># a new client creates a link to this destination.</span>
|
|
|
@ -994,7 +1187,13 @@ interface to efficiently pass files of any size over a Reticulum <a class="refer
|
|
|
|
<span class="c1"># read it and pack it as a resource</span>
|
|
|
|
<span class="c1"># read it and pack it as a resource</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Client requested </span><span class="se">\"</span><span class="s2">"</span><span class="o">+</span><span class="n">filename</span><span class="o">+</span><span class="s2">"</span><span class="se">\"</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="s2">"Client requested </span><span class="se">\"</span><span class="s2">"</span><span class="o">+</span><span class="n">filename</span><span class="o">+</span><span class="s2">"</span><span class="se">\"</span><span class="s2">"</span><span class="p">)</span>
|
|
|
|
<span class="n">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">serve_path</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span> <span class="s2">"rb"</span><span class="p">)</span>
|
|
|
|
<span class="n">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">serve_path</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span> <span class="s2">"rb"</span><span class="p">)</span>
|
|
|
|
<span class="n">file_resource</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Resource</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">packet</span><span class="o">.</span><span class="n">link</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">resource_sending_concluded</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">file_resource</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Resource</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">file</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">packet</span><span class="o">.</span><span class="n">link</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">callback</span><span class="o">=</span><span class="n">resource_sending_concluded</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">file_resource</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
|
|
|
|
<span class="n">file_resource</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
|
|
<span class="c1"># If somethign went wrong, we close</span>
|
|
|
|
<span class="c1"># If somethign went wrong, we close</span>
|
|
|
@ -1082,7 +1281,14 @@ interface to efficiently pass files of any size over a Reticulum <a class="refer
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># When the server identity is known, we set</span>
|
|
|
|
<span class="c1"># When the server identity is known, we set</span>
|
|
|
|
<span class="c1"># up a destination</span>
|
|
|
|
<span class="c1"># up a destination</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span><span class="n">server_identity</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span> <span class="n">APP_NAME</span><span class="p">,</span> <span class="s2">"filetransfer"</span><span class="p">,</span> <span class="s2">"server"</span><span class="p">)</span>
|
|
|
|
<span class="n">server_destination</span> <span class="o">=</span> <span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="n">server_identity</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">OUT</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">SINGLE</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">APP_NAME</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"filetransfer"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"server"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="c1"># We also want to automatically prove incoming packets</span>
|
|
|
|
<span class="c1"># We also want to automatically prove incoming packets</span>
|
|
|
|
<span class="n">server_destination</span><span class="o">.</span><span class="n">set_proof_strategy</span><span class="p">(</span><span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">PROVE_ALL</span><span class="p">)</span>
|
|
|
|
<span class="n">server_destination</span><span class="o">.</span><span class="n">set_proof_strategy</span><span class="p">(</span><span class="n">RNS</span><span class="o">.</span><span class="n">Destination</span><span class="o">.</span><span class="n">PROVE_ALL</span><span class="p">)</span>
|
|
|
@ -1383,10 +1589,34 @@ interface to efficiently pass files of any size over a Reticulum <a class="refer
|
|
|
|
<span class="c1"># starts up the desired program mode.</span>
|
|
|
|
<span class="c1"># starts up the desired program mode.</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="k">try</span><span class="p">:</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">"Simple file transfer server and client utility"</span><span class="p">)</span>
|
|
|
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"-s"</span><span class="p">,</span> <span class="s2">"--serve"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">"dir"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"serve a directory of files to clients"</span><span class="p">)</span>
|
|
|
|
<span class="n">description</span><span class="o">=</span><span class="s2">"Simple file transfer server and client utility"</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"--config"</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
<span class="p">)</span>
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">"destination"</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"-s"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="s2">"--serve"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">metavar</span><span class="o">=</span><span class="s2">"dir"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"serve a directory of files to clients"</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"--config"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">action</span><span class="o">=</span><span class="s2">"store"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"path to alternative Reticulum config directory"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
|
|
|
|
|
|
|
|
<span class="s2">"destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">nargs</span><span class="o">=</span><span class="s2">"?"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="n">help</span><span class="o">=</span><span class="s2">"hexadecimal hash of the server destination"</span><span class="p">,</span>
|
|
|
|
|
|
|
|
<span class="nb">type</span><span class="o">=</span><span class="nb">str</span>
|
|
|
|
|
|
|
|
<span class="p">)</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
<span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
|
|
|
|
|
|
|
|
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|
<span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">config</span><span class="p">:</span>
|
|
|
|