ntp_usg
A Network Time Protocol (NTP) packet parsing and client library written in Rust.
Features
- 🔒 Safe & Secure: Zero unsafe code with
#![forbid(unsafe_code)] - 📚 Well Documented: Comprehensive API documentation with examples
- ⚡ Configurable Timeouts: Control request timeouts for different network conditions
- 🔄 Async Ready: Optional async support via Tokio (
features = ["tokio"]) - 🕐 Y2036 Safe: Era-aware timestamp handling for the NTP 32-bit rollover
- 🌍 Multi-Server Support: Query multiple NTP servers for improved reliability
- 🔐 Network Time Security: NTS (RFC 8915) with TLS 1.3 key establishment and AEAD authentication (
features = ["nts"]) - 📡 Continuous Client: Adaptive poll interval, multi-peer, and interleaved mode (RFC 9769) (
features = ["tokio"]) - 🌐 IPv6 Dual-Stack: Automatic IPv4/IPv6 socket binding
- 🦀 Modern Rust: Edition 2024 with MSRV 1.93
- ✅ Well Tested: CI/CD on Linux, macOS, and Windows
Installation
Add this to your Cargo.toml:
[]
= "1.0"
Minimum Supported Rust Version (MSRV): 1.93 Edition: 2024
Usage
Basic Example
use TimeZone;
Custom Timeout
use Duration;
let response = request_with_timeout?;
Async with Tokio
Enable the tokio feature:
[]
= { = "1.0", = ["tokio"] }
= { = "1", = ["rt-multi-thread", "macros"] }
async
Continuous Client
The continuous client polls servers with adaptive intervals and supports interleaved mode (RFC 9769):
use NtpClient;
async
NTS (Network Time Security)
Enable the nts feature for authenticated NTP:
[]
= { = "1.0", = ["nts"] }
= { = "1", = ["rt-multi-thread", "macros"] }
use NtsSession;
async
NTS Continuous Client
Combine NTS authentication with the continuous polling client:
use NtpClient;
async
Multiple Servers
See examples/multiple_servers.rs for a complete example of querying multiple NTP servers.
Examples
Run the included examples to see the library in action:
# Basic request example
# Custom timeout demonstration
# Query multiple servers
# Detailed packet information
# Async concurrent queries (requires tokio feature)
# Continuous client with poll management (requires tokio feature)
# NTS-authenticated request (requires nts feature)
# NTS continuous client (requires nts feature)
Roadmap
- async support (tokio)
- NTP era handling (Y2036)
- IPv6 dual-stack support
- Continuous client with adaptive polling
- Interleaved mode (RFC 9769)
- Network Time Security (RFC 8915)
- no-std support
- io-independent parsing
- async-std support
- setting system clocks
- NTP server functionality
Contributing
Pull requests and issues are welcome! Please see our GitHub repository for more information.
License
ntp_usg is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.