Merge jayReflector additions: per-trunk filters, node-list, PTY mute
Ports DJ1JAY / FM-Funknetz' jayReflector features (https://github.com/dj1jay/jayReflector) into GeuReflector while keeping the in-process MqttPublisher. Per-trunk config (TrunkLink): BLACKLIST_TGS, ALLOW_TGS, TG_MAP (with explicit-route bypass of the prefix routing check), PEER_ID. New helpers TgFilter.h provide exact / "24*" / "10-20" syntax shared across keys. Wire protocol (additive, backward compatible — older peers ignore unknown types): MsgTrunkNodeList (type 121) carries callsign + current_tg + optional lat/lon/QTH; MsgTrunkFilter (type 122) reserved for satellite TG filters. Reflector emits debounced (500 ms) MsgTrunkNodeList to all trunk peers on local client login/logout/TG change. Inbound lists are republished via MQTT under nodes/<peer_id>; the local list under nodes/local. New MQTT_NAME global key inserts a path component so several reflectors can share a TOPIC_PREFIX. PTY commands (Reflector): TRUNK MUTE|UNMUTE <section> <callsign>, TRUNK RELOAD [<section>] re-reads BLACKLIST_TGS/ALLOW_TGS/TG_MAP without restart, TRUNK STATUS [<section>] dumps a one-line summary per link. Mute is applied on the inbound audio path. Tests: 8 new integration tests (19-27) plus a TEST_PEER_FILTER fixture in topology.py. Tests cover PEER_ID hello, BLACKLIST/ALLOW/TG_MAP semantics, PTY MUTE/RELOAD/STATUS via docker exec, MQTT_NAME topic namespacing, and node-list emission. Total now 27 tests. Docs: docs/JAY-additions.md credits DJ1JAY / FM-Funknetz and lists every merged feature with file pointers and the filter-evaluation order. README.md links it. svxreflector.conf.in documents every new key. Bumps SVXREFLECTOR to 1.3.99.13+trunk.
This commit is contained in:
1 parent
6f5138cd11
commit
5708e2d0e8
17 files changed
+1287
-58
No files matched your search
+31
-1
@@ -16,7 +16,7 @@ bash run_tests.sh
|
||||
This will:
|
||||
1. Generate configs and `docker-compose.test.yml` from `topology.py`
|
||||
2. Build and start the 3-reflector mesh
|
||||
3. Run 17 automated tests
|
||||
3. Run 27 automated tests
|
||||
4. Enter an interactive prompt to manually test any TG number
|
||||
5. Tear down the mesh on exit (or Ctrl-C)
|
||||
|
||||
@@ -126,6 +126,36 @@ Simulates a V2 SvxLink client. Performs the full TCP authentication handshake (P
|
||||
|---|------|-----------------|
|
||||
| 17 | Bidirectional trunk conversation | Client-A on reflector-a talks on a TG owned by reflector-b, Client-B on reflector-b receives it; Client-B replies, Client-A receives the return audio (peer interest tracking) |
|
||||
|
||||
### MQTT Publishing
|
||||
|
||||
| # | Test | What it verifies |
|
||||
|---|------|-----------------|
|
||||
| 18 | MQTT talker event | Talker start/stop on a trunk publishes to `<prefix>/talker/<tg>/(start|stop)` |
|
||||
| 26 | `MQTT_NAME` in topic | Reflector with `MQTT_NAME=mqname-c` publishes node-list under `<prefix>/c/mqname-c/nodes/local` |
|
||||
|
||||
### Per-Trunk Filters and Mapping (jayReflector additions)
|
||||
|
||||
A third test peer `TRUNK_TEST_FILTER` (prefix `7`, secret `test_secret_filter`)
|
||||
is configured with `PEER_ID=filter-peer`, `BLACKLIST_TGS=12345`,
|
||||
`ALLOW_TGS=7*,1220`, and `TG_MAP=7000:1220` so these tests can verify
|
||||
each filter independently of the other trunk fixtures.
|
||||
|
||||
| # | Test | What it verifies |
|
||||
|---|------|-----------------|
|
||||
| 19 | `PEER_ID` in hello | Reflector advertises the configured `PEER_ID` (not the section name) in `MsgTrunkHello` |
|
||||
| 20 | `BLACKLIST_TGS` drops TG | TalkerStart on a blacklisted TG is dropped (not in `/status` active talkers) |
|
||||
| 21 | `ALLOW_TGS` whitelist | TG matching the whitelist passes; TG outside is dropped |
|
||||
| 22 | `TG_MAP` remap | TalkerStart on wire TG `7000` is remapped and tracked as local TG `1220` |
|
||||
| 23 | PTY `TRUNK STATUS` | Command is accepted; `TRUNK_TEST_FILTER` is loaded by the reflector |
|
||||
| 24 | PTY `TRUNK MUTE` | Audio from a muted callsign is dropped before reaching local clients |
|
||||
| 25 | PTY `TRUNK RELOAD` | After live `CFG` update of `BLACKLIST_TGS`, `TRUNK RELOAD` re-reads it and the formerly-allowed TG is now blocked |
|
||||
|
||||
### Trunk Node-List Exchange
|
||||
|
||||
| # | Test | What it verifies |
|
||||
|---|------|-----------------|
|
||||
| 27 | `MsgTrunkNodeList` emission | Connecting a V2 client triggers a debounced node-list send to trunk peers; the harness receives a `MsgTrunkNodeList` (type 121) containing the new client |
|
||||
|
||||
## Interactive Mode
|
||||
|
||||
After the automated tests pass, an interactive prompt lets you test any TG number:
|
||||
|
||||
@@ -73,6 +73,16 @@ def generate_reflector_conf(name: str) -> str:
|
||||
f"SECRET={T.TEST_PEER_RX['secret']}",
|
||||
f"REMOTE_PREFIX={T.prefix_str(T.TEST_PEER_RX['prefix'])}",
|
||||
"",
|
||||
"[TRUNK_TEST_FILTER]",
|
||||
"HOST=192.0.2.1",
|
||||
"PORT=59304",
|
||||
f"SECRET={T.TEST_PEER_FILTER['secret']}",
|
||||
f"REMOTE_PREFIX={T.prefix_str(T.TEST_PEER_FILTER['prefix'])}",
|
||||
f"PEER_ID={T.TEST_PEER_FILTER['peer_id']}",
|
||||
f"BLACKLIST_TGS={T.TEST_PEER_FILTER['blacklist_tgs']}",
|
||||
f"ALLOW_TGS={T.TEST_PEER_FILTER['allow_tgs']}",
|
||||
f"TG_MAP={T.TEST_PEER_FILTER['tg_map']}",
|
||||
"",
|
||||
]
|
||||
|
||||
# Satellite server section (only on the primary reflector)
|
||||
@@ -94,8 +104,10 @@ def generate_reflector_conf(name: str) -> str:
|
||||
f"PASSWORD={T.MQTT['password']}",
|
||||
f"TOPIC_PREFIX=svxreflector/{name}",
|
||||
"STATUS_INTERVAL=1000",
|
||||
"",
|
||||
]
|
||||
if name in T.MQTT_NAMES:
|
||||
lines.append(f"MQTT_NAME={T.MQTT_NAMES[name]}")
|
||||
lines.append("")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import os
|
||||
import re
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@@ -67,6 +68,11 @@ MSG_TRUNK_TALKER_STOP = 117
|
||||
MSG_TRUNK_AUDIO = 118
|
||||
MSG_TRUNK_FLUSH = 119
|
||||
MSG_TRUNK_HEARTBEAT = 120
|
||||
MSG_TRUNK_NODE_LIST = 121
|
||||
|
||||
# Filter test peer constants
|
||||
FILTER_SECRET = T.TEST_PEER_FILTER["secret"]
|
||||
FILTER_PREFIX = T.prefix_str(T.TEST_PEER_FILTER["prefix"])
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Wire format helpers
|
||||
@@ -196,6 +202,32 @@ def parse_msg(data: bytes):
|
||||
return msg_type, {"tg": tg}
|
||||
elif msg_type == MSG_TRUNK_HEARTBEAT:
|
||||
return msg_type, {}
|
||||
elif msg_type == MSG_TRUNK_NODE_LIST:
|
||||
# vec<string> callsigns, vec<u32> tgs, vec<float> lat, vec<float> lon,
|
||||
# vec<string> qth_names. Each vector is u32-prefixed length.
|
||||
def read_vec_str(off):
|
||||
n = struct.unpack_from("!I", data, off)[0]; off += 4
|
||||
out = []
|
||||
for _ in range(n):
|
||||
s, off = unpack_string(data, off)
|
||||
out.append(s)
|
||||
return out, off
|
||||
|
||||
def read_vec_u32(off):
|
||||
n = struct.unpack_from("!I", data, off)[0]; off += 4
|
||||
out = list(struct.unpack_from(f"!{n}I", data, off))
|
||||
off += 4 * n
|
||||
return out, off
|
||||
|
||||
def read_vec_f32(off):
|
||||
n = struct.unpack_from("!I", data, off)[0]; off += 4
|
||||
out = list(struct.unpack_from(f"!{n}f", data, off))
|
||||
off += 4 * n
|
||||
return out, off
|
||||
|
||||
callsigns, off = read_vec_str(off)
|
||||
tgs, off = read_vec_u32(off)
|
||||
return msg_type, {"callsigns": callsigns, "tgs": tgs}
|
||||
else:
|
||||
return msg_type, {"raw": data[off:]}
|
||||
|
||||
@@ -530,6 +562,38 @@ def wait_for_trunk_connected(host: str, port: int, trunk_name: str,
|
||||
msg=f"trunk {trunk_name} on {host}:{port} not connected")
|
||||
|
||||
|
||||
def pty_send(reflector_name: str, command: str, timeout: float = 5.0) -> str:
|
||||
"""Write a line to /dev/shm/reflector_ctrl inside a reflector container
|
||||
and return the captured stdout (the reflector echoes responses there
|
||||
over the next ~200ms — we just confirm the write succeeded)."""
|
||||
svc = T.service_name(reflector_name)
|
||||
# bash here-string ensures a trailing newline (line-buffered PTY)
|
||||
proc = subprocess.run(
|
||||
["docker", "compose", "-f", "docker-compose.test.yml",
|
||||
"exec", "-T", svc,
|
||||
"bash", "-c", f"printf '%s\\n' {repr(command)} > /dev/shm/reflector_ctrl"],
|
||||
cwd=os.path.dirname(os.path.abspath(__file__)),
|
||||
capture_output=True, text=True, timeout=timeout,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError(
|
||||
f"pty_send to {svc} failed: rc={proc.returncode} "
|
||||
f"stderr={proc.stderr.strip()}")
|
||||
return proc.stdout
|
||||
|
||||
|
||||
def docker_logs_since(reflector_name: str, since: str = "5s") -> str:
|
||||
"""Return the stdout/stderr of a reflector container since N seconds ago."""
|
||||
svc = T.service_name(reflector_name)
|
||||
proc = subprocess.run(
|
||||
["docker", "compose", "-f", "docker-compose.test.yml",
|
||||
"logs", "--no-color", "--since", since, svc],
|
||||
cwd=os.path.dirname(os.path.abspath(__file__)),
|
||||
capture_output=True, text=True, timeout=10.0,
|
||||
)
|
||||
return proc.stdout + proc.stderr
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Test cases
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1273,6 +1337,325 @@ class TestTrunkIntegration(unittest.TestCase):
|
||||
mc.loop_stop()
|
||||
mc.disconnect()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 19: PEER_ID is advertised in MsgTrunkHello
|
||||
# ------------------------------------------------------------------
|
||||
def test_19_peer_id_in_hello(self):
|
||||
"""When PEER_ID is configured, the reflector advertises it (not the
|
||||
section name) in its outbound hello on the TRUNK_TEST_FILTER link."""
|
||||
# Listen for an outbound connection on port 59304 — the reflector
|
||||
# is configured to dial 192.0.2.1:59304 which is a black hole, so
|
||||
# we can't capture *that*. Instead we verify the PEER_ID via the
|
||||
# inbound side: we connect to the reflector's trunk port and send
|
||||
# a hello as the FILTER peer; the reflector replies with its hello
|
||||
# using PEER_ID="filter-peer".
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
msg_type, fields = peer.handshake(
|
||||
trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET,
|
||||
)
|
||||
try:
|
||||
self.assertEqual(msg_type, MSG_TRUNK_HELLO)
|
||||
self.assertEqual(fields["id"], T.TEST_PEER_FILTER["peer_id"],
|
||||
f"Expected PEER_ID '{T.TEST_PEER_FILTER['peer_id']}' "
|
||||
f"in reflector's hello, got '{fields['id']}'")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 20: BLACKLIST_TGS drops talker on receive path
|
||||
# ------------------------------------------------------------------
|
||||
def test_20_blacklist_drops_tg(self):
|
||||
"""A TalkerStart on a blacklisted TG must NOT appear as an active
|
||||
talker on the receiving reflector."""
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
peer.handshake(trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET)
|
||||
try:
|
||||
blocked_tg = int(T.TEST_PEER_FILTER["blacklist_tgs"])
|
||||
peer.send_talker_start(blocked_tg, "N0BLACK")
|
||||
time.sleep(1.0)
|
||||
|
||||
status = get_status(*_http(self.PRIMARY))
|
||||
active = status["trunks"].get(
|
||||
"TRUNK_TEST_FILTER", {}).get("active_talkers", {})
|
||||
self.assertNotIn(str(blocked_tg), active,
|
||||
f"Blacklisted TG {blocked_tg} appeared as active talker: "
|
||||
f"{active}")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 21: ALLOW_TGS rejects TGs not in the whitelist
|
||||
# ------------------------------------------------------------------
|
||||
def test_21_allow_tgs_blocks_others(self):
|
||||
"""ALLOW_TGS=7*,1220 — TG 7100 must pass, TG 99 must be dropped."""
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
peer.handshake(trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET)
|
||||
try:
|
||||
allowed_tg = 7100 # matches "7*"
|
||||
peer.send_talker_start(allowed_tg, "N0ALLOW")
|
||||
disallowed_tg = 99 # matches neither "7*" nor "1220"
|
||||
peer.send_talker_start(disallowed_tg, "N0BLOCK")
|
||||
time.sleep(1.0)
|
||||
|
||||
active = get_status(*_http(self.PRIMARY))[
|
||||
"trunks"]["TRUNK_TEST_FILTER"]["active_talkers"]
|
||||
self.assertIn(str(allowed_tg), active,
|
||||
f"Allowed TG {allowed_tg} missing from active talkers: "
|
||||
f"{active}")
|
||||
self.assertNotIn(str(disallowed_tg), active,
|
||||
f"Disallowed TG {disallowed_tg} should not be active: "
|
||||
f"{active}")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 22: TG_MAP remaps incoming TGs
|
||||
# ------------------------------------------------------------------
|
||||
def test_22_tg_map_remap_in(self):
|
||||
"""TG_MAP=7000:1220 — peer sends TalkerStart on wire TG 7000,
|
||||
reflector should track it as local TG 1220."""
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
peer.handshake(trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET)
|
||||
try:
|
||||
wire_tg, local_tg = 7000, 1220
|
||||
peer.send_talker_start(wire_tg, "N0MAP")
|
||||
time.sleep(1.0)
|
||||
|
||||
active = get_status(*_http(self.PRIMARY))[
|
||||
"trunks"]["TRUNK_TEST_FILTER"]["active_talkers"]
|
||||
# After mapping, the reflector tracks the LOCAL TG
|
||||
self.assertIn(str(local_tg), active,
|
||||
f"Mapped local TG {local_tg} not active "
|
||||
f"(after wire TG {wire_tg}): {active}")
|
||||
self.assertNotIn(str(wire_tg), active,
|
||||
f"Wire TG {wire_tg} should have been remapped to "
|
||||
f"{local_tg}: {active}")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 23: PTY TRUNK STATUS lists trunks
|
||||
# ------------------------------------------------------------------
|
||||
def test_23_pty_trunk_status(self):
|
||||
"""`TRUNK STATUS` over PTY enumerates the configured trunks."""
|
||||
# Issue command and read the docker logs for the reflector's PTY
|
||||
# echo (the reflector also writes the response back to the PTY,
|
||||
# which our subprocess can't read — so we check that the command
|
||||
# was accepted via no-error from pty_send).
|
||||
out = pty_send(self.PRIMARY, "TRUNK STATUS")
|
||||
# The actual list goes back to the PTY reader. Best we can do
|
||||
# without a PTY reader is verify the command did not error and
|
||||
# the per-link config was previously logged at startup.
|
||||
logs = docker_logs_since(self.PRIMARY, since="120s")
|
||||
self.assertIn("TRUNK_TEST_FILTER", logs,
|
||||
"TRUNK_TEST_FILTER section was not loaded by reflector "
|
||||
f"(out={out!r}, logs head={logs[:400]!r})")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 24: PTY TRUNK MUTE blocks audio from the muted callsign
|
||||
# ------------------------------------------------------------------
|
||||
def test_24_pty_trunk_mute(self):
|
||||
"""After TRUNK MUTE on a callsign, audio from that callsign on
|
||||
the muted trunk link is dropped (not delivered to local clients)."""
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
peer.handshake(trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET)
|
||||
try:
|
||||
local_tg = 1220 # via TG_MAP from wire 7000
|
||||
wire_tg = 7000
|
||||
|
||||
# Mute first, then claim TG and send audio
|
||||
pty_send(self.PRIMARY,
|
||||
"TRUNK MUTE TRUNK_TEST_FILTER N0MUTE")
|
||||
time.sleep(0.3)
|
||||
|
||||
# Local listener
|
||||
listener = ClientPeer()
|
||||
port = T.mapped_client_port(self.PRIMARY)
|
||||
listener.connect(HOST, port)
|
||||
listener.authenticate(callsign=CLIENT_CALLSIGN,
|
||||
password=CLIENT_PASSWORD)
|
||||
listener.setup_udp(udp_port=port)
|
||||
listener.select_tg(local_tg)
|
||||
time.sleep(0.3)
|
||||
|
||||
peer.send_talker_start(wire_tg, "N0MUTE")
|
||||
for _ in range(5):
|
||||
peer.send_audio(wire_tg, b"\xAA" * 80)
|
||||
time.sleep(0.02)
|
||||
time.sleep(1.0)
|
||||
|
||||
msgs = listener.recv_udp_all(timeout=1.0)
|
||||
audio_count = sum(1 for t, _ in msgs if t == UDP_AUDIO)
|
||||
listener.close()
|
||||
|
||||
# Cleanup mute
|
||||
pty_send(self.PRIMARY,
|
||||
"TRUNK UNMUTE TRUNK_TEST_FILTER N0MUTE")
|
||||
|
||||
self.assertEqual(audio_count, 0,
|
||||
f"Listener received {audio_count} audio frame(s) for "
|
||||
f"muted callsign N0MUTE on TG {local_tg}")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 25: PTY TRUNK RELOAD re-reads BLACKLIST after live CFG update
|
||||
# ------------------------------------------------------------------
|
||||
def test_25_pty_trunk_reload(self):
|
||||
"""CFG-update BLACKLIST_TGS for TRUNK_TEST_FILTER, then TRUNK RELOAD
|
||||
— a TG that was previously allowed must now be blocked."""
|
||||
peer = TrunkPeer()
|
||||
peer.connect(*_trunk(self.PRIMARY))
|
||||
peer.handshake(trunk_id="TRUNK_TEST_FILTER",
|
||||
local_prefix=FILTER_PREFIX,
|
||||
secret=FILTER_SECRET)
|
||||
try:
|
||||
tg_to_block = 7200 # currently allowed by ALLOW_TGS=7*
|
||||
|
||||
# Sanity: it currently goes through
|
||||
peer.send_talker_start(tg_to_block, "N0PRE")
|
||||
time.sleep(0.5)
|
||||
active = get_status(*_http(self.PRIMARY))[
|
||||
"trunks"]["TRUNK_TEST_FILTER"]["active_talkers"]
|
||||
self.assertIn(str(tg_to_block), active,
|
||||
f"Pre-reload: TG {tg_to_block} should be active, got {active}")
|
||||
peer.send_talker_stop(tg_to_block)
|
||||
time.sleep(0.3)
|
||||
|
||||
# Update config + reload
|
||||
pty_send(self.PRIMARY,
|
||||
f"CFG TRUNK_TEST_FILTER BLACKLIST_TGS {tg_to_block}")
|
||||
pty_send(self.PRIMARY, "TRUNK RELOAD TRUNK_TEST_FILTER")
|
||||
time.sleep(0.5)
|
||||
|
||||
# Now it must be blocked
|
||||
peer.send_talker_start(tg_to_block, "N0POST")
|
||||
time.sleep(0.5)
|
||||
active = get_status(*_http(self.PRIMARY))[
|
||||
"trunks"]["TRUNK_TEST_FILTER"]["active_talkers"]
|
||||
self.assertNotIn(str(tg_to_block), active,
|
||||
f"Post-reload: TG {tg_to_block} should be blacklisted, "
|
||||
f"got {active}")
|
||||
|
||||
# Restore original config so other tests aren't affected
|
||||
pty_send(self.PRIMARY,
|
||||
f"CFG TRUNK_TEST_FILTER BLACKLIST_TGS "
|
||||
f"{T.TEST_PEER_FILTER['blacklist_tgs']}")
|
||||
pty_send(self.PRIMARY, "TRUNK RELOAD TRUNK_TEST_FILTER")
|
||||
finally:
|
||||
peer.close()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 26: MQTT_NAME inserts a path component before the topic suffix
|
||||
# ------------------------------------------------------------------
|
||||
def test_26_mqtt_name_in_topic(self):
|
||||
"""Reflector 'c' has MQTT_NAME=mqname-c → topics live under
|
||||
svxreflector/c/mqname-c/... — verify a node-list update arrives
|
||||
on the namespaced 'nodes/local' topic."""
|
||||
received = []
|
||||
connected_event = threading.Event()
|
||||
topic_sub = f"svxreflector/c/{T.MQTT_NAMES['c']}/nodes/local"
|
||||
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
client.subscribe(topic_sub)
|
||||
connected_event.set()
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
received.append((msg.topic, msg.payload.decode()))
|
||||
|
||||
mc = mqtt_client.Client()
|
||||
mc.on_connect = on_connect
|
||||
mc.on_message = on_message
|
||||
mc.connect(HOST, 11883, 60)
|
||||
mc.loop_start()
|
||||
try:
|
||||
self.assertTrue(connected_event.wait(timeout=5),
|
||||
"MQTT subscribe timed out")
|
||||
time.sleep(0.5)
|
||||
|
||||
# Trigger a node-list update by connecting a client to 'c'
|
||||
client = ClientPeer()
|
||||
port = T.mapped_client_port("c")
|
||||
client.connect(HOST, port)
|
||||
client.authenticate(callsign=CLIENT_CALLSIGN,
|
||||
password=CLIENT_PASSWORD)
|
||||
try:
|
||||
# Wait for a retained or fresh message
|
||||
wait_until(lambda: len(received) > 0, timeout=5.0,
|
||||
msg=f"no message on {topic_sub}")
|
||||
topic, payload = received[-1]
|
||||
self.assertEqual(topic, topic_sub)
|
||||
self.assertIn("nodes", payload)
|
||||
finally:
|
||||
client.close()
|
||||
finally:
|
||||
mc.loop_stop()
|
||||
mc.disconnect()
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Test 27: MsgTrunkNodeList is emitted on local client login
|
||||
# ------------------------------------------------------------------
|
||||
def test_27_node_list_emitted_to_trunk_peer(self):
|
||||
"""Connect as the TRUNK_TEST_RX harness, then connect a V2 client
|
||||
on the primary reflector — within the debounce window the harness
|
||||
must receive a MsgTrunkNodeList containing that client."""
|
||||
rx = TrunkPeer()
|
||||
rx.connect(*_trunk(self.PRIMARY))
|
||||
rx.handshake(trunk_id="TRUNK_TEST_RX",
|
||||
local_prefix=TEST_RX_PREFIX,
|
||||
secret=TEST_RX_SECRET)
|
||||
try:
|
||||
# Drain any messages already queued from existing local state
|
||||
rx.sock.settimeout(0.5)
|
||||
try:
|
||||
while True:
|
||||
recv_frame(rx.sock)
|
||||
except (socket.timeout, ConnectionError):
|
||||
pass
|
||||
rx.sock.settimeout(5.0)
|
||||
|
||||
# Trigger: new client connects → debounced node-list emission
|
||||
client = ClientPeer()
|
||||
port = T.mapped_client_port(self.PRIMARY)
|
||||
client.connect(HOST, port)
|
||||
client.authenticate(callsign=CLIENT_CALLSIGN,
|
||||
password=CLIENT_PASSWORD)
|
||||
try:
|
||||
# Wait up to 5s for a NodeList frame containing our callsign
|
||||
deadline = time.monotonic() + 5.0
|
||||
found = False
|
||||
while time.monotonic() < deadline and not found:
|
||||
try:
|
||||
msg_type, fields = rx.recv_msg(timeout=1.0)
|
||||
except socket.timeout:
|
||||
continue
|
||||
if msg_type != MSG_TRUNK_NODE_LIST:
|
||||
continue
|
||||
if CLIENT_CALLSIGN in fields["callsigns"]:
|
||||
found = True
|
||||
self.assertTrue(found,
|
||||
f"No MsgTrunkNodeList containing {CLIENT_CALLSIGN} "
|
||||
f"was received on the trunk")
|
||||
finally:
|
||||
client.close()
|
||||
finally:
|
||||
rx.close()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Custom test runner with clean, readable output
|
||||
|
||||
@@ -29,6 +29,25 @@ TEST_PEER_RX = {
|
||||
"secret": "test_secret_rx",
|
||||
}
|
||||
|
||||
# Third test peer used to exercise per-link BLACKLIST_TGS / ALLOW_TGS /
|
||||
# TG_MAP / PEER_ID. Kept isolated from TEST_PEER so routing tests don't
|
||||
# interact with filter tests.
|
||||
TEST_PEER_FILTER = {
|
||||
"prefix": ["7"],
|
||||
"secret": "test_secret_filter",
|
||||
"peer_id": "filter-peer",
|
||||
"blacklist_tgs": "12345",
|
||||
"allow_tgs": "7*,1220",
|
||||
"tg_map": "7000:1220",
|
||||
}
|
||||
|
||||
# Per-reflector MQTT_NAME overrides — when set, the reflector publishes
|
||||
# under <TOPIC_PREFIX>/<MQTT_NAME>/... so tests can verify the new key
|
||||
# without breaking the flat-topic MQTT test on reflector 'a'.
|
||||
MQTT_NAMES = {
|
||||
"c": "mqname-c",
|
||||
}
|
||||
|
||||
# Cluster TGs — forwarded to all peers regardless of prefix ownership
|
||||
# 8000: no prefix match (not owned by any reflector)
|
||||
# 1201: starts with prefix "120" (overlaps with reflector-a's ownership)
|
||||
|
||||
Reference in new issue
Block a user