From 5123dd3d1a12a73250892e98d71929eb3f755659 Mon Sep 17 00:00:00 2001 From: Joaquin Madrid Belando Date: Sat, 7 Mar 2026 21:20:01 +0100 Subject: [PATCH] Filter announcements by TG: only send to peers active on matching talkgroup --- bridge_master.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 0bae01d..9602c67 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -978,6 +978,24 @@ def _saveRecording(): _recording_state['frames'] = 0 _recording_state['rf_src'] = None +def _sendFilteredByTG(_sys_obj, pkt, _tg, _ts, _label, _pkt_idx): + _tg_bytes = bytes_3(_tg) if isinstance(_tg, int) else _tg + if hasattr(_sys_obj, '_peer_tg') and hasattr(_sys_obj, '_peers'): + _sent_count = 0 + for _peer in list(_sys_obj._peers.keys()): + _send = False + if _peer in _sys_obj._peer_tg: + if _ts in _sys_obj._peer_tg[_peer]: + if _sys_obj._peer_tg[_peer][_ts]['tgid'] == _tg_bytes: + _send = True + if _send: + _sys_obj.send_peer(_peer, pkt) + _sent_count += 1 + return _sent_count + else: + _sys_obj.send_system(pkt) + return -1 + def _announcementSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, _ann_num=1, _next_time=None): global _announcement_running @@ -1015,7 +1033,9 @@ def _announcementSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _ else: _sys_obj.STATUS[_stream_id]['LAST'] = _now _slot['TX_TIME'] = _now - _sys_obj.send_system(pkt) + _fc = _sendFilteredByTG(_sys_obj, pkt, _tg, _ts, _label, _pkt_idx) + if _pkt_idx == 0 and _fc >= 0: + logger.info('(%s) TG filter: %s/%s peers match TG %s TS%s on %s', _label, _fc, len(_sys_obj._peers), _tg, _ts, _t['name']) except Exception as e: logger.error('(%s) Error sending packet %s to %s: %s', _label, _pkt_idx, _t['name'], e) @@ -1350,7 +1370,9 @@ def _ttsSendBroadcast(_targets, _pkts, _pkt_idx, _source_id, _dst_id, _tg, _ts, else: _sys_obj.STATUS[_stream_id]['LAST'] = _now _slot['TX_TIME'] = _now - _sys_obj.send_system(pkt) + _fc = _sendFilteredByTG(_sys_obj, pkt, _tg, _ts, _label, _pkt_idx) + if _pkt_idx == 0 and _fc >= 0: + logger.info('(%s) TG filter: %s/%s peers match TG %s TS%s on %s', _label, _fc, len(_sys_obj._peers), _tg, _ts, _t['name']) except Exception as e: logger.error('(%s) Error sending packet %s to %s: %s', _label, _pkt_idx, _t['name'], e) @@ -2300,6 +2322,7 @@ class routerHBP(HBSYSTEM): } } self.CALL_DATA = [] + self._peer_tg = {} def to_target(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _frame_type, _dtype_vseq, _stream_id, _data, pkt_time, dmrpkt, _bits,_bridge,_system,_noOBP,sysIgnore,_source_server, _ber, _rssi, _source_rptr): _sysIgnore = sysIgnore @@ -2998,6 +3021,11 @@ class routerHBP(HBSYSTEM): self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot) if CONFIG['REPORTS']['REPORT']: self._report.send_bridgeEvent('GROUP VOICE,START,RX,{},{},{},{},{},{}'.format(self._system, int_id(_stream_id), int_id(_peer_id), int_id(_rf_src), _slot, int_id(_dst_id)).encode(encoding='utf-8', errors='ignore')) + + if _peer_id not in self._peer_tg: + self._peer_tg[_peer_id] = {} + self._peer_tg[_peer_id][_slot] = {'tgid': _dst_id, 'time': pkt_time} + else: logger.info('(%s) *VCSBK* STREAM ID: %s SUB: %s (%s) PEER: %s (%s) TGID %s (%s), TS %s _dtype_vseq: %s', self._system, int_id(_stream_id), get_alias(_rf_src, subscriber_ids), int_id(_rf_src), get_alias(_peer_id, peer_ids), int_id(_peer_id), get_alias(_dst_id, talkgroup_ids), int_id(_dst_id), _slot, _dtype_vseq)