reference: rework adjustment of reference timestamp
Instead of converting the reference timestamp to the NTP format and back, add a negative double value to the timestamp directly. Move the code to a separate function. This will allow the timestamp to stay outside the compiled-in NTP era, which is useful for testing of the cmdmon protocol.
This commit is contained in:
parent
6d1796d6be
commit
9ef7ea2bcb
1 changed files with 13 additions and 6 deletions
19
reference.c
19
reference.c
|
@ -959,6 +959,18 @@ get_clock_estimates(int manual,
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
static void
|
||||||
|
fuzz_ref_time(struct timespec *ts)
|
||||||
|
{
|
||||||
|
uint32_t rnd;
|
||||||
|
|
||||||
|
/* Add a random value from interval [-1.0, 0.0] */
|
||||||
|
UTI_GetRandomBytes(&rnd, sizeof (rnd));
|
||||||
|
UTI_AddDoubleToTimespec(ts, -(double)rnd / (uint32_t)-1, ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
|
REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
|
||||||
uint32_t ref_id, IPAddr *ref_ip, struct timespec *ref_time,
|
uint32_t ref_id, IPAddr *ref_ip, struct timespec *ref_time,
|
||||||
|
@ -970,7 +982,6 @@ REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
|
||||||
double residual_frequency, local_abs_frequency;
|
double residual_frequency, local_abs_frequency;
|
||||||
double elapsed, update_interval, correction_rate, orig_root_distance;
|
double elapsed, update_interval, correction_rate, orig_root_distance;
|
||||||
struct timespec now, raw_now;
|
struct timespec now, raw_now;
|
||||||
NTP_int64 ref_fuzz;
|
|
||||||
int manual;
|
int manual;
|
||||||
|
|
||||||
assert(initialised);
|
assert(initialised);
|
||||||
|
@ -1065,11 +1076,7 @@ REF_SetReference(int stratum, NTP_Leap leap, int combined_sources,
|
||||||
/* Add a random error of up to one second to the reference time to make it
|
/* Add a random error of up to one second to the reference time to make it
|
||||||
less useful when disclosed to NTP and cmdmon clients for estimating
|
less useful when disclosed to NTP and cmdmon clients for estimating
|
||||||
receive timestamps in the interleaved symmetric NTP mode */
|
receive timestamps in the interleaved symmetric NTP mode */
|
||||||
UTI_GetNtp64Fuzz(&ref_fuzz, 0);
|
fuzz_ref_time(&our_ref_time);
|
||||||
UTI_TimespecToNtp64(&our_ref_time, &ref_fuzz, &ref_fuzz);
|
|
||||||
UTI_Ntp64ToTimespec(&ref_fuzz, &our_ref_time);
|
|
||||||
if (UTI_CompareTimespecs(&our_ref_time, ref_time) >= 0)
|
|
||||||
our_ref_time.tv_sec--;
|
|
||||||
|
|
||||||
local_abs_frequency = LCL_ReadAbsoluteFrequency();
|
local_abs_frequency = LCL_ReadAbsoluteFrequency();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue