lxmf: re-announce when an interface or peer comes online

The startup announce fires before AutoInterface finishes its peering
handshake, so it reaches no peer; a peer discovered later (or a link that
recovers) would otherwise wait out the whole `announce_interval`.

Replace the blocking `_stop.wait(interval)` announce loop with a tick loop
that announces on the interval, and also immediately after an interface scan
sees a new online transition (AutoInterface reports `online` only after its
peering wait, and every discovered peer is a fresh interface). Each announce
records its time and a `reason` (startup / interval / peer discovered) on the
`lxmf_announced` trace event; a scan error is traced, never fatal.
This commit is contained in:
gabby committed 2026-10-17 07:35:12 +00:00
1 parent ec3e6b1b97
commit a6b8617562
2 files changed
+135 -6

No files matched your search

+51
View File
@@ -180,3 +180,54 @@ def test_enqueue_carries_audio_on_the_outbound_queue():
# The stop sentinel is unchanged.
daemon.enqueue(None)
assert daemon._outbound.get_nowait() is None
# ---- interface-transition re-announce ----
def test_announce_records_time_and_reason():
daemon = LxmfDaemon(config_dir="x", storage_path="y")
announced = []
class _Router:
def announce(self, destination_hash):
announced.append(destination_hash)
class _Destination:
hash = b"\x00" * 16
daemon._router = _Router()
daemon._destination = _Destination()
assert daemon._last_announce == 0.0
daemon._announce("startup")
assert announced == [b"\x00" * 16]
assert daemon._last_announce > 0.0
def test_scan_interfaces_flags_only_newly_online(monkeypatch):
import sys
import types
class _Iface:
def __init__(self, name, online):
self._name = name
self.online = online
def __str__(self):
return self._name
a = _Iface("A", False)
b = _Iface("B", True)
fake_rns = types.SimpleNamespace(
Transport=types.SimpleNamespace(interfaces=[a, b])
)
monkeypatch.setitem(sys.modules, "RNS", fake_rns)
daemon = LxmfDaemon(config_dir="x", storage_path="y")
daemon._interface_states = {"A": False, "B": True}
assert daemon._scan_interfaces() is False # steady state: nothing changed
a.online = True
assert daemon._scan_interfaces() is True # A came online
assert daemon._scan_interfaces() is False # now recorded online
fake_rns.Transport.interfaces.append(_Iface("C", True))
assert daemon._scan_interfaces() is True # a fresh peer interface