diff --git a/NXDNGateway/Conf.cpp b/NXDNGateway/Conf.cpp index 40fb0eb..8b4dda2 100644 --- a/NXDNGateway/Conf.cpp +++ b/NXDNGateway/Conf.cpp @@ -68,7 +68,8 @@ m_aprsPassword(), m_aprsSuffix(), m_aprsDescription(), m_networkPort(0U), -m_networkHosts(), +m_networkHosts1(), +m_networkHosts2(), m_networkReloadTime(0U), m_networkParrotAddress("127.0.0.1"), m_networkParrotPort(0U), @@ -196,8 +197,10 @@ bool CConf::read() } else if (section == SECTION_NETWORK) { if (::strcmp(key, "Port") == 0) m_networkPort = (unsigned int)::atoi(value); - else if (::strcmp(key, "HostsFile") == 0) - m_networkHosts = value; + else if (::strcmp(key, "HostsFile1") == 0) + m_networkHosts1 = value; + else if (::strcmp(key, "HostsFile2") == 0) + m_networkHosts2 = value; else if (::strcmp(key, "ReloadTime") == 0) m_networkReloadTime = (unsigned int)::atoi(value); else if (::strcmp(key, "ParrotAddress") == 0) @@ -367,9 +370,14 @@ unsigned int CConf::getNetworkPort() const return m_networkPort; } -std::string CConf::getNetworkHosts() const +std::string CConf::getNetworkHosts1() const { - return m_networkHosts; + return m_networkHosts1; +} + +std::string CConf::getNetworkHosts2() const +{ + return m_networkHosts2; } unsigned int CConf::getNetworkReloadTime() const diff --git a/NXDNGateway/Conf.h b/NXDNGateway/Conf.h index bfbb131..64f29d6 100644 --- a/NXDNGateway/Conf.h +++ b/NXDNGateway/Conf.h @@ -72,7 +72,8 @@ public: // The Network section unsigned int getNetworkPort() const; - std::string getNetworkHosts() const; + std::string getNetworkHosts1() const; + std::string getNetworkHosts2() const; unsigned int getNetworkReloadTime() const; std::string getNetworkParrotAddress() const; unsigned int getNetworkParrotPort() const; @@ -119,7 +120,8 @@ private: std::string m_aprsDescription; unsigned int m_networkPort; - std::string m_networkHosts; + std::string m_networkHosts1; + std::string m_networkHosts2; unsigned int m_networkReloadTime; std::string m_networkParrotAddress; unsigned int m_networkParrotPort; diff --git a/NXDNGateway/NXDNGateway.cpp b/NXDNGateway/NXDNGateway.cpp index b1ed1fe..f96cba7 100644 --- a/NXDNGateway/NXDNGateway.cpp +++ b/NXDNGateway/NXDNGateway.cpp @@ -188,7 +188,7 @@ void CNXDNGateway::run() return; } - CReflectors reflectors(m_conf.getNetworkHosts(), m_conf.getNetworkReloadTime()); + CReflectors reflectors(m_conf.getNetworkHosts1(), m_conf.getNetworkHosts2(), m_conf.getNetworkReloadTime()); if (m_conf.getNetworkParrotPort() > 0U) reflectors.setParrot(m_conf.getNetworkParrotAddress(), m_conf.getNetworkParrotPort()); if (m_conf.getNetworkNXDN2DMRPort() > 0U) diff --git a/NXDNGateway/NXDNGateway.ini b/NXDNGateway/NXDNGateway.ini index 93b7ea4..a77efca 100644 --- a/NXDNGateway/NXDNGateway.ini +++ b/NXDNGateway/NXDNGateway.ini @@ -41,7 +41,8 @@ FileRoot=NXDNGateway [Network] Port=14050 -HostsFile=./NXDNHosts.txt +HostsFile1=./NXDNHosts.txt +HostsFile2=./private/NXDNHosts.txt ReloadTime=60 ParrotAddress=127.0.0.1 ParrotPort=42021 diff --git a/NXDNGateway/Reflectors.cpp b/NXDNGateway/Reflectors.cpp index 6b11957..20c0a92 100644 --- a/NXDNGateway/Reflectors.cpp +++ b/NXDNGateway/Reflectors.cpp @@ -26,8 +26,9 @@ #include #include -CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) : -m_hostsFile(hostsFile), +CReflectors::CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime) : +m_hostsFile1(hostsFile1), +m_hostsFile2(hostsFile2), m_parrotAddress(), m_parrotPort(0U), m_reflectors(), @@ -65,7 +66,7 @@ bool CReflectors::load() m_reflectors.clear(); - FILE* fp = ::fopen(m_hostsFile.c_str(), "rt"); + FILE* fp = ::fopen(m_hostsFile1.c_str(), "rt"); if (fp != NULL) { char buffer[100U]; while (::fgets(buffer, 100U, fp) != NULL) { @@ -94,6 +95,39 @@ bool CReflectors::load() ::fclose(fp); } + fp = ::fopen(m_hostsFile2.c_str(), "rt"); + if (fp != NULL) { + char buffer[100U]; + while (::fgets(buffer, 100U, fp) != NULL) { + if (buffer[0U] == '#') + continue; + + char* p1 = ::strtok(buffer, " \t\r\n"); + char* p2 = ::strtok(NULL, " \t\r\n"); + char* p3 = ::strtok(NULL, " \t\r\n"); + + if (p1 != NULL && p2 != NULL && p3 != NULL) { + // Don't allow duplicate reflector ids from the secondary hosts file. + unsigned int id = (unsigned int)::atoi(p1); + if (find(id) == NULL) { + std::string host = std::string(p2); + + in_addr address = CUDPSocket::lookup(host); + if (address.s_addr != INADDR_NONE) { + CNXDNReflector* refl = new CNXDNReflector; + refl->m_id = id; + refl->m_address = address; + refl->m_port = (unsigned int)::atoi(p3); + + m_reflectors.push_back(refl); + } + } + } + } + + ::fclose(fp); + } + size_t size = m_reflectors.size(); LogInfo("Loaded %u NXDN reflectors", size); diff --git a/NXDNGateway/Reflectors.h b/NXDNGateway/Reflectors.h index 4a79096..3c3672c 100644 --- a/NXDNGateway/Reflectors.h +++ b/NXDNGateway/Reflectors.h @@ -41,7 +41,7 @@ public: class CReflectors { public: - CReflectors(const std::string& hostsFile, unsigned int reloadTime); + CReflectors(const std::string& hostsFile1, const std::string& hostsFile2, unsigned int reloadTime); ~CReflectors(); void setParrot(const std::string& address, unsigned int port); @@ -54,7 +54,8 @@ public: void clock(unsigned int ms); private: - std::string m_hostsFile; + std::string m_hostsFile1; + std::string m_hostsFile2; std::string m_parrotAddress; unsigned int m_parrotPort; std::string m_nxdn2dmrAddress;