Midnight Sun Firmware
Loading...
Searching...
No Matches
ntp_server.h
1#pragma once
2
3/************************************************************************************************
4 * @file ntp_server.h
5 *
6 * @brief Header file defining the NTPServer class
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <atomic>
14#include <chrono>
15#include <ctime>
16#include <string>
17
18/* Inter-component Headers */
19#include <arpa/inet.h>
20#include <pthread.h>
21#include <sys/socket.h>
22#include <unistd.h>
23
24#include "network_time_protocol.h"
25
26/* Intra-component Headers */
27
41class NTPServer {
42 private:
43 static constexpr int NTP_PORT = 123;
44 static constexpr unsigned int NTP_SYNC_PERIOD_S = 60U;
47 std::string m_bindAddress;
48 std::string m_NTPServerAddress;
50 std::atomic<bool> m_isListening;
60
68 bool queryNTPServer(NTPPacket &response);
69
70 public:
75 NTPServer();
76
81 void NTPServerProcedure();
82
89 void startListening(const std::string &bindAddress, const std::string &NTPServerAddress);
90};
91
Class that represents the netowrk-time-protocol server that synchronizes clients.
Definition: ntp_server.h:41
NTPServer()
Constructs a NTPServer object.
Definition: ntp_server.cc:194
void startListening(const std::string &bindAddress, const std::string &NTPServerAddress)
Starts listening to NTP clients to begin synchronization.
Definition: ntp_server.cc:183
static constexpr int NTP_PORT
Definition: ntp_server.h:43
std::string m_NTPServerAddress
Definition: ntp_server.h:48
static constexpr unsigned int NTP_SYNC_PERIOD_S
Definition: ntp_server.h:44
bool queryNTPServer(NTPPacket &response)
Queries the remote NTP server and fills the response packet.
Definition: ntp_server.cc:20
void NTPServerProcedure()
Thread procedure for handling NTP synchronization.
Definition: ntp_server.cc:121
std::atomic< bool > m_isListening
Definition: ntp_server.h:50
int m_NTPSocket
Definition: ntp_server.h:46
std::string m_bindAddress
Definition: ntp_server.h:47
pthread_t m_NTPServerThreadId
Definition: ntp_server.h:49
NTPPacket processNTPRequest(const NTPPacket &request)
Processes an incoming NTP request and returns the response packet.
Definition: ntp_server.cc:81
Structure representing an NTP packet.
Definition: network_time_protocol.h:68