Basic Timesync - etemu/satar GitHub Wiki

  • Node 1 and Node 2 send keepalive/status packets to the Server (containing their local timestamp)
    most likely both packets are not sent at the same time, so the trip delay of both will not vary too much

  • when the server receives one of this packets it calculates the difference between the received time
    so we can assume a time ($server_time+$node_diff) + $ping for every node.

We don't know the variable $ping but it should only vary in an acceptable range (a few ms)

Using advanced mathematical methods we now can do this:

($server_time+$node1_offset) + $ping1 = ($server_time+$node2_offset) + $ping2 + $node12_diff <=> $node12_diff = ($server_time + $node1_offset) + $ping1 - ($server_time+$node2_offset) - $ping2

assuming $ping1 = $ping1 we get the term:
$node12_diff = $node1_offset - $node2_offset
which we can now add to a riders time from node1 to node2 to get an quite accurate result and because the keepalive packets are sent every t=60s or less the maximum age for one set of timediffs is 2t or 120s while it adapts to the network conditions. (+ some algorithm to filter out peaks and packetloss) To create redundancy we could send our set of timediffs to the SatarServer or even back to the node.