From 8ac3364420dde47bf8508df788415d711564e7d5 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 20 Sep 2025 13:55:18 -0500 Subject: [PATCH] Improve documentation and logging setup --- ren_browser/announces/announces.py | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ren_browser/announces/announces.py b/ren_browser/announces/announces.py index cca24bf..e626cc9 100644 --- a/ren_browser/announces/announces.py +++ b/ren_browser/announces/announces.py @@ -1,35 +1,63 @@ -import pathlib +"""Reticulum network announce handling for Ren Browser. + +This module provides services for listening to and collecting network +announces from the Reticulum network. +""" import time from dataclasses import dataclass import RNS +from ren_browser.storage.storage import get_rns_config_directory + @dataclass class Announce: + """Represents a Reticulum network announce. + + Contains destination hash, display name, and timestamp. + """ + destination_hash: str display_name: str | None timestamp: int class AnnounceService: """Service to listen for Reticulum announces and collect them. + Calls update_callback whenever a new announce is received. """ def __init__(self, update_callback): + """Initialize the announce service. + + Args: + update_callback: Function called when new announces are received. + + """ self.aspect_filter = "nomadnetwork.node" self.receive_path_responses = True self.announces: list[Announce] = [] self.update_callback = update_callback - config_dir = pathlib.Path(__file__).resolve().parents[2] / "config" + config_dir = get_rns_config_directory() try: RNS.Reticulum(str(config_dir)) + from ren_browser.logs import setup_rns_logging + setup_rns_logging() except (OSError, ValueError): pass RNS.Transport.register_announce_handler(self) RNS.log("AnnounceService: registered announce handler") def received_announce(self, destination_hash, announced_identity, app_data): + """Handle received announce from Reticulum network. + + Args: + destination_hash: Hash of the announcing destination. + announced_identity: Identity of the announcer. + app_data: Optional application data from the announce. + + """ RNS.log(f"AnnounceService: received announce from {destination_hash.hex()}") ts = int(time.time()) display_name = None