From bde6284308497c6d8a7e69ab7223abae1eb3c5fd Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Wed, 10 Jan 2024 13:43:20 -0500 Subject: [PATCH] ensure FNE software reports itself differently; make host Network class private section protected so the FNE codebase can inherit from it; create PeerNetwork inherited class on FNE; --- src/fne/Defines.h | 3 + src/fne/HostFNE.cpp | 6 +- src/fne/HostFNE.h | 6 +- src/fne/network/FNENetwork.cpp | 6 ++ src/fne/network/PeerNetwork.cpp | 131 ++++++++++++++++++++++++++++++++ src/fne/network/PeerNetwork.h | 54 +++++++++++++ src/host/network/Network.cpp | 4 +- src/host/network/Network.h | 4 +- 8 files changed, 204 insertions(+), 10 deletions(-) create mode 100644 src/fne/network/PeerNetwork.cpp create mode 100644 src/fne/network/PeerNetwork.h diff --git a/src/fne/Defines.h b/src/fne/Defines.h index 5c6396b1..937a9f83 100644 --- a/src/fne/Defines.h +++ b/src/fne/Defines.h @@ -42,6 +42,9 @@ #undef __EXE_NAME__ #define __EXE_NAME__ "dvmfne" +#undef __NETVER__ +#define __NETVER__ "FNE_R" VERSION_MAJOR VERSION_REV VERSION_MINOR + #undef DEFAULT_CONF_FILE #define DEFAULT_CONF_FILE "fne-config.yml" #undef DEFAULT_LOCK_FILE diff --git a/src/fne/HostFNE.cpp b/src/fne/HostFNE.cpp index b40e148a..18c0e7c3 100644 --- a/src/fne/HostFNE.cpp +++ b/src/fne/HostFNE.cpp @@ -219,7 +219,7 @@ int HostFNE::run() // clock peers for (auto network : m_peerNetworks) { - network::Network* peerNetwork = network.second; + network::PeerNetwork* peerNetwork = network.second; if (peerNetwork != nullptr) { peerNetwork->clock(ms); @@ -483,7 +483,7 @@ bool HostFNE::createPeerNetworks() } // initialize networking - network::Network* network = new Network(masterAddress, masterPort, 0U, id, password, true, debug, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, true, true, m_allowActivityTransfer, m_allowDiagnosticTransfer, false); + network::PeerNetwork* network = new PeerNetwork(masterAddress, masterPort, 0U, id, password, true, debug, m_dmrEnabled, m_p25Enabled, m_nxdnEnabled, true, true, m_allowActivityTransfer, m_allowDiagnosticTransfer, false); network->setMetadata(identity, rxFrequency, txFrequency, 0.0F, 0.0F, 0, 0, 0, latitude, longitude, 0, location); network->enable(enabled); @@ -507,7 +507,7 @@ bool HostFNE::createPeerNetworks() /// Processes any peer network traffic. /// /// -void HostFNE::processPeer(network::Network* peerNetwork) +void HostFNE::processPeer(network::PeerNetwork* peerNetwork) { if (peerNetwork == nullptr) return; // this shouldn't happen... diff --git a/src/fne/HostFNE.h b/src/fne/HostFNE.h index 7047f077..d481d864 100644 --- a/src/fne/HostFNE.h +++ b/src/fne/HostFNE.h @@ -32,8 +32,8 @@ #include "common/yaml/Yaml.h" #include "common/Timer.h" #include "network/FNENetwork.h" +#include "network/PeerNetwork.h" #include "network/RESTAPI.h" -#include "host/network/Network.h" #include #include @@ -79,7 +79,7 @@ private: lookups::RadioIdLookup* m_ridLookup; lookups::TalkgroupRulesLookup* m_tidLookup; - std::unordered_map m_peerNetworks; + std::unordered_map m_peerNetworks; uint32_t m_pingTime; uint32_t m_maxMissedPings; @@ -101,7 +101,7 @@ private: bool createPeerNetworks(); /// Processes any peer network traffic. - void processPeer(network::Network* peerNetwork); + void processPeer(network::PeerNetwork* peerNetwork); }; #endif // __HOST_FNE_H__ diff --git a/src/fne/network/FNENetwork.cpp b/src/fne/network/FNENetwork.cpp index 7c76e6f8..fff1e22a 100644 --- a/src/fne/network/FNENetwork.cpp +++ b/src/fne/network/FNENetwork.cpp @@ -443,6 +443,12 @@ void FNENetwork::clock(uint32_t ms) writeTGIDs(peerId, true); writeDeactiveTGIDs(peerId, true); m_frameQueue->flushQueue(); + + json::object peerConfig = connection.config(); + if (peerConfig["software"].is()) { + std::string software = peerConfig["software"].get(); + LogInfoEx(LOG_NET, "PEER %u reports software %s", peerId, software.c_str()); + } } } } diff --git a/src/fne/network/PeerNetwork.cpp b/src/fne/network/PeerNetwork.cpp new file mode 100644 index 00000000..b2fd84a7 --- /dev/null +++ b/src/fne/network/PeerNetwork.cpp @@ -0,0 +1,131 @@ +/** +* Digital Voice Modem - Converged FNE Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Converged FNE Software +* +*/ +/* +* Copyright (C) 2024 by Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include "fne/Defines.h" +#include "common/network/json/json.h" +#include "common/Utils.h" +#include "fne/network/PeerNetwork.h" + +using namespace network; + +#include +#include +#include + +// --------------------------------------------------------------------------- +// Public Class Members +// --------------------------------------------------------------------------- + +/// +/// Initializes a new instance of the PeerNetwork class. +/// +/// Network Hostname/IP address to connect to. +/// Network port number. +/// +/// Unique ID on the network. +/// Network authentication password. +/// Flag indicating full-duplex operation. +/// Flag indicating whether network debug is enabled. +/// Flag indicating whether DMR is enabled. +/// Flag indicating whether P25 is enabled. +/// Flag indicating whether NXDN is enabled. +/// Flag indicating whether DMR slot 1 is enabled for network traffic. +/// Flag indicating whether DMR slot 2 is enabled for network traffic. +/// Flag indicating that the system activity logs will be sent to the network. +/// Flag indicating that the system diagnostic logs will be sent to the network. +/// Flag indicating that the system will accept radio ID and talkgroup ID lookups from the network. +PeerNetwork::PeerNetwork(const std::string& address, uint16_t port, uint16_t localPort, uint32_t peerId, const std::string& password, + bool duplex, bool debug, bool dmr, bool p25, bool nxdn, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer, bool updateLookup) : + Network(address, port, localPort, peerId, password, duplex, debug, dmr, p25, nxdn, slot1, slot2, allowActivityTransfer, allowDiagnosticTransfer, updateLookup) +{ + assert(!address.empty()); + assert(port > 0U); + assert(!password.empty()); +} + +// --------------------------------------------------------------------------- +// Protected Class Members +// --------------------------------------------------------------------------- + +/// +/// Writes configuration to the network. +/// +/// +bool PeerNetwork::writeConfig() +{ + if (m_loginStreamId == 0U) { + LogWarning(LOG_NET, "BUGBUG: tried to write network authorisation with no stream ID?"); + return false; + } + + const char* software = __NETVER__; + + json::object config = json::object(); + + // identity and frequency + config["identity"].set(m_identity); // Identity + config["rxFrequency"].set(m_rxFrequency); // Rx Frequency + config["txFrequency"].set(m_txFrequency); // Tx Frequency + + // system info + json::object sysInfo = json::object(); + sysInfo["latitude"].set(m_latitude); // Latitude + sysInfo["longitude"].set(m_longitude); // Longitude + + sysInfo["height"].set(m_height); // Height + sysInfo["location"].set(m_location); // Location + config["info"].set(sysInfo); + + // channel data + json::object channel = json::object(); + channel["txPower"].set(m_power); // Tx Power + channel["txOffsetMhz"].set(m_txOffsetMhz); // Tx Offset (Mhz) + channel["chBandwidthKhz"].set(m_chBandwidthKhz); // Ch. Bandwidth (khz) + channel["channelId"].set(m_channelId); // Channel ID + channel["channelNo"].set(m_channelNo); // Channel No + config["channel"].set(channel); + + // RCON + json::object rcon = json::object(); + rcon["password"].set(m_restApiPassword); // REST API Password + rcon["port"].set(m_restApiPort); // REST API Port + config["rcon"].set(rcon); + + config["software"].set(std::string(software)); // Software ID + + json::value v = json::value(config); + std::string json = v.serialize(); + + char buffer[json.length() + 8U]; + + ::memcpy(buffer + 0U, TAG_REPEATER_CONFIG, 4U); + ::sprintf(buffer + 8U, "%s", json.c_str()); + + if (m_debug) { + Utils::dump(1U, "Network Message, Configuration", (uint8_t*)buffer, json.length() + 8U); + } + + return writeMaster({ NET_FUNC_RPTC, NET_SUBFUNC_NOP }, (uint8_t*)buffer, json.length() + 8U, pktSeq(), m_loginStreamId); +} diff --git a/src/fne/network/PeerNetwork.h b/src/fne/network/PeerNetwork.h new file mode 100644 index 00000000..114c9003 --- /dev/null +++ b/src/fne/network/PeerNetwork.h @@ -0,0 +1,54 @@ +/** +* Digital Voice Modem - Converged FNE Software +* GPLv2 Open Source. Use is subject to license terms. +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* @package DVM / Converged FNE Software +* +*/ +/* +* Copyright (C) 2024 by Bryan Biedenkapp N2PLL +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#if !defined(__PEER_NETWORK_H__) +#define __PEER_NETWORK_H__ + +#include "Defines.h" +#include "host/network/Network.h" + +#include +#include + +namespace network +{ + // --------------------------------------------------------------------------- + // Class Declaration + // Implements the core peer networking logic. + // --------------------------------------------------------------------------- + + class HOST_SW_API PeerNetwork : public Network { + public: + /// Initializes a new instance of the PeerNetwork class. + PeerNetwork(const std::string& address, uint16_t port, uint16_t localPort, uint32_t peerId, const std::string& password, + bool duplex, bool debug, bool dmr, bool p25, bool nxdn, bool slot1, bool slot2, bool allowActivityTransfer, bool allowDiagnosticTransfer, bool updateLookup); + + protected: + /// Writes configuration to the network. + bool writeConfig() override; + }; +} // namespace network + +#endif // __NETWORK_H__ diff --git a/src/host/network/Network.cpp b/src/host/network/Network.cpp index 04c6319f..cd8a23b5 100644 --- a/src/host/network/Network.cpp +++ b/src/host/network/Network.cpp @@ -630,7 +630,7 @@ void Network::close() } // --------------------------------------------------------------------------- -// Private Class Members +// Protected Class Members // --------------------------------------------------------------------------- /// @@ -732,7 +732,7 @@ bool Network::writeConfig() rcon["port"].set(m_restApiPort); // REST API Port config["rcon"].set(rcon); - config["software"].set(std::string(software)); // Software ID + config["software"].set(std::string(software)); // Software ID json::value v = json::value(config); std::string json = v.serialize(); diff --git a/src/host/network/Network.h b/src/host/network/Network.h index 18d1bc49..a53a64d7 100644 --- a/src/host/network/Network.h +++ b/src/host/network/Network.h @@ -85,7 +85,7 @@ namespace network /// Last received RTP sequence number. __READONLY_PROPERTY_PLAIN(uint16_t, pktLastSeq, pktLastSeq); - private: + protected: std::string m_address; uint16_t m_port; @@ -140,7 +140,7 @@ namespace network /// Writes network authentication challenge. bool writeAuthorisation(); /// Writes modem configuration to the network. - bool writeConfig(); + virtual bool writeConfig(); /// Writes a network stay-alive ping. bool writePing(); };