Skip to content

Commit

Permalink
sync handling stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Sep 25, 2020
1 parent 0d14ea9 commit 5b8ea48
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion mlat/server/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self, work_dir, partition=(1, 1), tag="mlat", authenticator=None, p
self.authenticator = authenticator
self.partition = partition
self.tag = tag
self.tracker = tracker.Tracker(partition)
self.tracker = tracker.Tracker(self, partition)
self.clock_tracker = clocktrack.ClockTracker(self)
self.mlat_tracker = mlattrack.MlatTracker(self,
blacklist_filename=work_dir + '/blacklist.txt',
Expand Down
30 changes: 16 additions & 14 deletions mlat/server/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ class Tracker(object):
"""Tracks which receivers can see which aircraft, and asks receivers to
forward traffic accordingly."""

def __init__(self, partition):
def __init__(self, coordinator, partition):
self.aircraft = {}
self.partition_id = partition[0] - 1
self.partition_count = partition[1]
self.coordinator = coordinator

def in_local_partition(self, icao):
if self.partition_count == 1:
Expand Down Expand Up @@ -166,7 +167,7 @@ def update_interest(self, receiver):

if receiver.last_rate_report is None:
# Legacy client, no rate report, we cannot be very selective.
new_sync = {ac for ac in receiver.tracking if len(ac.tracking) > 1}
new_sync = {ac for ac in receiver.tracking}
new_mlat = {ac for ac in receiver.tracking if ac.allow_mlat and (len(ac.adsb_seen) < 3 or ac.last_syncpoint_time < now - 300)}
if now - receiver.last_clock_reset < 45:
new_sync = set(receiver.tracking)
Expand All @@ -184,10 +185,11 @@ def update_interest(self, receiver):
ratepair_list = []
rate_report_set = set()
for icao, rate in receiver.last_rate_report.items():
rate_report_set.add(icao)
ac = self.aircraft.get(icao)
if not ac:
continue
self.coordinator.receiver_tracking_add(self.receiver, {int(icao, 16)})

rate_report_set.add(ac)

if rate < 0.25:
continue
Expand Down Expand Up @@ -217,53 +219,53 @@ def update_interest(self, receiver):
ratepair_list.sort()

ntotal = {}
new_sync_set = set()
new_sync = set()
total_rate = 0

# select SYNC aircraft round1
for rp, r1, ac, rate in ratepair_list:
if ac in new_sync_set:
if ac in new_sync:
continue # already added

if total_rate > config.MAX_SYNC_RATE:
break

if ntotal.get(r1, 0.0) < 1.0:
# use this aircraft for sync
new_sync_set.add(ac)
new_sync.add(ac)
total_rate += rate
# update rate-product totals for all receivers that see this aircraft
for rp2, r2, ac2, rate in ac_to_ratepair_map[ac]:
ntotal[r2] = ntotal.get(r2, 0.0) + rp2

# select SYNC aircraft round2 < 2.0 instead of < 1.0 ntotal
for rp, r1, ac, rate in ratepair_list:
if ac in new_sync_set:
if ac in new_sync:
continue # already added

if total_rate > config.MAX_SYNC_RATE:
break

if ntotal.get(r1, 0.0) < 2.5:
# use this aircraft for sync
new_sync_set.add(ac)
new_sync.add(ac)
total_rate += rate
# update rate-product totals for all receivers that see this aircraft
for rp2, r2, ac2, rate in ac_to_ratepair_map[ac]:
ntotal[r2] = ntotal.get(r2, 0.0) + rp2

if now - receiver.last_clock_reset < 45:
new_sync = rate_report_set.union(receiver.tracking)
if now - receiver.last_clock_reset < 45 and len(new_sync) < 10:
new_sync = receiver.tracking

# for multilateration we are interesting in
# all aircraft that we are tracking but for
# which we have no ADS-B rate (i.e. are not
# transmitting positions)
new_mlat_set = set()
new_mlat = set()

for ac in receiver.tracking:
if ac.allow_mlat and (len(ac.adsb_seen) < 3 or ac.last_syncpoint_time < now - 300):
new_mlat_set.add(ac)
new_mlat.add(ac)

receiver.update_interest_sets(new_sync_set, new_mlat_set, new_adsb)
receiver.update_interest_sets(new_sync, new_mlat, new_adsb)
asyncio.get_event_loop().call_soon(receiver.refresh_traffic_requests)

0 comments on commit 5b8ea48

Please sign in to comment.