From 2d6e2b5232c10a2ecd3cdd8d61aefc7fdb229366 Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 22 Nov 2026 18:41:59 +0000 Subject: [PATCH] Grant gateway SMS on idle personal hotspot matches --- bridge_master.py | 65 +++++++++++++++++--------------- docs/release-notes-unreleased.md | 5 +++ docs/unit-data-hold.md | 9 +++-- tests/test_gateway_admission.py | 33 ++++++++++++++++ 4 files changed, 79 insertions(+), 33 deletions(-) diff --git a/bridge_master.py b/bridge_master.py index 7b70f80..a064ba4 100644 --- a/bridge_master.py +++ b/bridge_master.py @@ -1967,42 +1967,47 @@ class routerOBP(OPENBRIDGE): allowed = allowed and acl_check(source_id, policy['SUB_ACL']) and acl_check(destination_id, policy['TG1_ACL']) if allowed: target = subMapTarget(destination_id) - if not target: - # Match the existing hotspot-ID fallback, but never reserve ambiguously. - matches = [(name, 2, now) for name, config in CONFIG['SYSTEMS'].items() + if target: + targets = [target] + else: + targets = [(name, 2, now) for name, config in CONFIG['SYSTEMS'].items() if config['MODE'] == 'MASTER' and config['ENABLED'] and any(str(int_id(peer))[:7] == str(int_id(destination_id))[:7] for peer in config['PEERS'])] - target = matches[0] if len(matches) == 1 else None - if not target: - result = 2 - else: - system, slot, _ = target - config = CONFIG['SYSTEMS'][system] - status = systems[system].STATUS.get(slot) if config['MODE'] == 'MASTER' else None - if status is None or not config['ENABLED'] or not config['PEERS']: - result = 2 - elif not config.get('UNIT_DATA_HOLD', True): - result = 3 - elif (status['RX_TYPE'] != HBPF_SLT_VTERM or status['TX_TYPE'] != HBPF_SLT_VTERM - or now - status['TX_TIME'] <= config['GROUP_HANGTIME'] - or status.get('TX_PROMPT_ACTIVE', False)): - result = 1 - else: - hold = unitDataHold(system, status, now) - if hold is not None: - if (hold[:2] == (source_id, destination_id) - and status.get('TX_UNIT_DATA_LINK') == self._system): - result, deadline = 0, min(now + .5, hold[2]) - else: - result = 1 - else: - result, deadline = 0, now + .5 - status['TX_UNIT_DATA_HOLD'] = (source_id, destination_id, deadline) - status['TX_UNIT_DATA_LINK'] = self._system + # IP access (5005) still requires a single identifiable access peer. + if int_id(source_id) == 5005 and len(targets) != 1: + targets = [] + result = 2 + for system, slot, _ in targets: + decision, expiry = self._reserve_gateway_target(system, slot, source_id, destination_id, now) + if decision == 0: + # One reply covers every reserved target, not beyond its earliest expiry. + deadline = min(deadline, expiry) if result == 0 else expiry + result = 0 + elif result != 0 and (decision == 1 or result == 2): + result = decision cache[request_id] = (source_id, destination_id, result, deadline, now + 30) return result, max(0, min(500, int(round((deadline - now) * 1000)))) if result == 0 else 0 + def _reserve_gateway_target(self, system, slot, source_id, destination_id, now): + config = CONFIG['SYSTEMS'][system] + status = systems[system].STATUS.get(slot) if config['MODE'] == 'MASTER' else None + if status is None or not config['ENABLED'] or not config['PEERS']: + return 2, now + if not config.get('UNIT_DATA_HOLD', True): + return 3, now + if (status['RX_TYPE'] != HBPF_SLT_VTERM or status['TX_TYPE'] != HBPF_SLT_VTERM + or now - status['TX_TIME'] <= config['GROUP_HANGTIME'] or status.get('TX_PROMPT_ACTIVE', False)): + return 1, now + hold = unitDataHold(system, status, now) + if hold is not None: + if hold[:2] == (source_id, destination_id) and status.get('TX_UNIT_DATA_LINK') == self._system: + return 0, min(now + .5, hold[2]) + return 1, now + deadline = now + .5 + status['TX_UNIT_DATA_HOLD'] = (source_id, destination_id, deadline) + status['TX_UNIT_DATA_LINK'] = self._system + return 0, deadline def __init__(self, _name, _config, _report): OPENBRIDGE.__init__(self, _name, _config, _report) diff --git a/docs/release-notes-unreleased.md b/docs/release-notes-unreleased.md index a44c371..3472a88 100644 --- a/docs/release-notes-unreleased.md +++ b/docs/release-notes-unreleased.md @@ -1,5 +1,10 @@ # Unreleased Changes +- Gateway SMS admission now grants when at least one matching personal hotspot + is idle, even if several SSIDs are connected to one worker. A connected + subscriber-map target still takes precedence, including when it is busy. + Ordinary forwarding, mesh containment and IP-service admission are unchanged. + - The CI release helper upgrades GitLab's advertised HTTP API URL to HTTPS before sending its job token. Redirects remain errors and are not followed. This fixes release-page creation behind the HTTPS redirect without changing diff --git a/docs/unit-data-hold.md b/docs/unit-data-hold.md index 7d8ec7c..753a23e 100644 --- a/docs/unit-data-hold.md +++ b/docs/unit-data-hold.md @@ -42,9 +42,12 @@ provisional hold using `BCRQ`; `BCTS` replies with granted, busy, no local route or denied. Ordinary mesh relationships cannot request holds. The new controls use a 16-byte keyed BLAKE2b tag; existing FBCP controls are unchanged. -The worker resolves the local destination through its subscriber map or an -unambiguous connected-hotspot match. A grant reserves that slot for 500ms for -the requesting relationship and ordered source/destination pair. The first +The worker uses the connected subscriber-map target first, even if it is busy. +Without a mapped target, an SMS request reserves each idle, eligible personal +hotspot system whose peer ID starts with the subscriber's seven digits. One +grant covers those systems; a busy match does not hide an idle one. IP service +5005 still requires an unambiguous fallback. A grant reserves a slot for up to +500ms for the requesting relationship and ordered source/destination pair. The first matching admitted burst promotes it to the five-second hold above. With no packet, it expires automatically. Existing voice/hangtime and prompt checks still apply, and `UNIT_DATA_HOLD: False` denies requests for that master. diff --git a/tests/test_gateway_admission.py b/tests/test_gateway_admission.py index c99a019..384395d 100644 --- a/tests/test_gateway_admission.py +++ b/tests/test_gateway_admission.py @@ -128,6 +128,39 @@ class GatewayAdmissionTests(unittest.TestCase): self.assertFalse(s.transports[system].writes) self.assertNotIn('TX_UNIT_DATA_HOLD', s.systems['MASTER-B'].STATUS[2]) + def test_sms_personal_hotspot_fallback_reserves_each_idle_match(self): + for busy in ((), ('MASTER-A',), ('MASTER-B',), ('MASTER-A', 'MASTER-B')): + with self.subTest(busy=busy), self.scenario() as s: + s.clock.advance(10) + for name, peer in (('MASTER-A', 234269010), ('MASTER-B', 234269011)): + s.register_peer(name, peer) + if name in busy: + s.systems[name].STATUS[2]['RX_TYPE'] = 1 + grant = self.request(s, source=2341, destination=2342690) + self.assertEqual(grant, (1, 0) if len(busy) == 2 else (0, 500)) + for name in ('MASTER-A', 'MASTER-B'): + self.assertEqual('TX_UNIT_DATA_HOLD' in s.systems[name].STATUS[2], name not in busy) + s.clock.advance(.25) + self.assertEqual(self.request(s, source=2341, destination=2342690), + (1, 0) if len(busy) == 2 else (0, 250)) + + def test_mapped_repeater_precedes_idle_personal_hotspot(self): + with self.scenario() as s: + s.clock.advance(10) + access = s.register_peer('MASTER-A', 234001) + s.register_peer('MASTER-B', 234269010) + s.bm.SUB_MAP[bytes_3(2342690)] = (access, 1, s.clock.time()) + s.systems['MASTER-A'].STATUS[1]['RX_TYPE'] = 1 + self.assertEqual(self.request(s, source=2341, destination=2342690), (1, 0)) + self.assertNotIn('TX_UNIT_DATA_HOLD', s.systems['MASTER-B'].STATUS[2]) + + def test_ip_still_requires_unambiguous_hotspot_fallback(self): + with self.scenario() as s: + s.clock.advance(10) + s.register_peer('MASTER-A', 234269010) + s.register_peer('MASTER-B', 234269011) + self.assertEqual(self.request(s, source=5005, destination=2342690), (2, 0)) + def test_cache_is_bounded_and_ages_out(self): with self.scenario() as s: self.prepare(s)