Midnight Sun Firmware
Loading...
Searching...
No Matches
NTPServer

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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ NTPServer()

NTPServer ( )

Constructs a NTPServer object.

Initializes the NTP server. The constructor sets up internal variables

Member Function Documentation

◆ NTPServerProcedure()

void NTPServerProcedure ( )

Thread procedure for handling NTP synchronization.

This thread shall run at the NTP_SYNC_PERIOD_S frequency

◆ processNTPRequest()

NTPPacket processNTPRequest ( const NTPPacket request)
private

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

Parameters
requestThe incoming NTP request packet
Returns
The NTP response packet

◆ queryNTPServer()

bool queryNTPServer ( NTPPacket response)
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

Parameters
responseThe NTP response packet that will be filled with data from the server
Returns
True if the query was successful, otherwise false

◆ startListening()

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

Parameters
bindAddressThe local address to bind the NTP server
NTPServerAddressThe external NTP server address to query for time data

Member Data Documentation

◆ m_bindAddress

std::string m_bindAddress
private

The NTP servers bind address

◆ m_isListening

std::atomic<bool> m_isListening
private

Boolean flag to indicate the NTP servers status

◆ m_NTPServerAddress

std::string m_NTPServerAddress
private

The NTP servers address for fetching stratum 0/1 data (ie: time.google.com)

◆ m_NTPServerThreadId

pthread_t m_NTPServerThreadId
private

Thread Id for synchronizing clients

◆ m_NTPSocket

int m_NTPSocket
private

The NTP servers socket FD

◆ NTP_PORT

constexpr int NTP_PORT = 123
staticconstexprprivate

Universal port for network-time-protocol

◆ NTP_SYNC_PERIOD_S

constexpr unsigned int NTP_SYNC_PERIOD_S = 60U
staticconstexprprivate

Client synchronization period


The documentation for this class was generated from the following files: