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

offset = t4 - t_sender_us - avg_rtt/2
RTT усредняется по всем линкам соединения (rtt_last в 0.1ms).
This commit is contained in:
Evgeny committed 2026-07-20 01:19:33 +03:00
1 parent f83efda54e
commit 333acb2fe5
1 file changed
+4 -1
+4 -1
View File
@@ -5,6 +5,7 @@
#include "../lib/mem.h"
#include "etcp_api.h"
#include "etcp.h"
#include "etcp_connections.h"
#include <string.h>
#include <stdlib.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);
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();