|
Time Shield Library
C++ library for working with time
|
Pool of NTP servers: rate-limited multi-server offset estimation. More...
#include <ntp_client_pool.hpp>
Classes | |
| struct | ServerState |
| Runtime state for a configured server. More... | |
Public Member Functions | |
| NtpClientPoolT (NtpPoolConfig cfg={}) | |
| Construct pool with configuration. | |
| NtpClientPoolT (const NtpClientPoolT &)=delete | |
| NtpClientPoolT & | operator= (const NtpClientPoolT &)=delete |
| NtpClientPoolT (NtpClientPoolT &&other) noexcept | |
| Move-construct pool state. | |
| NtpClientPoolT & | operator= (NtpClientPoolT &&other) noexcept |
| Move-assign pool state. | |
| void | set_servers (std::vector< NtpServerConfig > servers) |
| Replace server list (keeps pool config). | |
| void | add_server (NtpServerConfig server_cfg) |
| Add one server. | |
| void | set_default_servers () |
| Replace server list with a conservative default set. | |
| void | clear_servers () |
| Clear server list. | |
| bool | measure () |
| Perform measurement using current config (queries up to sample_servers). | |
| bool | measure_n (std::size_t servers_to_sample) |
| Perform measurement using a custom number of servers. | |
| int64_t | offset_us () const noexcept |
| Last estimated pool offset (µs). | |
| int64_t | utc_time_us () const noexcept |
| Current UTC time in microseconds based on pool offset. | |
| int64_t | utc_time_ms () const noexcept |
| Current UTC time in milliseconds based on pool offset. | |
| int64_t | utc_time_sec () const noexcept |
| Current UTC time in seconds based on pool offset. | |
| std::vector< NtpSample > | last_samples () const |
| Returns last measurement samples (copy). | |
| bool | apply_samples (const std::vector< NtpSample > &samples) |
| Apply pre-collected samples (testing/offline). | |
| NtpPoolConfig | config () const |
| Access config. | |
| void | set_config (NtpPoolConfig cfg) |
| Replace pool configuration. | |
Static Public Member Functions | |
| static std::vector< NtpServerConfig > | build_default_servers () |
| Build a conservative default server list. | |
| static int64_t | median (std::vector< int64_t > &values) |
| Returns median of values. | |
| static int64_t | median_mad_trim (std::vector< int64_t > &offsets) |
| Median with MAD trimming. | |
| static int64_t | best_delay_offset (const std::vector< NtpSample > &samples) |
| Offset from best (lowest) delay sample. | |
Public Attributes | |
| NtpPoolConfig | m_cfg |
| std::mutex | m_mtx |
| std::vector< ServerState > | m_servers |
| std::vector< NtpSample > | m_last_samples |
| std::atomic< int64_t > | m_offset_us |
| std::mt19937_64 | m_rng |
Private Member Functions | |
| std::vector< std::size_t > | pick_servers_locked (std::size_t servers_to_sample) |
| NtpSample | query_one (std::size_t server_index) |
| void | update_server_state_after_query (std::size_t index, const NtpSample &sample) |
| bool | update_from_samples (const std::vector< NtpSample > &samples, const NtpPoolConfig &cfg) |
Static Private Member Functions | |
| static std::uint64_t | init_seed (std::uint64_t seed) |
Pool of NTP servers: rate-limited multi-server offset estimation.
| ClientT | NTP client type with interface: ClientT(const std::string& host, int port); bool query(); // may throw int last_error_code() const; int64_t offset_us() const; int64_t delay_us() const; int stratum() const; |
Definition at line 78 of file ntp_client_pool.hpp.
|
inlineexplicit |
Construct pool with configuration.
| cfg | Pool configuration. |
Definition at line 82 of file ntp_client_pool.hpp.
|
delete |
|
inlinenoexcept |
Move-construct pool state.
Definition at line 91 of file ntp_client_pool.hpp.
|
inline |
Add one server.
| server_cfg | Server configuration to add. |
Definition at line 135 of file ntp_client_pool.hpp.
|
inline |
Apply pre-collected samples (testing/offline).
| samples | Sample list to apply. |
Definition at line 452 of file ntp_client_pool.hpp.
|
inlinestatic |
Offset from best (lowest) delay sample.
| samples | Sample list to scan. |
Definition at line 511 of file ntp_client_pool.hpp.
|
inlinestatic |
Build a conservative default server list.
Definition at line 144 of file ntp_client_pool.hpp.
|
inline |
Clear server list.
Definition at line 384 of file ntp_client_pool.hpp.
|
inline |
Access config.
Definition at line 533 of file ntp_client_pool.hpp.
|
inlinestaticprivate |
Definition at line 570 of file ntp_client_pool.hpp.
|
inline |
Returns last measurement samples (copy).
Definition at line 443 of file ntp_client_pool.hpp.
|
inline |
Perform measurement using current config (queries up to sample_servers).
Definition at line 391 of file ntp_client_pool.hpp.
|
inline |
Perform measurement using a custom number of servers.
| servers_to_sample | Number of servers to query in this measurement. |
Definition at line 399 of file ntp_client_pool.hpp.
|
inlinestatic |
Returns median of values.
| values | Values to process in-place. |
Definition at line 463 of file ntp_client_pool.hpp.
|
inlinestatic |
Median with MAD trimming.
| offsets | Offset list to process in-place. |
Definition at line 479 of file ntp_client_pool.hpp.
|
inlinenoexcept |
Last estimated pool offset (µs).
Definition at line 427 of file ntp_client_pool.hpp.
|
delete |
|
inlinenoexcept |
Move-assign pool state.
Definition at line 104 of file ntp_client_pool.hpp.
|
inlineprivate |
Definition at line 577 of file ntp_client_pool.hpp.
|
inlineprivate |
Definition at line 599 of file ntp_client_pool.hpp.
|
inline |
Replace pool configuration.
| cfg | New pool configuration. |
Definition at line 539 of file ntp_client_pool.hpp.
|
inline |
Replace server list with a conservative default set.
Definition at line 379 of file ntp_client_pool.hpp.
|
inline |
Replace server list (keeps pool config).
| servers | Server configurations to use. |
Definition at line 122 of file ntp_client_pool.hpp.
|
inlineprivate |
Definition at line 666 of file ntp_client_pool.hpp.
|
inlineprivate |
Definition at line 638 of file ntp_client_pool.hpp.
|
inlinenoexcept |
Current UTC time in milliseconds based on pool offset.
Definition at line 435 of file ntp_client_pool.hpp.
|
inlinenoexcept |
Current UTC time in seconds based on pool offset.
Definition at line 439 of file ntp_client_pool.hpp.
|
inlinenoexcept |
Current UTC time in microseconds based on pool offset.
Definition at line 431 of file ntp_client_pool.hpp.
| NtpPoolConfig time_shield::NtpClientPoolT< ClientT >::m_cfg |
Definition at line 559 of file ntp_client_pool.hpp.
| std::vector<NtpSample> time_shield::NtpClientPoolT< ClientT >::m_last_samples |
Definition at line 563 of file ntp_client_pool.hpp.
|
mutable |
Definition at line 561 of file ntp_client_pool.hpp.
| std::atomic<int64_t> time_shield::NtpClientPoolT< ClientT >::m_offset_us |
Definition at line 565 of file ntp_client_pool.hpp.
| std::mt19937_64 time_shield::NtpClientPoolT< ClientT >::m_rng |
Definition at line 567 of file ntp_client_pool.hpp.
| std::vector<ServerState> time_shield::NtpClientPoolT< ClientT >::m_servers |
Definition at line 562 of file ntp_client_pool.hpp.