Browse Source

ntp_node_time: учёт пол-RTT в корректировке времени

offset = t4 - t_sender_us - avg_rtt/2
RTT усредняется по всем линкам соединения (rtt_last в 0.1ms).
topo_upd
Evgeny 2 months ago
parent
commit
333acb2fe5
  1. 5
      src/ntp_node_time.c

5
src/ntp_node_time.c

@ -5,6 +5,7 @@
#include "../lib/mem.h" #include "../lib/mem.h"
#include "etcp_api.h" #include "etcp_api.h"
#include "etcp.h" #include "etcp.h"
#include "etcp_connections.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
@ -148,7 +149,9 @@ static void ntp_node_recv_cb(struct ETCP_CONN* conn, struct ll_entry* entry) {
int was_unsynced = !ntp_time_is_synced(inst); int was_unsynced = !ntp_time_is_synced(inst);
if (was_unsynced && sender_synced) { if (was_unsynced && sender_synced) {
inst->ntp.offset_us = t4 - msg->t_sender_us; int64_t rtt_us = 0, n = 0;
for (struct ETCP_LINK* l = conn->links; l; l = l->next) { rtt_us += l->rtt_last * 100LL; n++; }
inst->ntp.offset_us = t4 - msg->t_sender_us - (n ? rtt_us / n / 2 : 0);
inst->ntp.synced = 1; inst->ntp.synced = 1;
inst->ntp.last_sync_tb = get_time_tb(); inst->ntp.last_sync_tb = get_time_tb();

Loading…
Cancel
Save