Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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