check_drift() вызывался с сырой разницей часов между узлами, а не с изменением offset со временем. При разнице часов между машинами в 229 секунд это давало спам WARN на каждый TIME_SYNC обмен. Теперь: первый обмен сохраняет offset без проверки; последующие сравнивают дельту и warn только при реальном дрейфе (изменении offset).
37 lines
820 B
C
37 lines
820 B
C
#ifndef NTP_NODE_TIME_H
|
|
#define NTP_NODE_TIME_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct UTUN_INSTANCE;
|
|
|
|
#define NTP_NODE_MAX_PEERS 32
|
|
|
|
#define NTP_NODE_DRIFT_WARN_US 2000000LL // 2 seconds
|
|
#define NTP_NODE_DRIFT_ERROR_US 10000000LL // 10 seconds
|
|
|
|
struct NTP_NODE_PEER {
|
|
uint64_t node_id;
|
|
int64_t offset_us; // my_time_recv - peer_time (positive = my clock ahead)
|
|
int has_offset; // first offset already stored, subsequent deltas are real drift
|
|
};
|
|
|
|
struct NTP_NODE_TIME {
|
|
struct NTP_NODE_PEER peers[NTP_NODE_MAX_PEERS];
|
|
int peer_count;
|
|
};
|
|
|
|
int ntp_node_time_init(struct UTUN_INSTANCE* inst);
|
|
void ntp_node_time_destroy(struct UTUN_INSTANCE* inst);
|
|
void ntp_node_sync_peers(struct UTUN_INSTANCE* inst);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // NTP_NODE_TIME_H
|