Dynamic ntp time source selection in timestamp_mw#364
Conversation
- NodeInfo storage using std::unordered_map - Implemented best neighbor selection algorithm - Unit tests for discovery manager
- configuration manager - integration with controller - unit tests
| @@ -0,0 +1,5 @@ | |||
| { | |||
| "ip": "192.168.10.51", | |||
| "ntp_class": 3, | |||
There was a problem hiding this comment.
| "ntp_class": 3, | |
| "ntp_class": 4, |
|
|
||
| auto raw_json = parser.GetObject(); | ||
|
|
||
| if (raw_json.contains("ntp_class") && raw_json["ntp_class"].is_number_integer()) { |
There was a problem hiding this comment.
| if (raw_json.contains("ntp_class") && raw_json["ntp_class"].is_number_integer()) { | |
| auto ntp_class = raw_json.GetNumer<uint8_t>("ntp_class"); | |
| config.ntp_class = ntp_class.value_or(kDefault_device_class); |
tak samo dla reszty (do definiowania defaultowych wartosci użyj namespace {static constexpr auto kDefault_device_class = 7;}
| namespace srp { | ||
| namespace tinyNTP { | ||
|
|
||
| constexpr const char* CONFIG_FILEPATH = "/srp/opt/cpu_srp/ntp_config.json"; |
There was a problem hiding this comment.
| constexpr const char* CONFIG_FILEPATH = "/srp/opt/cpu_srp/ntp_config.json"; | |
| namespace { | |
| static constexpr auto kConfig_file_path = "/srp/opt/cpu_srp/ntp_config.json"; | |
| } |
There was a problem hiding this comment.
cpplint rzuca błąd za nienazwany namespace w .hpp
|
|
||
| std::optional<std::string> readMyIP(); | ||
| std::vector<uint8_t> socket_callback(const std::string& ip, const std::uint16_t& port, | ||
| const std::vector<std::uint8_t> payload); |
There was a problem hiding this comment.
| const std::vector<std::uint8_t> payload); | |
| const std::vector<std::uint8_t>& payload); |
| int64_t CalculateOffset(const int64_t T0, const int64_t T1, const int64_t T2, const int64_t T3); | ||
| uint64_t CalculateRoundTripDelay(const int64_t T0, const int64_t T1, const int64_t T2, const int64_t T3); |
There was a problem hiding this comment.
| int64_t CalculateOffset(const int64_t T0, const int64_t T1, const int64_t T2, const int64_t T3); | |
| uint64_t CalculateRoundTripDelay(const int64_t T0, const int64_t T1, const int64_t T2, const int64_t T3); | |
| int64_t CalculateOffset(const int64_t& T0, const int64_t& T1, const int64_t& T2, const int64_t& T3); | |
| uint64_t CalculateRoundTripDelay(const int64_t& T0, const int64_t& T1, const int64_t& T2, const int64_t& T3); |
| void DiscoveryManager::UpdateNode(const std::string& ip, uint8_t ntp_class, bool holdover) { | ||
| std::lock_guard<std::mutex> lock(map_mutex_); | ||
|
|
||
| NodeInfo& node = neighbors_[ip]; |
There was a problem hiding this comment.
pootencjalny segmentation fault?
There was a problem hiding this comment.
neighbors_ to std::unordered_map<std::string, NodeInfo>, więc raczej nie. Tu co najwyżej pytanie, czy nie zmienić tego na zwykły vector?
There was a problem hiding this comment.
bardzo dobrze że jest to unordered map, ale jeśli w neightbors_ nie będzie ip do którego się odwołujesz dostaniesz Segmentation Fault, użyj np find.
cytując https://www.geeksforgeeks.org/cpp/unordered_map-in-cpp-stl/
#include <bits/stdc++.h>
using namespace std;
int main() {
unordered_map<int, string> um =
{{1, "Geeks"}, {2, "For"}, {3, "C++"}};
// Finding element with key 2
auto it = um.find(2);
if (it != um.end())
cout << it->first << ": " << it->second;
else cout << "Not Found";
return 0;
}
- Initialization of udp and udp multicast sockets - Connecting to mechanism of chosing best neighbor
- Resolving conversations - Fixing code to pass cpplint tests - Fixing code to pass unit tests
- separate callback functions for socket - safety checks for invalid message types and rapid change of function between server and client mode - header setting encoding test
No description provided.