Network Time Synchronization
As Demos network is strongly based on correct communication between nodes, the protocol’s way to synchronize timestamps and to have a reliable network timestamp is crucial. ThecalibrateTime.ts library provides essential functionality for time synchronization and correction in the Demos network. Here’s an overview of its key components and functions:
NTP Server Configuration
The library defines a primary NTP (Network Time Protocol) server and a list of fallback servers to ensure reliable time synchronization.Time Calibration:
The main function getTimestampCorrection() calculates the time difference between the local system and the NTP server, storing this correction in shared state.Network Timestamp Retrieval
The getNetworkTimestamp() function provides a corrected network timestamp by applying the stored correction to the current local time.Time Delta Calculation
The getMeasuredTimeDelta() function performs the actual time synchronization by:- Fetching the NTP time
- Calculating the round-trip time
- Adjusting for network latency
- Computing the difference between the adjusted NTP time and local time