From 0e20d4fec04e7557da4e55fa7de845ccff5abb8c Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Fri, 2 Feb 2024 21:42:57 -0500 Subject: [PATCH] add separate config option for reporting peer pings to the log; add extra logging around an RPTL NAK condition; --- configs/fne-config.example.yml | 3 +++ src/fne/HostFNE.cpp | 6 +++++- src/fne/network/FNENetwork.cpp | 12 ++++++++++-- src/fne/network/FNENetwork.h | 3 ++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/configs/fne-config.example.yml b/configs/fne-config.example.yml index 0f00f74a..95ff4dcf 100644 --- a/configs/fne-config.example.yml +++ b/configs/fne-config.example.yml @@ -46,6 +46,9 @@ master: # Flag indicating whether or not verbose debug logging is enabled. debug: false + # Flag indicating whether or not peer pinging will be reported. + reportPeerPing: true + # Flag indicating whether or not master endpoint networking is encrypted. encrypted: false # AES-256 32-byte Preshared Key diff --git a/src/fne/HostFNE.cpp b/src/fne/HostFNE.cpp index 8840dbc5..2cd131f2 100644 --- a/src/fne/HostFNE.cpp +++ b/src/fne/HostFNE.cpp @@ -373,6 +373,8 @@ bool HostFNE::createMasterNetwork() bool verbose = masterConf["verbose"].as(false); bool debug = masterConf["debug"].as(false); + bool reportPeerPing = masterConf["reportPeerPing"].as(false); + bool encrypted = masterConf["encrypted"].as(false); std::string key = masterConf["presharedKey"].as(); uint8_t presharedKey[AES_WRAPPED_PCKT_KEY_LEN]; @@ -433,6 +435,8 @@ bool HostFNE::createMasterNetwork() LogInfo(" Encrypted: %s", encrypted ? "yes" : "no"); + LogInfo(" Report Peer Pings: %s", reportPeerPing ? "yes" : "no"); + if (verbose) { LogInfo(" Verbose: yes"); } @@ -442,7 +446,7 @@ bool HostFNE::createMasterNetwork() } // initialize networking - m_network = new FNENetwork(this, address, port, id, password, debug, verbose, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, + m_network = new FNENetwork(this, address, port, id, password, debug, verbose, reportPeerPing, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, parrotDelay, parrotGrantDemand, m_allowActivityTransfer, m_allowDiagnosticTransfer, m_pingTime, m_updateLookupTime); m_network->setLookups(m_ridLookup, m_tidLookup); diff --git a/src/fne/network/FNENetwork.cpp b/src/fne/network/FNENetwork.cpp index fd445b0c..0c87c5b5 100644 --- a/src/fne/network/FNENetwork.cpp +++ b/src/fne/network/FNENetwork.cpp @@ -42,6 +42,7 @@ using namespace network::fne; /// Network authentication password. /// Flag indicating whether network debug is enabled. /// Flag indicating whether network verbose logging is enabled. +/// Flag indicating whether peer pinging is reported. /// Flag indicating whether DMR is enabled. /// Flag indicating whether P25 is enabled. /// Flag indicating whether NXDN is enabled. @@ -52,7 +53,7 @@ using namespace network::fne; /// /// FNENetwork::FNENetwork(HostFNE* host, const std::string& address, uint16_t port, uint32_t peerId, const std::string& password, - bool debug, bool verbose, bool dmr, bool p25, bool nxdn, uint32_t parrotDelay, bool parrotGrantDemand, + bool debug, bool verbose, bool reportPeerPing, bool dmr, bool p25, bool nxdn, uint32_t parrotDelay, bool parrotGrantDemand, bool allowActivityTransfer, bool allowDiagnosticTransfer, uint32_t pingTime, uint32_t updateLookupTime) : BaseNetwork(peerId, true, debug, true, true, allowActivityTransfer, allowDiagnosticTransfer), m_tagDMR(nullptr), @@ -76,6 +77,7 @@ FNENetwork::FNENetwork(HostFNE* host, const std::string& address, uint16_t port, m_updateLookupTimer(1000U, (updateLookupTime * 60U)), m_forceListUpdate(false), m_callInProgress(false), + m_reportPeerPing(reportPeerPing), m_verbose(verbose) { assert(host != nullptr); @@ -320,12 +322,18 @@ void FNENetwork::clock(uint32_t ms) // the login sequence if (peerId > 0 && (m_peers.find(peerId) != m_peers.end())) { FNEPeerConnection* connection = m_peers[peerId]; + LogMessage(LOG_NET, "PEER %u was RPTL NAKed cleaning up peer connection", peerId); if (connection != nullptr) { if (connection->connectionState() != NET_STAT_RUNNING) { if (erasePeer(peerId)) { delete connection; } } + } else { + erasePeer(peerId); + if (m_verbose) { + LogWarning(LOG_NET, "PEER %u was RPTL NAKed while having no connection?", peerId); + } } } } @@ -510,7 +518,7 @@ void FNENetwork::clock(uint32_t ms) m_peers[peerId] = connection; writePeerCommand(peerId, { NET_FUNC_PONG, NET_SUBFUNC_NOP }); - if (m_verbose) { + if (m_reportPeerPing) { LogInfoEx(LOG_NET, "PEER %u ping received and answered, pingsReceived = %u", peerId, connection->pingsReceived()); } } diff --git a/src/fne/network/FNENetwork.h b/src/fne/network/FNENetwork.h index 85f8eb86..a40ec28f 100644 --- a/src/fne/network/FNENetwork.h +++ b/src/fne/network/FNENetwork.h @@ -141,7 +141,7 @@ namespace network public: /// Initializes a new instance of the FNENetwork class. FNENetwork(HostFNE* host, const std::string& address, uint16_t port, uint32_t peerId, const std::string& password, - bool debug, bool verbose, bool dmr, bool p25, bool nxdn, uint32_t parrotDelay, bool parrotGrantDemand, + bool debug, bool verbose, bool reportPeerPing, bool dmr, bool p25, bool nxdn, uint32_t parrotDelay, bool parrotGrantDemand, bool allowActivityTransfer, bool allowDiagnosticTransfer, uint32_t pingTime, uint32_t updateLookupTime); /// Finalizes a instance of the FNENetwork class. ~FNENetwork() override; @@ -209,6 +209,7 @@ namespace network bool m_forceListUpdate; bool m_callInProgress; + bool m_reportPeerPing; bool m_verbose; /// Helper to erase the peer from the peers affiliations list.