From 0a97f9dcff51cefbfd0ad252e6c7ed6ecf0a5dcd Mon Sep 17 00:00:00 2001 From: Andrei Sosnin Date: Fri, 17 May 2024 08:39:44 +0300 Subject: [PATCH] Add support for iTAK-specific routing by uid --- taky/cot/models/detail.py | 21 ++++++++++++++++++++- taky/cot/router.py | 10 ++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/taky/cot/models/detail.py b/taky/cot/models/detail.py index e809298..ee221af 100644 --- a/taky/cot/models/detail.py +++ b/taky/cot/models/detail.py @@ -46,7 +46,26 @@ def marti_cs(self): return for dest in marti.iterfind("dest"): - yield dest.get("callsign") + if dest.get("callsign") is not None: + yield dest.get("callsign") + + @property + def marti_uid(self): + """ + A list of UIDs in the Marti tag (if present) + + Returns an empty list if not present + """ + if self.elm is None: + return + + marti = self.elm.find("marti") + if marti is None: + return + + for dest in marti.iterfind("dest"): + if dest.get("uid") is not None: + yield dest.get("uid") @property def as_element(self): diff --git a/taky/cot/router.py b/taky/cot/router.py index e597400..285be90 100644 --- a/taky/cot/router.py +++ b/taky/cot/router.py @@ -2,6 +2,7 @@ import time import enum import logging +from pytz import UTC from datetime import datetime as dt from datetime import timedelta @@ -126,6 +127,7 @@ def send_user(self, src, msg, dst_cs=None, dst_uid=None): Send a message to a destination by callsign or UID """ for client in self.find_clients(uid=dst_uid, callsign=dst_cs): + self.lgr.debug("%s -> %s: %s", src.user, client.user, msg) client.send_event(msg) def route(self, src, evt): @@ -138,7 +140,7 @@ def route(self, src, evt): # If configured, constrain events to a max TTL if self.max_ttl >= 0: if evt.persist_ttl > self.max_ttl: - evt.stale = dt.utcnow() + timedelta(seconds=self.max_ttl) + evt.stale = dt.now(UTC) + timedelta(seconds=self.max_ttl) # Special handling for chat messages if isinstance(evt.detail, models.GeoChat): @@ -153,9 +155,13 @@ def route(self, src, evt): # Check for Marti, use first if evt.detail and evt.detail.has_marti: - self.lgr.debug("Handling marti") + self.lgr.debug("Handling marti: %s %s", + [callsign for callsign in evt.detail.marti_cs], [uid for uid in evt.detail.marti_uid]) for callsign in evt.detail.marti_cs: self.send_user(src, evt, dst_cs=callsign) + + for uid in evt.detail.marti_uid: + self.send_user(src, evt, dst_uid=uid) return # Assume broadcast