- sock_match: единая классификация сокетов (DIRECT/NAT/LOCAL) и адресов (PUB/PRIV/UNREACH) - eim приравнен к direct; на приватный адрес — только с приватного интерфейса; оба EIM за одним NAT (одинаковый публичный IP) — только через LAN - topo_node: LOCAL-сокеты рекламируются (INTERFACE), private скрыт, NAT-адрес не рекламируется для strict и при оффлайне - ntp: флаг reachable по циклам + пере-анонс nodeinfo при смене доступности - cm_direct_add_links / ncd_create_links / conn_match_candidate_sockets на sock_match - test_sock_match: unit-тесты классификации и сопоставления
49 lines
1.7 KiB
C
49 lines
1.7 KiB
C
#ifndef NTP_TIME_H
|
|
#define NTP_TIME_H
|
|
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
#include "../lib/platform_compat.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
struct UTUN_INSTANCE;
|
|
|
|
#define NTP_DEFAULT_INTERVAL_SEC 3600
|
|
#define NTP_FIRST_SYNC_DELAY_SEC 0
|
|
|
|
struct NTP_TIME {
|
|
int enabled;
|
|
int synced;
|
|
int reachable; // доступность интернет-NTP по циклам (1=есть интернет, 0=нет); для классификации сокетов
|
|
int64_t offset_us; // local_time - ntp_time (positive = local clock ahead)
|
|
uint64_t last_sync_tb; // monotonic time of last successful sync (0.1ms units)
|
|
void* timer; // uasync timer handle
|
|
char **servers; // dynamic array, allocated at init
|
|
int server_count;
|
|
int server_current;
|
|
int resync_interval_sec;
|
|
struct sockaddr_in test_addr; // test mode: direct address when sin_port != 0
|
|
struct sockaddr_in test_dns; // test mode: DNS server for hostname resolution (sin_port != 0)
|
|
uint16_t test_port; // test mode: NTP query port override (0 = 123)
|
|
void* sync; // активный контекст синхронизации (struct ntp_sync*, opaque)
|
|
};
|
|
|
|
int ntp_time_init(struct UTUN_INSTANCE* instance);
|
|
void ntp_time_destroy(struct UTUN_INSTANCE* instance);
|
|
|
|
void ntp_time_set_test_addr(struct NTP_TIME* ntp, const char* ip, uint16_t port);
|
|
void ntp_time_set_test_dns(struct NTP_TIME* ntp, const char* ip, uint16_t dns_port, uint16_t ntp_port);
|
|
|
|
int64_t ntp_time_get_us(struct UTUN_INSTANCE* instance);
|
|
time_t ntp_time_get_seconds(struct UTUN_INSTANCE* instance);
|
|
int ntp_time_is_synced(struct UTUN_INSTANCE* instance);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // NTP_TIME_H
|