55#ifndef __N_CLOCK_SYNC_HEADER
56#define __N_CLOCK_SYNC_HEADER
70#ifndef N_CLOCK_SYNC_SAMPLE_COUNT
71#define N_CLOCK_SYNC_SAMPLE_COUNT 11
75#ifndef N_CLOCK_SYNC_INTERVAL
76#define N_CLOCK_SYNC_INTERVAL 3.0
82#ifndef N_CLOCK_SYNC_BURST_INTERVAL
83#define N_CLOCK_SYNC_BURST_INTERVAL 0.5
87#ifndef N_CLOCK_SYNC_BURST_SAMPLES
88#define N_CLOCK_SYNC_BURST_SAMPLES 5
93#ifndef N_CLOCK_SYNC_MAX_RTT
94#define N_CLOCK_SYNC_MAX_RTT 10.0
100#ifndef N_CLOCK_SYNC_SLEW_SECONDS
101#define N_CLOCK_SYNC_SLEW_SECONDS 1.0
int sample_index
current write position in circular buffer
double last_sync_time
local time of last sync request sent
double estimated_offset
add to local time to get estimated server time (raw best-RTT target — n_clock_sync_server_time applie...
double estimated_rtt
current estimated round-trip time
double offset_change_time
local time at which estimated_offset last changed
int synthetic
TRUE while the buffer holds only a synthetic n_clock_sync_seed sample — flushed wholesale by the firs...
int sample_count
number of samples collected so far
double offset_prev
effective offset at the moment estimated_offset last changed — the slew blends offset_prev → estimate...
double rtt_samples[11]
circular buffer of RTT values
double offset_samples[11]
circular buffer of offset estimates
#define N_CLOCK_SYNC_SAMPLE_COUNT
number of samples for the median filter
N_CLOCK_SYNC * n_clock_sync_new(void)
allocate and initialize a new clock sync estimator
int n_clock_sync_should_send(const N_CLOCK_SYNC *cs, double local_now)
check if it's time to send a new sync request (returns TRUE/FALSE).
double n_clock_sync_server_time(const N_CLOCK_SYNC *cs, double local_now)
get estimated server time given a local time value.
void n_clock_sync_seed(N_CLOCK_SYNC *cs, double offset, double rtt)
Inject a synthetic (offset, rtt) sample, e.g.
void n_clock_sync_delete(N_CLOCK_SYNC **cs)
free a clock sync estimator
void n_clock_sync_mark_sent(N_CLOCK_SYNC *cs, double local_now)
mark that a sync request was just sent
int n_clock_sync_process_response(N_CLOCK_SYNC *cs, double client_send_time, double server_time, double local_now)
record a sync response: client_send_time is the local time the request was sent, server_time is the s...
clock synchronization estimator
Common headers and low-level functions & define.