Midnight Sun Firmware
|
Class that represents the netowrk-time-protocol server that synchronizes clients. More...
#include <ntp_server.h>
Public Member Functions | |
NTPServer () | |
Constructs a NTPServer object. More... | |
void | NTPServerProcedure () |
Thread procedure for handling NTP synchronization. More... | |
void | startListening (const std::string &bindAddress, const std::string &NTPServerAddress) |
Starts listening to NTP clients to begin synchronization. More... | |
Private Member Functions | |
NTPPacket | processNTPRequest (const NTPPacket &request) |
Processes an incoming NTP request and returns the response packet. More... | |
bool | queryNTPServer (NTPPacket &response) |
Queries the remote NTP server and fills the response packet. More... | |
Private Attributes | |
int | m_NTPSocket |
std::string | m_bindAddress |
std::string | m_NTPServerAddress |
pthread_t | m_NTPServerThreadId |
std::atomic< bool > | m_isListening |
Static Private Attributes | |
static constexpr int | NTP_PORT = 123 |
static constexpr unsigned int | NTP_SYNC_PERIOD_S = 60U |
Class that represents the netowrk-time-protocol server that synchronizes clients.
This class is responsible for fetching stratum 0/1 time and forwarding it to clients The server shall account for timing errors/differences The client shall be responsibile for adjusting their timing
NTPServer | ( | ) |
Constructs a NTPServer object.
Initializes the NTP server. The constructor sets up internal variables
void NTPServerProcedure | ( | ) |
Thread procedure for handling NTP synchronization.
This thread shall run at the NTP_SYNC_PERIOD_S frequency
Processes an incoming NTP request and returns the response packet.
This shall create a stratum 2 time image If the NTP server query is succesful, the times shall be updated
request | The incoming NTP request packet |
|
private |
Queries the remote NTP server and fills the response packet.
This shall fetch stratum 0/1 timing data The response from the server will contain the most accurate time information
response | The NTP response packet that will be filled with data from the server |
void startListening | ( | const std::string & | bindAddress, |
const std::string & | NTPServerAddress | ||
) |
Starts listening to NTP clients to begin synchronization.
This function will spawn the NTPServerProcedure thread
bindAddress | The local address to bind the NTP server |
NTPServerAddress | The external NTP server address to query for time data |
|
private |
The NTP servers bind address
|
private |
Boolean flag to indicate the NTP servers status
|
private |
The NTP servers address for fetching stratum 0/1 data (ie: time.google.com)
|
private |
Thread Id for synchronizing clients
|
private |
The NTP servers socket FD
|
staticconstexprprivate |
Universal port for network-time-protocol
|
staticconstexprprivate |
Client synchronization period