Improve documentation and logging setup
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user