English
ntp
The SNTP client of the ntp section: an exchange at start, then once per interval; it keeps the clock offset and, where sing-box does it (Linux, write_to_system), writes the system time. TLS, REALITY and Shadowsocks 2022 read time from ours_clock::Clock, which adds this offset. The offset returns to zero when a reload drops the ntp section and after the system clock has been written. Errors are logged and do not bring down the configuration: an unavailable time server must not get in the proxy's way.
| Crate | ours-mod-ntp, modules/system/ntp |
| Binary feature | ntp |
| Crate features | none |
requires
dial — the query goes through the configuration's dialer (detour, netns, the mark, DNS for the server's address); the DialTable comes from the services.
provides
Provide::Section { key: "ntp" }— the section is enabled by presence, the server is written ashost:port, the dialer — in thedialblock.Provide::Schema { name: "ntp" }.Provide::Unit(Unit)— theNtpcomponent of the current configuration.buildreuses the running one if the plan did not touch it (Ntp::reusable);commitstarts the new one, and the one being replaced works until its successor starts. A failed start does not change the clock.
Syntax: ntp.
Dependencies
ours-ntp-wire (the SNTP packet and the offset computation), ours-clock (the process time), ours-api, ours-bufpool, ours-codec, ours-json, rustix (time, writing the system clock).
Design
src/lib.rs—Ntp(build,reusable,set_dial_table,start,close,clock),MODULE, the unit and parsing the section.src/service.rs— the client itself: a UDP exchange with one server through the dialer, the interval loop.src/options.rs— options and the schema.
Tests
modules/system/ntp/tests/instance.rs — start/stop with the instance, keeping or replacing on reload; unit tests in src/service.rs.