diff --git a/src/ntp_node_time.c b/src/ntp_node_time.c index e22f30b7..771562f7 100644 --- a/src/ntp_node_time.c +++ b/src/ntp_node_time.c @@ -5,6 +5,7 @@ #include "../lib/mem.h" #include "etcp_api.h" #include "etcp.h" +#include "etcp_connections.h" #include #include #include @@ -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); 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.last_sync_tb = get_time_tb();