diff --git a/docs/en/server/protocols/report-v2.md b/docs/en/server/protocols/report-v2.md index 0addf21..7bd7f0b 100644 --- a/docs/en/server/protocols/report-v2.md +++ b/docs/en/server/protocols/report-v2.md @@ -249,7 +249,8 @@ v2 equivalent: "src_id": 3120001, "slot": 2, "dst_id": 52090, - "duration_s": null + "duration_s": null, + "is_announcement": false } ``` @@ -262,6 +263,7 @@ v2 equivalent: | `peer_id`, `src_id`, `dst_id` | int | yes | DMR ids (1–16777215). | | `slot` | int | yes | `1` or `2`. | | `duration_s` | float \| null | no | Set on `END`. | +| `is_announcement` | bool | yes | `true` when the call is the announcement/TTS synthetic PTT, not a real connected peer — the reported `peer_id`/`src_id` must not be attributed to any logged-in bridge. | OpenBridge **INGRESS** vs **START** semantics match [Monitoring and reports](../user-guide/monitoring.md#openbridge-monitor-semantics): use `phase: "INGRESS"` for first sight, `phase: "START"` after loop control. diff --git a/docs/es/server/protocols/report-v2.md b/docs/es/server/protocols/report-v2.md index bd003ae..a234634 100644 --- a/docs/es/server/protocols/report-v2.md +++ b/docs/es/server/protocols/report-v2.md @@ -205,7 +205,8 @@ Equivalente v2: "src_id": 3120001, "slot": 2, "dst_id": 52090, - "duration_s": null + "duration_s": null, + "is_announcement": false } ``` @@ -217,6 +218,7 @@ Equivalente v2: | `stream_id` | int | sí | Stream HBP 32 bits. | | `peer_id`, `src_id`, `dst_id` | int | sí | IDs DMR (1–16777215). | | `slot` | int | sí | `1` o `2`. | +| `is_announcement` | bool | sí | `true` cuando la llamada es el PTT sintético de anuncio/TTS, no un peer real conectado — el `peer_id`/`src_id` reportado no debe atribuirse a ningún bridge logueado. | | `duration_s` | float \| null | no | En eventos `END`. | Semántica OpenBridge INGRESS/START: ver [Monitor e informes](../user-guide/monitoring.md). diff --git a/schemas/examples/voice_event.json b/schemas/examples/voice_event.json index 75931fe..0d4fa89 100644 --- a/schemas/examples/voice_event.json +++ b/schemas/examples/voice_event.json @@ -10,5 +10,6 @@ "src_id": 3120001, "slot": 2, "dst_id": 52090, - "duration_s": null + "duration_s": null, + "is_announcement": false } diff --git a/schemas/report-v2.json b/schemas/report-v2.json index 34e1e4d..ec85403 100644 --- a/schemas/report-v2.json +++ b/schemas/report-v2.json @@ -365,7 +365,8 @@ "peer_id", "src_id", "slot", - "dst_id" + "dst_id", + "is_announcement" ], "properties": { "type": { "const": "voice_event" }, @@ -394,6 +395,10 @@ "type": ["number", "null"], "minimum": 0, "description": "Present on END events." + }, + "is_announcement": { + "type": "boolean", + "description": "True when the call originated from the announcement/TTS synthetic PTT path, not a real connected peer." } } }, diff --git a/src/adn_server/application/report/monitor_topology.py b/src/adn_server/application/report/monitor_topology.py index 590ea8e..f76e6d6 100644 --- a/src/adn_server/application/report/monitor_topology.py +++ b/src/adn_server/application/report/monitor_topology.py @@ -356,6 +356,11 @@ def remap_inject_proxy_voice_events( parts = event.split(",") if len(parts) < 6 or parts[3].strip() != target: return [event] + if len(parts) > 9 and parts[-1].strip() == "1": + # Synthetic announcement PTT: never attribute/fan-out to a real hotspot + # row — a connected peer's radio id may coincidentally match the + # announcement's spoofed rf_src (field 6). + return [event] sys_cfg = systems.get(target, {}) if not isinstance(sys_cfg, dict): return [event] diff --git a/src/adn_server/application/report/payloads.py b/src/adn_server/application/report/payloads.py index 49a0ab1..5611df6 100644 --- a/src/adn_server/application/report/payloads.py +++ b/src/adn_server/application/report/payloads.py @@ -515,6 +515,7 @@ def parse_bridge_event_csv(event: str, *, ts: float | None = None) -> dict[str, voice["duration_s"] = None elif phase != "END": voice["duration_s"] = None + voice["is_announcement"] = len(parts) > 9 and parts[-1] == "1" return voice diff --git a/src/adn_server/application/routing/announcement_ptt_inject.py b/src/adn_server/application/routing/announcement_ptt_inject.py index adfa7ed..2096dc6 100644 --- a/src/adn_server/application/routing/announcement_ptt_inject.py +++ b/src/adn_server/application/routing/announcement_ptt_inject.py @@ -96,4 +96,5 @@ def inject_announcement_ptt( stream_id, pkt, ingress_pkt_time=pkt_time, + synthetic_announcement=True, ) diff --git a/src/adn_server/application/routing/obp_forward.py b/src/adn_server/application/routing/obp_forward.py index 496e1ce..91b6c1b 100644 --- a/src/adn_server/application/routing/obp_forward.py +++ b/src/adn_server/application/routing/obp_forward.py @@ -217,7 +217,7 @@ class ObpForwardMixin: # INGRESS: debug-only (all OBP legs); monitor logs it but does not update OPENBRIDGES chips until START. if _do_report: self._send_routing_event( - "GROUP VOICE,INGRESS,RX,{},{},{},{},{},{}".format( + "GROUP VOICE,INGRESS,RX,{},{},{},{},{},{},0".format( system_name, int_id(stream_id), int_id(peer_id), int_id(rf_src), slot, int_id(dst_id) ) ) diff --git a/src/adn_server/application/routing_use_cases.py b/src/adn_server/application/routing_use_cases.py index a9e2391..ab8d5bc 100644 --- a/src/adn_server/application/routing_use_cases.py +++ b/src/adn_server/application/routing_use_cases.py @@ -174,6 +174,7 @@ class RoutingUseCases( obp_ber: bytes = b"\x00", obp_rssi: bytes = b"\x00", obp_source_rptr: bytes = b"\x00\x00\x00\x00", + synthetic_announcement: bool = False, ) -> bool: """Called by UDP when DMRD is received. Forward to other systems in same bridge (to_target). @@ -182,6 +183,14 @@ class RoutingUseCases( parsing OPENBRIDGE DMRD v1 / DMRE (`hblink.py` ~309–416, ~592–596). When `obp_use_parsed` is True, the OBP path uses those values (1:1 with `bridge.py` `routerOBP.dmrd_received` → `send_system`). HBP sources should pass ``ingress_pkt_time`` from UDP receive (legacy single ``pkt_time`` at router entry). + + ``synthetic_announcement=True`` marks a frame injected by the announcement/TTS + PTT path (`routing/announcement_ptt_inject.py`) rather than a real peer + connection. Its ``peer_id`` is already the global SERVER_ID (never a real + peer — see `_announcement_packet_peer`), so `resolve_voice_peer_id`'s rf_src/ + fuzzy fallback must be skipped: matching the announcement's spoofed rf_src + against a real connected peer's ID would misattribute the call (TX state, + dynamic TG) to that peer. """ if not self._send_to_system: return @@ -294,7 +303,7 @@ class RoutingUseCases( _suppress_uplink_rx = bool(slot_st.get("_suppress_uplink")) if _is_new_rx_stream and not _suppress_uplink_rx: _rx_report_peer = peer_id - if not source_is_obp: + if not source_is_obp and not synthetic_announcement: _rx_report_peer = resolve_voice_peer_id( peer_id, rf_src, @@ -302,13 +311,14 @@ class RoutingUseCases( systems_cfg, ) self._send_routing_event( - "GROUP VOICE,START,RX,{},{},{},{},{},{}".format( + "GROUP VOICE,START,RX,{},{},{},{},{},{},{}".format( system_name, int_id(stream_id), int_id(_rx_report_peer), int_id(rf_src), slot, int_id(dst_id), + int(synthetic_announcement), ) ) elif frame_type == HBPF_DATA_SYNC and dtype_vseq == HBPF_SLT_VTERM: @@ -332,7 +342,7 @@ class RoutingUseCases( self._clear_silent_activation_log(system_name, peer_id, dst_id) if not _suppress_uplink_vterm: _rx_report_peer = peer_id - if not source_is_obp: + if not source_is_obp and not synthetic_announcement: _rx_report_peer = resolve_voice_peer_id( peer_id, rf_src, @@ -340,7 +350,7 @@ class RoutingUseCases( systems_cfg, ) self._send_routing_event( - "GROUP VOICE,END,RX,{},{},{},{},{},{},{:.2f}".format( + "GROUP VOICE,END,RX,{},{},{},{},{},{},{:.2f},{}".format( system_name, int_id(stream_id), int_id(_rx_report_peer), @@ -348,6 +358,7 @@ class RoutingUseCases( slot, int_id(dst_id), duration, + int(synthetic_announcement), ) ) has_source = bool( @@ -467,7 +478,7 @@ class RoutingUseCases( _deduped_legs.append(_leg) forward_legs = tuple(_deduped_legs) _tx_report_peer = int_id(peer_id) - if not source_is_obp: + if not source_is_obp and not synthetic_announcement: _tx_report_peer = int_id( resolve_voice_peer_id(peer_id, rf_src, system_name, systems_cfg) ) @@ -576,8 +587,8 @@ class RoutingUseCases( system_name, _relay_table_key, entry["SYSTEM"], entry.get("TS", 1), int_id(target_tgid), ) self._send_routing_event( - "GROUP VOICE,START,TX,{},{},{},{},{},{}".format( - entry["SYSTEM"], int_id(stream_id), _tx_report_peer, int_id(rf_src), entry.get("TS", 1), int_id(target_tgid) + "GROUP VOICE,START,TX,{},{},{},{},{},{},{}".format( + entry["SYSTEM"], int_id(stream_id), _tx_report_peer, int_id(rf_src), entry.get("TS", 1), int_id(target_tgid), int(synthetic_announcement) ) ) if "EMB_LC" not in _target_status[stream_id]: @@ -613,8 +624,8 @@ class RoutingUseCases( self._clear_talker_alias_embed(_target_status[stream_id]) call_duration = pkt_time - _target_status[stream_id].get("START", pkt_time) self._send_routing_event( - "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f}".format( - entry["SYSTEM"], int_id(stream_id), _tx_report_peer, int_id(rf_src), entry.get("TS", 1), int_id(target_tgid), call_duration + "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f},{}".format( + entry["SYSTEM"], int_id(stream_id), _tx_report_peer, int_id(rf_src), entry.get("TS", 1), int_id(target_tgid), call_duration, int(synthetic_announcement) ) ) elif dtype_vseq in (1, 2, 3, 4): @@ -695,14 +706,14 @@ class RoutingUseCases( call_duration = pkt_time - _ts_st.get("TX_START", pkt_time) _end_peer = _ts_st.get("TX_PEER", peer_id) _end_report_peer = int_id(_end_peer) - if not source_is_obp: + if not source_is_obp and not synthetic_announcement: _end_report_peer = int_id( resolve_voice_peer_id( _end_peer, rf_src, system_name, systems_cfg ) ) self._send_routing_event( - "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f}".format( + "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f},{}".format( entry["SYSTEM"], int_id(stream_id), _end_report_peer, @@ -710,6 +721,7 @@ class RoutingUseCases( entry_ts, int_id(entry_tgid_b), call_duration, + int(synthetic_announcement), ) ) if not _obp_deferred_bridge: @@ -812,13 +824,14 @@ class RoutingUseCases( system_name, _relay_table_key, entry["SYSTEM"], entry_ts, int_id(entry_tgid_b), ) self._send_routing_event( - "GROUP VOICE,START,TX,{},{},{},{},{},{}".format( + "GROUP VOICE,START,TX,{},{},{},{},{},{},{}".format( entry["SYSTEM"], int_id(stream_id), _tx_report_peer, int_id(rf_src), entry_ts, int_id(entry_tgid_b), + int(synthetic_announcement), ) ) if _obp_deferred_bridge and _bridge_tx_leg is not None: @@ -850,14 +863,14 @@ class RoutingUseCases( call_duration = pkt_time - _ts_st.get("TX_START", pkt_time) _end_peer = _ts_st.get("TX_PEER", peer_id) _end_report_peer = int_id(_end_peer) - if not source_is_obp: + if not source_is_obp and not synthetic_announcement: _end_report_peer = int_id( resolve_voice_peer_id( _end_peer, rf_src, system_name, systems_cfg ) ) self._send_routing_event( - "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f}".format( + "GROUP VOICE,END,TX,{},{},{},{},{},{},{:.2f},{}".format( entry["SYSTEM"], int_id(stream_id), _end_report_peer, @@ -865,6 +878,7 @@ class RoutingUseCases( entry_ts, int_id(entry_tgid_b), call_duration, + int(synthetic_announcement), ) ) if not _obp_deferred_bridge: @@ -926,7 +940,7 @@ class RoutingUseCases( loss_pct, ) self._send_routing_event( - "GROUP VOICE,END,RX,{},{},{},{},{},{},{:.2f}".format( + "GROUP VOICE,END,RX,{},{},{},{},{},{},{:.2f},{}".format( system_name, int_id(stream_id), int_id(peer_id), @@ -934,6 +948,7 @@ class RoutingUseCases( slot, int_id(dst_id), call_duration, + int(synthetic_announcement), ) ) ost["_fin"] = True diff --git a/src/adn_server/application/voice_use_cases.py b/src/adn_server/application/voice_use_cases.py index ca82b9d..04b7c34 100644 --- a/src/adn_server/application/voice_use_cases.py +++ b/src/adn_server/application/voice_use_cases.py @@ -301,6 +301,7 @@ class VoiceUseCases: ] if duration is not None: parts.append(f"{duration:.2f}") + parts.append("1") self._send_routing_event(",".join(parts)) def _maybe_begin_legacy_voice_report( diff --git a/tests/application/test_monitor_topology.py b/tests/application/test_monitor_topology.py index f703f26..9dc696f 100644 --- a/tests/application/test_monitor_topology.py +++ b/tests/application/test_monitor_topology.py @@ -229,6 +229,22 @@ def test_local_hotspot_rx_fans_out_tx_only_to_peers_with_matching_tg() -> None: assert "SYSTEM-4" not in by_system +def test_remap_inject_proxy_skips_announcement_even_if_rf_src_matches_peer() -> None: + """Announcement rf_src (field 6) coincidentally matching a real connected peer's + + login id must not be attributed/remapped to that peer's SYSTEM-N row — the + trailing ``is_announcement=1`` field short-circuits the fuzzy peer match in + ``_peer_key_from_voice_csv``. + """ + real_peer = bytes_4(1000001) + peers = {real_peer: _peer()} + config = _proxy_config(peers) + peer_slots = {real_peer: 1} + raw = "GROUP VOICE,START,RX,SYSTEM,3262598598,9990001,1000001,2,91,1" + events = remap_inject_proxy_voice_events(raw, config, config["SYSTEMS"], peer_slots) + assert events == [raw] + + def test_obp_tx_single_hotspot_remaps_dynamic_tg_not_in_static() -> None: """One HS online: downlink/monitor must remap TX even when TG is UA-only (not in OPTIONS).""" peer = bytes_4(730039101) diff --git a/tests/routing/test_announcement_ptt_inject.py b/tests/routing/test_announcement_ptt_inject.py index d81b037..826c148 100644 --- a/tests/routing/test_announcement_ptt_inject.py +++ b/tests/routing/test_announcement_ptt_inject.py @@ -30,7 +30,7 @@ from adn_server.application.routing.announcement_ptt_inject import ( inject_announcement_ptt, ) from adn_server.application.server_voice import DEFAULT_SERVER_VOICE_ID -from adn_server.domain import bytes_4 +from adn_server.domain import bytes_4, int_id def test_announcement_ptt_system_prefers_proxy_target() -> None: @@ -75,3 +75,57 @@ def test_inject_forwards_to_obp_and_peer_master() -> None: ) is True assert len(scenario.capture.for_system("OBP-CL")) == 3 assert len(scenario.capture.for_system("MASTER-A")) == 0 + + +def test_inject_does_not_attribute_call_to_real_peer_matching_rf_src() -> None: + """An announcement whose rf_src (e.g. 1000001) matches a real connected peer's + + login id must never be reported as that peer's call: no RX/TX attribution, + no dynamic TG learned for it. Regression for the misattribution bug where + ``resolve_voice_peer_id``'s rf_src fallback fired for synthetic frames. + """ + scenario = obp_bridge_scenario("OBP-CL", tg=91) + scenario.config["PROXY"] = {"TARGET_SYSTEM": "MASTER-A"} + real_peer_id = DEFAULT_SERVER_VOICE_ID + scenario.config["SYSTEMS"]["MASTER-A"]["PEERS"] = { + bytes_4(real_peer_id): {"CONNECTION": "YES", "OPTIONS": b"TS2=91;"}, + } + server_id = scenario.config["GLOBAL"]["SERVER_ID"] + sid = server_id if isinstance(server_id, bytes) else bytes_4(int(server_id)) + events: list[str] = [] + scenario.routing._send_routing_event = events.append # type: ignore[method-assign] + base = PacketSpec( + peer_id=int_id(sid), + rf_src=real_peer_id, + dst_id=91, + slot=2, + stream_id=0xB0B0B0B0, + ) + with patch_routing_wall_time(scenario.clock): + vhead = DeterministicScenario.voice_head_spec(base) + inject_announcement_ptt( + scenario.routing, + "MASTER-A", + vhead.data(), + pkt_time=scenario.clock.time(), + server_id=sid, + ) + for seq in range(1, 3): + spec = DeterministicScenario.voice_burst_spec(base, seq=seq, dtype_vseq=min(seq, 4)) + inject_announcement_ptt( + scenario.routing, + "MASTER-A", + spec.data(), + pkt_time=scenario.clock.time(), + server_id=sid, + ) + + assert events, "expected at least one GROUP VOICE report" + rx_events = [e for e in events if e.startswith("GROUP VOICE,START,RX,") or e.startswith("GROUP VOICE,END,RX,")] + assert rx_events, "expected an RX report for the MASTER-A inject" + for event in rx_events: + fields = event.split(",") + reported_peer = int(fields[5]) + assert reported_peer != real_peer_id + assert reported_peer == int_id(sid) + assert fields[-1] == "1"