You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
/* ntp_node_time — обмен временем с прямыми ETCP-пирами, дополнение к интернет-NTP. |
|
* Несинхронизированный узел принимает коррекцию синхронизированного пира с оценкой половины RTT, |
|
* затем передаёт время остальным; при последующих сообщениях сравнивает изменение смещения для диагностики. |
|
* init привязывает ETCP_ID_NTP_TIME и подписку на соединения, destroy удаляет их; все вызовы — uasync. */ |
|
#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
|
|
|