Files
utun2/src/ntp_time.h
T
Evgeny e31cd141a4 dns: async_dns модуль (libdns) + неблокирующий NTP sync
- Вендор libdns (MIT) как lib/dns.{c,h}; правка dns_quietinit для GCC 5+
- Новый lib/async_dns.{c,h}: неблокирующий A-резолвер поверх uasync
- src/ntp_time.c: убраны блокирующие getaddrinfo+select; async DNS + неблокирующая машина состояний UDP-запроса
- test_async_dns.c (юнит) + test_ntp.c сценарий hostname→DNS
- сборка: -DDNS_RANDOM=RAND_bytes, -lcrypto в COMMON_LIBS
2026-08-16 12:10:33 +03:00

48 lines
1.5 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;
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