def _do_sync(self, address, posA, posB, r0, t0A, t0B, r1, t1A, t1B): # find or create clock pair k = (r0, r1) pairing = self.clock_pairs.get(k) if pairing is None: self.clock_pairs[k] = pairing = clocksync.ClockPairing(r0, r1) # propagation delays, in clock units delay0A = geodesy.ecef_distance( posA, r0.position) * r0.clock.freq / constants.Cair delay0B = geodesy.ecef_distance( posB, r0.position) * r0.clock.freq / constants.Cair delay1A = geodesy.ecef_distance( posA, r1.position) * r1.clock.freq / constants.Cair delay1B = geodesy.ecef_distance( posB, r1.position) * r1.clock.freq / constants.Cair # compute intervals, adjusted for transmitter motion i0 = (t0B - delay0B) - (t0A - delay0A) i1 = (t1B - delay1B) - (t1A - delay1A) if not pairing.is_new(t0B - delay0B): return True # timestamp is in the past or duplicated, don't use this # do the update return pairing.update(address, t0B - delay0B, t1B - delay1B, i0, i1)
def _do_sync(self, address, now, r0, td0B, i0, r1, td1B, i1): # find or create clock pair k = (r0, r1) pairing = self.clock_pairs.get(k) if pairing is None: distance = r0.distance[r1] if distance < 1e3: return False if (r0.sync_peers + r1.sync_peers > 1.5 * config.MAX_PEERS and r0.sync_peers > 10 and r1.sync_peers > 10 and distance > config.MAX_PEERS_MIN_DISTANCE): return False r0.sync_peers += 1 r1.sync_peers += 1 self.clock_pairs[k] = pairing = clocksync.ClockPairing(r0, r1) if pairing.n > 15 and now < pairing.updated + 0.5: return False if not pairing.is_new(td0B): return True # timestamp is in the past or duplicated, don't use this # do the update return pairing.update(address, td0B, td1B, i0, i1, now)
def _do_sync(self, address, now, r0, td0B, i0, r1, td1B, i1): # find or create clock pair k = (r0, r1) pairing = self.clock_pairs.get(k) rejectPairing = False distance = r0.distance[r1] if r0.bad_syncs > 1 or r1.bad_syncs > 1: if r0.sync_peers > 0.5 * config.MIN_PEERS and 0.5 * r1.sync_peers > config.MIN_PEERS: rejectPairing = True if r0.sync_peers > config.MIN_PEERS and r1.sync_peers > config.MIN_PEERS and distance > config.MAX_PEERS_MIN_DISTANCE: if r0.sync_peers > config.MAX_PEERS or r1.sync_peers > config.MAX_PEERS: rejectPairing = True if pairing is None: if rejectPairing: return False r0.sync_peers += 1 r1.sync_peers += 1 self.clock_pairs[k] = pairing = clocksync.ClockPairing(r0, r1) if rejectPairing and r0.sync_peers > 1.25 * config.MIN_PEERS and r1.sync_peers > 1.25 * config.MIN_PEERS: k[0].sync_peers -= 1 k[1].sync_peers -= 1 del self.clock_pairs[k] if pairing.n > 20 and now < pairing.updated + 0.8: return False if not pairing.is_new(td0B): return True # timestamp is in the past or duplicated, don't use this # do the update return pairing.update(address, td0B, td1B, i0, i1, now)