|
|
|
|
@ -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)
|
|
|
|
|
|