Compare commits

...

10 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire
ea6786d33f
Merge 3eb8d92028 into 4524a17e67 2024-09-07 03:50:38 +02:00
Mark Qvist
4524a17e67 Updated documentation 2024-09-06 19:52:11 +02:00
Mark Qvist
8a82d6bfeb Allow announce handlers to also receive path responses 2024-09-06 19:52:05 +02:00
Mark Qvist
971f5ffadd Check ratchet dir exists before cleaning 2024-09-05 15:58:54 +02:00
Tristan Brice Velloza Kildaire
3eb8d92028 Rename 2024-09-04 23:59:03 +02:00
Tristan Brice Velloza Kildaire
ef3baf2cd9 Add bade
(Will work once active on mark's repo)
2024-09-04 23:58:16 +02:00
Tristan Brice Velloza Kildaire
f2f936d846 Clean up testing 2024-09-04 23:56:55 +02:00
Tristan Brice Velloza Kildaire
6599e210de Fixed up test 2024-09-04 23:56:01 +02:00
Tristan B. Velloza Kildaire
a8bc468e21
Update python-app.yml 2024-09-03 18:53:11 +02:00
Tristan B. Velloza Kildaire
95c4269869
Create python-app.yml 2024-09-03 18:52:10 +02:00
6 changed files with 80 additions and 39 deletions

28
.github/workflows/python-app.yml vendored Normal file
View File

@ -0,0 +1,28 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Test suite
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Test
run: |
make test

View File

@ -1,4 +1,4 @@
Reticulum Network Stack β <img align="right" src="https://static.pepy.tech/personalized-badge/rns?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Installs"/> Reticulum Network Stack β <img align="right" src="https://static.pepy.tech/personalized-badge/rns?period=total&units=international_system&left_color=grey&right_color=blue&left_text=Installs"/> [![Python application](https://github.com/deavmi/markqvist/actions/workflows/python-app.yml/badge.svg)](https://github.com/deavmi/markqvist/actions/workflows/python-app.yml)
========== ==========
<p align="center"><img width="200" src="https://raw.githubusercontent.com/markqvist/Reticulum/master/docs/source/graphics/rns_logo_512.png"></p> <p align="center"><img width="200" src="https://raw.githubusercontent.com/markqvist/Reticulum/master/docs/source/graphics/rns_logo_512.png"></p>

View File

@ -249,7 +249,7 @@ class Identity:
@staticmethod @staticmethod
def _remember_ratchet(destination_hash, ratchet): def _remember_ratchet(destination_hash, ratchet):
# TODO: Remove at some point # TODO: Remove at some point, and only log new ratchets
RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity.truncated_hash(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME) RNS.log(f"Remembering ratchet {RNS.prettyhexrep(Identity.truncated_hash(ratchet))} for {RNS.prettyhexrep(destination_hash)}", RNS.LOG_EXTREME)
try: try:
Identity.known_ratchets[destination_hash] = ratchet Identity.known_ratchets[destination_hash] = ratchet
@ -286,20 +286,21 @@ class Identity:
try: try:
now = time.time() now = time.time()
ratchetdir = RNS.Reticulum.storagepath+"/ratchets" ratchetdir = RNS.Reticulum.storagepath+"/ratchets"
for filename in os.listdir(ratchetdir): if os.path.isdir(ratchetdir):
try: for filename in os.listdir(ratchetdir):
expired = False try:
with open(f"{ratchetdir}/{filename}", "rb") as rf: expired = False
ratchet_data = umsgpack.unpackb(rf.read()) with open(f"{ratchetdir}/{filename}", "rb") as rf:
if now > ratchet_data["received"]+Identity.RATCHET_EXPIRY: ratchet_data = umsgpack.unpackb(rf.read())
expired = True if now > ratchet_data["received"]+Identity.RATCHET_EXPIRY:
expired = True
if expired: if expired:
os.unlink(f"{ratchetdir}/{filename}") os.unlink(f"{ratchetdir}/{filename}")
except Exception as e: except Exception as e:
RNS.log(f"An error occurred while cleaning ratchets, in the processing of {ratchetdir}/{filename}.", RNS.LOG_ERROR) RNS.log(f"An error occurred while cleaning ratchets, in the processing of {ratchetdir}/{filename}.", RNS.LOG_ERROR)
RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR) RNS.log(f"The contained exception was: {e}", RNS.LOG_ERROR)
except Exception as e: except Exception as e:
RNS.log(f"An error occurred while cleaning ratchets. The contained exception was: {e}", RNS.LOG_ERROR) RNS.log(f"An error occurred while cleaning ratchets. The contained exception was: {e}", RNS.LOG_ERROR)

View File

@ -1677,30 +1677,38 @@ class Transport:
# Call externally registered callbacks from apps # Call externally registered callbacks from apps
# wanting to know when an announce arrives # wanting to know when an announce arrives
if packet.context != RNS.Packet.PATH_RESPONSE: for handler in Transport.announce_handlers:
for handler in Transport.announce_handlers: try:
try: # Check that the announced destination matches
# Check that the announced destination matches # the handlers aspect filter
# the handlers aspect filter execute_callback = False
execute_callback = False announce_identity = RNS.Identity.recall(packet.destination_hash)
announce_identity = RNS.Identity.recall(packet.destination_hash) if handler.aspect_filter == None:
if handler.aspect_filter == None: # If the handlers aspect filter is set to
# If the handlers aspect filter is set to # None, we execute the callback in all cases
# None, we execute the callback in all cases execute_callback = True
else:
handler_expected_hash = RNS.Destination.hash_from_name_and_identity(handler.aspect_filter, announce_identity)
if packet.destination_hash == handler_expected_hash:
execute_callback = True execute_callback = True
# If this is a path response, check whether the
# handler wants to receive it.
if packet.context == RNS.Packet.PATH_RESPONSE:
if hasattr(handler, "receive_path_responses") and handler.receive_path_responses == True:
pass
else: else:
handler_expected_hash = RNS.Destination.hash_from_name_and_identity(handler.aspect_filter, announce_identity) execute_callback = False
if packet.destination_hash == handler_expected_hash:
execute_callback = True if execute_callback:
if execute_callback: handler.received_announce(
handler.received_announce( destination_hash=packet.destination_hash,
destination_hash=packet.destination_hash, announced_identity=announce_identity,
announced_identity=announce_identity, app_data=RNS.Identity.recall_app_data(packet.destination_hash)
app_data=RNS.Identity.recall_app_data(packet.destination_hash) )
) except Exception as e:
except Exception as e: RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR)
RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR) RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
# Handling for link requests to local destinations # Handling for link requests to local destinations
elif packet.packet_type == RNS.Packet.LINKREQUEST: elif packet.packet_type == RNS.Packet.LINKREQUEST:
@ -1979,7 +1987,9 @@ class Transport:
""" """
Registers an announce handler. Registers an announce handler.
:param handler: Must be an object with an *aspect_filter* attribute and a *received_announce(destination_hash, announced_identity, app_data)* callable. See the :ref:`Announce Example<example-announce>` for more info. :param handler: Must be an object with an *aspect_filter* attribute and a *received_announce(destination_hash, announced_identity, app_data)*
callable. Can optionally have a *receive_path_responses* attribute set to ``True``, to also receive all path responses, in addition to live
announces. See the :ref:`Announce Example<example-announce>` for more info.
""" """
if hasattr(handler, "received_announce") and callable(handler.received_announce): if hasattr(handler, "received_announce") and callable(handler.received_announce):
if hasattr(handler, "aspect_filter"): if hasattr(handler, "aspect_filter"):

View File

@ -1898,7 +1898,9 @@ Transport system of Reticulum.</p>
<dd><p>Registers an announce handler.</p> <dd><p>Registers an announce handler.</p>
<dl class="field-list simple"> <dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt> <dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>handler</strong> Must be an object with an <em>aspect_filter</em> attribute and a <em>received_announce(destination_hash, announced_identity, app_data)</em> callable. See the <a class="reference internal" href="examples.html#example-announce"><span class="std std-ref">Announce Example</span></a> for more info.</p> <dd class="field-odd"><p><strong>handler</strong> Must be an object with an <em>aspect_filter</em> attribute and a <em>received_announce(destination_hash, announced_identity, app_data)</em>
callable. Can optionally have a <em>receive_path_responses</em> attribute set to <code class="docutils literal notranslate"><span class="pre">True</span></code>, to also receive all path responses, in addition to live
announces. See the <a class="reference internal" href="examples.html#example-announce"><span class="std std-ref">Announce Example</span></a> for more info.</p>
</dd> </dd>
</dl> </dl>
</dd></dl> </dd></dl>

File diff suppressed because one or more lines are too long