From 3335f7be392db6b18e331ce1fa355161d1119289 Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Fri, 7 Jun 2024 16:57:28 -0400 Subject: [PATCH] add support to reload TG and RID lists via REST API for the FNE; --- src/common/lookups/LookupTable.h | 7 ++++ src/common/lookups/TalkgroupRulesLookup.h | 3 ++ src/fne/network/FNENetwork.cpp | 7 ++++ src/fne/network/FNENetwork.h | 2 + src/fne/network/RESTAPI.cpp | 51 ++++++++++++++++++++++- src/fne/network/RESTAPI.h | 5 +++ src/fne/network/RESTDefines.h | 3 ++ src/remote/RESTClientMain.cpp | 10 +++++ 8 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/common/lookups/LookupTable.h b/src/common/lookups/LookupTable.h index 59903283..58e0e97f 100644 --- a/src/common/lookups/LookupTable.h +++ b/src/common/lookups/LookupTable.h @@ -96,6 +96,13 @@ namespace lookups return ret; } + /// Reads the lookup table from the specified lookup table file. + /// True, if lookup table was read, otherwise false. + virtual bool reload() + { + return load(); + } + /// Clears all entries from the lookup table. virtual void clear() { diff --git a/src/common/lookups/TalkgroupRulesLookup.h b/src/common/lookups/TalkgroupRulesLookup.h index a22c8556..0498f1e1 100644 --- a/src/common/lookups/TalkgroupRulesLookup.h +++ b/src/common/lookups/TalkgroupRulesLookup.h @@ -395,6 +395,9 @@ namespace lookups /// Reads the lookup table from the specified lookup table file. /// True, if lookup table was read, otherwise false. bool read(); + /// Reads the lookup table from the specified lookup table file. + /// True, if lookup table was read, otherwise false. + bool reload() { return load(); } /// Clears all entries from the lookup table. void clear(); diff --git a/src/fne/network/FNENetwork.cpp b/src/fne/network/FNENetwork.cpp index 0732c51a..bdf9fb36 100644 --- a/src/fne/network/FNENetwork.cpp +++ b/src/fne/network/FNENetwork.cpp @@ -281,6 +281,13 @@ void FNENetwork::clock(uint32_t ms) uint64_t now = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + if (m_forceListUpdate) { + for (auto peer : m_peers) { + peerACLUpdate(peer.first); + } + m_forceListUpdate = false; + } + m_maintainenceTimer.clock(ms); if (m_maintainenceTimer.isRunning() && m_maintainenceTimer.hasExpired()) { // check to see if any peers have been quiet (no ping) longer than allowed diff --git a/src/fne/network/FNENetwork.h b/src/fne/network/FNENetwork.h index b672fe86..2f4e8e1e 100644 --- a/src/fne/network/FNENetwork.h +++ b/src/fne/network/FNENetwork.h @@ -310,6 +310,8 @@ namespace network bool m_filterHeaders; bool m_filterTerminators; + bool m_forceListUpdate; + std::vector m_dropU2UPeerTable; bool m_enableInfluxDB; diff --git a/src/fne/network/RESTAPI.cpp b/src/fne/network/RESTAPI.cpp index 75f1c856..5378c1ff 100644 --- a/src/fne/network/RESTAPI.cpp +++ b/src/fne/network/RESTAPI.cpp @@ -582,6 +582,9 @@ void RESTAPI::initializeEndpoints() m_dispatcher.match(FNE_GET_FORCE_UPDATE).get(REST_API_BIND(RESTAPI::restAPI_GetForceUpdate, this)); + m_dispatcher.match(FNE_GET_RELOAD_TGS).get(REST_API_BIND(RESTAPI::restAPI_GetReloadTGs, this)); + m_dispatcher.match(FNE_GET_RELOAD_RIDS).get(REST_API_BIND(RESTAPI::restAPI_GetReloadRIDs, this)); + m_dispatcher.match(FNE_GET_AFF_LIST).get(REST_API_BIND(RESTAPI::restAPI_GetAffList, this)); /* @@ -1171,11 +1174,55 @@ void RESTAPI::restAPI_GetForceUpdate(const HTTPPayload& request, HTTPPayload& re json::object response = json::object(); setResponseDefaultStatus(response); -/* + if (m_network != nullptr) { m_network->m_forceListUpdate = true; } -*/ + + reply.payload(response); +} + +/// +/// +/// +/// +/// +/// +void RESTAPI::restAPI_GetReloadTGs(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match) +{ + if (!validateAuth(request, reply)) { + return; + } + + json::object response = json::object(); + setResponseDefaultStatus(response); + + if (m_network != nullptr) { + m_network->m_tidLookup->reload(); + } + + reply.payload(response); +} + +/// +/// +/// +/// +/// +/// +void RESTAPI::restAPI_GetReloadRIDs(const HTTPPayload& request, HTTPPayload& reply, const RequestMatch& match) +{ + if (!validateAuth(request, reply)) { + return; + } + + json::object response = json::object(); + setResponseDefaultStatus(response); + + if (m_network != nullptr) { + m_network->m_ridLookup->reload(); + } + reply.payload(response); } diff --git a/src/fne/network/RESTAPI.h b/src/fne/network/RESTAPI.h index ff8279d9..db8c8bd9 100644 --- a/src/fne/network/RESTAPI.h +++ b/src/fne/network/RESTAPI.h @@ -127,6 +127,11 @@ private: /// void restAPI_GetForceUpdate(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); + /// + void restAPI_GetReloadTGs(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); + /// + void restAPI_GetReloadRIDs(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); + /// void restAPI_GetAffList(const HTTPPayload& request, HTTPPayload& reply, const network::rest::RequestMatch& match); diff --git a/src/fne/network/RESTDefines.h b/src/fne/network/RESTDefines.h index 448a1a6d..0c851a77 100644 --- a/src/fne/network/RESTDefines.h +++ b/src/fne/network/RESTDefines.h @@ -35,6 +35,9 @@ #define FNE_GET_FORCE_UPDATE "/force-update" +#define FNE_GET_RELOAD_TGS "/reload-tgs" +#define FNE_GET_RELOAD_RIDS "/reload-rids" + #define FNE_GET_AFF_LIST "/report-affiliations" #endif // __FNE_REST_DEFINES_H__ diff --git a/src/remote/RESTClientMain.cpp b/src/remote/RESTClientMain.cpp index cf4069e1..a7ce0754 100644 --- a/src/remote/RESTClientMain.cpp +++ b/src/remote/RESTClientMain.cpp @@ -45,6 +45,8 @@ #define RCD_FNE_GET_TGIDLIST "fne-tgidlist" #define RCD_FNE_GET_FORCEUPDATE "fne-force-update" #define RCD_FNE_GET_AFFLIST "fne-affs" +#define RCD_FNE_GET_RELOADTGS "fne-reload-tgs" +#define RCD_FNE_GET_RELOADRIDS "fne-reload-rids" #define RCD_MODE "mdm-mode" #define RCD_MODE_OPT_IDLE "idle" @@ -200,6 +202,8 @@ void usage(const char* message, const char* arg) reply += " fne-tgidlist Retrieves the list of configured TGIDs (Converged FNE only)\r\n"; reply += " fne-force-update Forces the FNE to send list update (Converged FNE only)\r\n"; reply += " fne-affs Retrieves the list of currently affiliated SUs (Converged FNE only)\r\n"; + reply += " fne-reload-tgs Forces the FNE to reload its TGID list from disk (Converged FNE only)\r\n"; + reply += " fne-reload-rids Forces the FNE to reload its RID list from disk (Converged FNE only)\r\n"; reply += "\r\n"; reply += " mdm-mode Set current mode of host (idle, lockout, dmr, p25, nxdn)\r\n"; reply += " mdm-kill Causes the host to quit\r\n"; @@ -811,6 +815,12 @@ int main(int argc, char** argv) else if (rcom == RCD_FNE_GET_AFFLIST) { retCode = client->send(HTTP_GET, FNE_GET_AFF_LIST, json::object(), response); } + else if (rcom == RCD_FNE_GET_RELOADTGS) { + retCode = client->send(HTTP_GET, FNE_GET_RELOAD_TGS, json::object(), response); + } + else if (rcom == RCD_FNE_GET_RELOADRIDS) { + retCode = client->send(HTTP_GET, FNE_GET_RELOAD_RIDS, json::object(), response); + } else { args.clear(); LogError(LOG_REST, BAD_CMD_STR " (\"%s\")", rcom.c_str());