twekkel / htpdate

HTTP Time protocol
https://www.vervest.org/htp
Other
50 stars 13 forks source link

Time being corrected to half the offset #25

Closed gfcittolin closed 2 years ago

gfcittolin commented 2 years ago

Hello again!

I've noted that the time is being corrected to half the measured offset from the servers. For example, if server time is now 10:00:00, and computer's time is 08:00:00 (wrong by -2h), after adjustment, the time is set to 09:00:00.

In my scenario, the clock can be very wrong due to RTC failure, years behind actually, and setting the clock to half the way still yields a perceptibly wrong clock, albeit less wrong :)

I think the expected behavior could be, in this example, to set the clock to 10:00:00, but by inspecting the git history, I can see this change was explicitly introduced by c92a3a25b08559abcf09ac209550e4cd31a8ae99. Is there any reason for this I couldn't foresee?

Sorry for bothering once again, and thank you for the excellent work!

twekkel commented 2 years ago

Ouch, that is a bug... the '/2' was introduced for the situation when htpdate enters maximum precision and without it the time bounces constantly between lower/upper limits... drift calculations go wrong... but in initial time setting this should not be the case.

Can you please try this branch? Not the most elegant solution.

gfcittolin commented 2 years ago

This looks very good to me. Although I wasn't able to simulate many cases of timeavg < 1, for the ones I've tested I couldn't reproduce any of the problems you've mentioned. For timeavg >= 1, time was always corrected successfully within the precision aimed with htpdate. For me, good to go!

twekkel commented 2 years ago

Made the fix and released version 1.3.6. For the moment I dropped "tuning with /2" completely in all cases.

Thanks for reporting this bug!

gfcittolin commented 2 years ago

Thanks for the quick reaction!