|
|
|
@ -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(); |
|
|
|
|
|
|
|
|
|
|
|
|