Skip to content

Commit

Permalink
Add support for iTAK-specific routing by uid
Browse files Browse the repository at this point in the history
  • Loading branch information
deemoowoor committed May 17, 2024
1 parent 016f2c3 commit 0a97f9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
21 changes: 20 additions & 1 deletion taky/cot/models/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions taky/cot/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import enum
import logging
from pytz import UTC
from datetime import datetime as dt
from datetime import timedelta

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit 0a97f9d

Please sign in to comment.