diff --git a/Common/CacheManager.cpp b/Common/CacheManager.cpp index 682ad58..7915d1b 100644 --- a/Common/CacheManager.cpp +++ b/Common/CacheManager.cpp @@ -54,7 +54,7 @@ CUserData* CCacheManager::findUser(const wxString& user) if (gr == NULL) return NULL; - return new CUserData(user, ur->getRepeater(), gr->getGateway(), gr->getAddress(), gr->getG2Port()); + return new CUserData(user, ur->getRepeater(), gr->getGateway(), gr->getAddress()); } CGatewayData* CCacheManager::findGateway(const wxString& gateway) @@ -65,7 +65,7 @@ CGatewayData* CCacheManager::findGateway(const wxString& gateway) if (gr == NULL) return NULL; - return new CGatewayData(gateway, gr->getAddress(), gr->getProtocol(), gr->getG2Port()); + return new CGatewayData(gateway, gr->getAddress(), gr->getProtocol()); } CRepeaterData* CCacheManager::findRepeater(const wxString& repeater) @@ -87,7 +87,7 @@ CRepeaterData* CCacheManager::findRepeater(const wxString& repeater) if (gr == NULL) return NULL; - return new CRepeaterData(repeater, gr->getGateway(), gr->getAddress(), gr->getProtocol(), gr->getG2Port()); + return new CRepeaterData(repeater, gr->getGateway(), gr->getAddress(), gr->getProtocol()); } void CCacheManager::updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, const wxString& timestamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) @@ -126,8 +126,3 @@ void CCacheManager::updateGateway(const wxString& gateway, const wxString& addre m_gatewayCache.update(gateway, address, protocol, addrLock, protoLock); } - -void CCacheManager::updateGatewayG2(const wxString& gateway, const in_addr& address, unsigned int g2Port) -{ - m_gatewayCache.updateG2(gateway, address, g2Port); -} diff --git a/Common/CacheManager.h b/Common/CacheManager.h index dc38392..e8d669b 100644 --- a/Common/CacheManager.h +++ b/Common/CacheManager.h @@ -33,12 +33,11 @@ class CUserData { public: - CUserData(const wxString& user, const wxString& repeater, const wxString& gateway, in_addr address, unsigned int g2Port) : + CUserData(const wxString& user, const wxString& repeater, const wxString& gateway, in_addr address) : m_user(user), m_repeater(repeater), m_gateway(gateway), - m_address(address), - m_g2Port(g2Port) + m_address(address) { } @@ -62,27 +61,20 @@ public: return m_address; } - unsigned int getG2Port() const - { - return m_g2Port; - } - private: wxString m_user; wxString m_repeater; wxString m_gateway; in_addr m_address; - unsigned int m_g2Port; }; class CRepeaterData { public: - CRepeaterData(const wxString& repeater, const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol, unsigned int g2Port) : + CRepeaterData(const wxString& repeater, const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol) : m_repeater(repeater), m_gateway(gateway), m_address(address), - m_protocol(protocol), - m_g2Port(g2Port) + m_protocol(protocol) { } @@ -106,26 +98,19 @@ public: return m_protocol; } - unsigned int getG2Port() const - { - return m_g2Port; - } - private: wxString m_repeater; wxString m_gateway; in_addr m_address; DSTAR_PROTOCOL m_protocol; - unsigned int m_g2Port; }; class CGatewayData { public: - CGatewayData(const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol, unsigned int g2Port) : + CGatewayData(const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol) : m_gateway(gateway), m_address(address), - m_protocol(protocol), - m_g2Port(g2Port) + m_protocol(protocol) { } @@ -144,16 +129,10 @@ public: return m_protocol; } - unsigned int getG2Port() const - { - return m_g2Port; - } - private: wxString m_gateway; in_addr m_address; DSTAR_PROTOCOL m_protocol; - unsigned int m_g2Port; }; class CCacheManager { @@ -167,8 +146,7 @@ public: void updateUser(const wxString& user, const wxString& repeater, const wxString& gateway, const wxString& address, const wxString& timeStamp, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); void updateRepeater(const wxString& repeater, const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); - void updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol,bool addrLock, bool protoLock); - void updateGatewayG2(const wxString& gateway, const in_addr& address, unsigned int g2Port); + void updateGateway(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); private: wxMutex m_mutex; diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index abf30b4..bdbcfc3 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -189,7 +189,6 @@ - @@ -261,7 +260,6 @@ - diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 82574fb..8365240 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -209,9 +209,6 @@ Source Files - - Source Files - @@ -436,8 +433,5 @@ Header Files - - Header Files - \ No newline at end of file diff --git a/Common/G2ProtocolHandler.cpp b/Common/G2ProtocolHandler.cpp index fe9d5f6..7d1fc7e 100644 --- a/Common/G2ProtocolHandler.cpp +++ b/Common/G2ProtocolHandler.cpp @@ -29,7 +29,9 @@ CG2ProtocolHandler::CG2ProtocolHandler(unsigned int port, const wxString& addr) m_socket(addr, port), m_type(GT_NONE), m_buffer(NULL), -m_length(0U) +m_length(0U), +m_address(), +m_port(0U) { m_buffer = new unsigned char[BUFFER_LENGTH]; } @@ -74,33 +76,29 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data) return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort()); } -G2_TYPE CG2ProtocolHandler::read(in_addr& remoteAddress, unsigned int& remotePort) +G2_TYPE CG2ProtocolHandler::read() { bool res = true; // Loop until we have no more data from the socket or we have data for the higher layers while (res) - res = readPackets(remoteAddress, remotePort); + res = readPackets(); return m_type; } -bool CG2ProtocolHandler::readPackets(in_addr& remoteAddress, unsigned int& remotePort) +bool CG2ProtocolHandler::readPackets() { m_type = GT_NONE; - remotePort = 0; // No more data? - int length = m_socket.read(m_buffer, BUFFER_LENGTH, remoteAddress, remotePort); + int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_address, m_port); if (length <= 0) return false; m_length = length; if (m_buffer[0] != 'D' || m_buffer[1] != 'S' || m_buffer[2] != 'V' || m_buffer[3] != 'T') { - if(length == 1 && m_buffer[0] == 0) - return false;//we have been udp punched - return true; } else { // Header or data packet type? @@ -113,7 +111,7 @@ bool CG2ProtocolHandler::readPackets(in_addr& remoteAddress, unsigned int& remot } } -CHeaderData* CG2ProtocolHandler::readHeader(in_addr remoteAddress, unsigned int remotePort) +CHeaderData* CG2ProtocolHandler::readHeader() { if (m_type != GT_HEADER) return NULL; @@ -121,7 +119,7 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr remoteAddress, unsigned int CHeaderData* header = new CHeaderData; // G2 checksums are unreliable - bool res = header->setG2Data(m_buffer, m_length, false, remoteAddress, remotePort); + bool res = header->setG2Data(m_buffer, m_length, false, m_address, m_port); if (!res) { delete header; return NULL; @@ -130,15 +128,14 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr remoteAddress, unsigned int return header; } -CAMBEData* CG2ProtocolHandler::readAMBE(in_addr remoteAddress, unsigned int remotePort) +CAMBEData* CG2ProtocolHandler::readAMBE() { if (m_type != GT_AMBE) return NULL; CAMBEData* data = new CAMBEData; - bool res = data->setG2Data(m_buffer, m_length, remoteAddress, remotePort -); + bool res = data->setG2Data(m_buffer, m_length, m_address, m_port); if (!res) { delete data; return NULL; @@ -147,7 +144,7 @@ CAMBEData* CG2ProtocolHandler::readAMBE(in_addr remoteAddress, unsigned int remo return data; } -void CG2ProtocolHandler::traverseNat(const wxString& address) +void CG2ProtocolHandler::punchUDPHole(const wxString& address) { unsigned char buffer[1]; ::memset(buffer, 0, 1); diff --git a/Common/G2ProtocolHandler.h b/Common/G2ProtocolHandler.h index 088af25..8b74bd5 100644 --- a/Common/G2ProtocolHandler.h +++ b/Common/G2ProtocolHandler.h @@ -48,11 +48,11 @@ public: bool writeHeader(const CHeaderData& header); bool writeAMBE(const CAMBEData& data); - G2_TYPE read(in_addr& incomingAddress, unsigned int& incomingPort); - CHeaderData* readHeader(in_addr incomingAddress, unsigned int incomingPort); - CAMBEData* readAMBE(in_addr incomingAddress, unsigned int incomingPort); + G2_TYPE read(); + CHeaderData* readHeader(); + CAMBEData* readAMBE(); - void traverseNat(const wxString& addr); + void punchUDPHole(const wxString& addr); void close(); @@ -61,8 +61,10 @@ private: G2_TYPE m_type; unsigned char* m_buffer; unsigned int m_length; + in_addr m_address; + unsigned int m_port; - bool readPackets(in_addr& incomingAddress, unsigned int& incomingPort); + bool readPackets(); }; #endif diff --git a/Common/GatewayCache.cpp b/Common/GatewayCache.cpp index e97984e..b029d7c 100644 --- a/Common/GatewayCache.cpp +++ b/Common/GatewayCache.cpp @@ -38,56 +38,19 @@ CGatewayRecord* CGatewayCache::find(const wxString& gateway) void CGatewayCache::update(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { + CGatewayRecord* rec = m_cache[gateway]; + in_addr addr_in; addr_in.s_addr = ::inet_addr(address.mb_str()); - CGatewayRecord* rec = m_cache[gateway]; - - if(rec == NULL) { - rec = findByAddress(addr_in);//did this gateway punch to us and we do not have a gateway set for it ? - if(rec != NULL && rec->getGateway().empty() && rec->getProtocol() == protocol) - rec->setGateway(gateway); - else - rec = NULL; - } - if (rec == NULL) // A brand new record is needed - m_cache[gateway] = new CGatewayRecord(gateway, addr_in, G2_DV_PORT, protocol, addrLock, protoLock); + m_cache[gateway] = new CGatewayRecord(gateway, addr_in, protocol, addrLock, protoLock); else // Update an existing record rec->setData(addr_in, protocol, addrLock, protoLock); } -void CGatewayCache::updateG2(const wxString& gateway, in_addr address, unsigned int g2Port) -{ - //empty gateway means we are coming from udp hole punching, let see if we have an gateway with matching address - CGatewayRecord* rec = gateway.empty()? findByAddress(address) : m_cache[gateway]; - - if (rec == NULL) { - // A brand new record is needed - m_cache[gateway] = new CGatewayRecord(gateway, address, g2Port, DP_UNKNOWN, false, false); - } - else { - // Update an existing record - if(rec->getGateway().empty())//if this is a record created from a punch call, set its gateway - rec->setGateway(gateway); - - rec->setG2Data(address, g2Port); - } -} - -CGatewayRecord* CGatewayCache::findByAddress(in_addr address) -{ - for (CGatewayCache_t::iterator it = m_cache.begin(); it != m_cache.end(); ++it) { - if(it-> second != NULL - && it->second->getAddress().s_addr == address.s_addr) - return it->second; - } - - return NULL; -} - unsigned int CGatewayCache::getCount() const { return m_cache.size(); diff --git a/Common/GatewayCache.h b/Common/GatewayCache.h index dc963b9..561743c 100644 --- a/Common/GatewayCache.h +++ b/Common/GatewayCache.h @@ -35,10 +35,9 @@ class CGatewayRecord { public: - CGatewayRecord(const wxString& gateway, in_addr address, unsigned int g2Port, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) : + CGatewayRecord(const wxString& gateway, in_addr address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) : m_gateway(gateway), m_address(address), - m_g2Port(g2Port), m_protocol(DP_UNKNOWN), m_addrLock(addrLock), m_protoLock(false) @@ -54,11 +53,6 @@ public: return m_gateway; } - void setGateway(const wxString& gateway) - { - m_gateway = gateway; - } - in_addr getAddress() const { return m_address; @@ -69,11 +63,6 @@ public: return m_protocol; } - unsigned int getG2Port() const - { - return m_g2Port; - } - void setData(in_addr address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock) { if (!m_addrLock) { @@ -89,20 +78,9 @@ public: } } - void setG2Data(in_addr address, unsigned int g2Port) - { - if (!m_addrLock) { - m_address = address; - } - - m_g2Port = g2Port; - } - private: wxString m_gateway; - in_addr m_address; - //the incoming G2 port, keep track of it and use it to answer back instead of the default one. This helps us defeat NAT with no port forwarding to G2_DVPORT - unsigned int m_g2Port; + in_addr m_address; DSTAR_PROTOCOL m_protocol; bool m_addrLock; bool m_protoLock; @@ -118,13 +96,10 @@ public: CGatewayRecord* find(const wxString& gateway); void update(const wxString& gateway, const wxString& address, DSTAR_PROTOCOL protocol, bool addrLock, bool protoLock); - void updateG2(const wxString& gateway, in_addr address, unsigned int g2Port); unsigned int getCount() const; private: - CGatewayRecord* findByAddress(in_addr address); - CGatewayCache_t m_cache; }; diff --git a/Common/Makefile b/Common/Makefile index e215ea2..0243a4b 100644 --- a/Common/Makefile +++ b/Common/Makefile @@ -4,7 +4,7 @@ OBJECTS = AMBEData.o AnnouncementUnit.o APRSCollector.o APRSWriter.o APRSWriterT DPlusAuthenticator.o DPlusHandler.o DPlusProtocolHandler.o DPlusProtocolHandlerPool.o DRATSServer.o DTMF.o \ DummyRepeaterProtocolHandler.o DVTOOLFileReader.o EchoUnit.o G2Handler.o G2ProtocolHandler.o GatewayCache.o \ HBRepeaterProtocolHandler.o HeaderData.o HeaderLogger.o HeardData.o HostFile.o IcomRepeaterProtocolHandler.o IRCDDBGatewayConfig.o \ - LogEvent.o Logger.o NatTraversalHandler.o PollData.o RemoteHandler.o RemoteLinkData.o RemoteProtocolHandler.o RemoteRepeaterData.o RemoteStarNetGroup.o \ + LogEvent.o Logger.o PollData.o RemoteHandler.o RemoteLinkData.o RemoteProtocolHandler.o RemoteRepeaterData.o RemoteStarNetGroup.o \ RemoteStarNetUser.o RepeaterCache.o RepeaterHandler.o SHA256.o SlowDataEncoder.o StarNetHandler.o StatusData.o \ TCPReaderWriterClient.o TCPReaderWriterServer.o TextCollector.o TextData.o Timer.o UDPReaderWriter.o UserCache.o Utils.o \ VersionUnit.o XLXHostsFileDownloader.o diff --git a/Common/NatTraversalHandler.cpp b/Common/NatTraversalHandler.cpp deleted file mode 100644 index 052c5d9..0000000 --- a/Common/NatTraversalHandler.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 by Jonathan Naylor G4KLX - * - * 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 "NatTraversalHandler.h" - -const unsigned int CACHE_SIZE = 500U; - -CNatTraversalHandler::CNatTraversalHandler() : -m_g2cache(CACHE_SIZE), -m_g2Handler(NULL) -{ - -} - -CNatTraversalHandler::~CNatTraversalHandler() -{ - for (CNatTraversalCache_t::iterator it = m_g2cache.begin(); it != m_g2cache.end(); ++it) - delete it->second; -} - -void CNatTraversalHandler::setG2Handler(CG2ProtocolHandler * handler) -{ - m_g2Handler = handler; -} - -void CNatTraversalHandler::traverseNatG2(const wxString& address) -{ - if(m_g2Handler != NULL){ - CNatTraversalRecord* record = m_g2cache[address]; - - if(record == NULL) { - record = new CNatTraversalRecord(address); - m_g2cache[address] = record; - } - - std::time_t currentTime = std::time(NULL); - if(currentTime - record->getTimestamp() > G2_TRAVERSAL_TIMEOUT) { - record->setTimestamp(currentTime); - m_g2Handler->traverseNat(address); - } - } -} \ No newline at end of file diff --git a/Common/NatTraversalHandler.h b/Common/NatTraversalHandler.h deleted file mode 100644 index c5c424d..0000000 --- a/Common/NatTraversalHandler.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 by Jonathan Naylor G4KLX - * - * 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. - */ - -#ifndef NatTraversalHandler_H -#define NatTraversalHandler_H - -#define G2_TRAVERSAL_TIMEOUT 29 //seconds - -#include "G2ProtocolHandler.h" - -#include -#include - -enum NAT_TRAVERSAL_TYPE { - NTT_G2, - //NTT_DEXTRA - //NTT_DCS - //NTT_DPLUS -}; - -class CNatTraversalRecord { -public: - CNatTraversalRecord(const wxString& address) : - m_address(address), - m_timestamp(0) - { - } - - std::time_t getTimestamp() const - { - return m_timestamp; - } - - void setTimestamp(std::time_t timestamp) - { - m_timestamp = timestamp; - } - -private: - wxString m_address; - std::time_t m_timestamp; -}; - -WX_DECLARE_STRING_HASH_MAP(CNatTraversalRecord*, CNatTraversalCache_t); - -/* -* This keeps track of when we UDP punched to one destination so to avoid unnecessary traffic on each ircddb reporting -*/ -class CNatTraversalHandler { -public: - CNatTraversalHandler(); - ~CNatTraversalHandler(); - - void setG2Handler(CG2ProtocolHandler* handler); - void traverseNatG2(const wxString& address); - -private: - CNatTraversalCache_t m_g2cache; - CG2ProtocolHandler* m_g2Handler; -}; - -#endif \ No newline at end of file diff --git a/Common/RepeaterHandler.cpp b/Common/RepeaterHandler.cpp index c1f32a9..1a25db0 100644 --- a/Common/RepeaterHandler.cpp +++ b/Common/RepeaterHandler.cpp @@ -109,7 +109,6 @@ m_g2Repeater(), m_g2Gateway(), m_g2Header(NULL), m_g2Address(), -m_g2Port(G2_DV_PORT), m_linkStatus(LS_NONE), m_linkRepeater(), m_linkGateway(), @@ -633,7 +632,6 @@ void CRepeaterHandler::processRepeater(CHeaderData& header) m_g2User.Clear(); m_g2Repeater.Clear(); m_g2Gateway.Clear(); - m_g2Port = G2_DV_PORT; // Check if this user is restricted m_restricted = false; @@ -831,7 +829,7 @@ void CRepeaterHandler::processRepeater(CAMBEData& data) break; case G2_OK: - data.setDestination(m_g2Address, m_g2Port); + data.setDestination(m_g2Address, G2_DV_PORT); m_g2Handler->writeAMBE(data); if (data.isEnd()) { @@ -1215,7 +1213,7 @@ void CRepeaterHandler::resolveUserInt(const wxString& user, const wxString& repe m_g2Repeater = repeater; m_g2Gateway = gateway; - m_g2Header->setDestination(m_g2Address, m_g2Port); + m_g2Header->setDestination(m_g2Address, G2_DV_PORT); m_g2Header->setRepeaters(m_g2Gateway, m_g2Repeater); m_g2Handler->writeHeader(*m_g2Header); @@ -1228,7 +1226,6 @@ void CRepeaterHandler::resolveUserInt(const wxString& user, const wxString& repe m_g2User.Clear(); m_g2Repeater.Clear(); m_g2Gateway.Clear(); - m_g2Port = G2_DV_PORT; delete m_g2Header; m_g2Header = NULL; @@ -1248,10 +1245,7 @@ void CRepeaterHandler::resolveRepeaterInt(const wxString& repeater, const wxStri m_g2Repeater = repeater; m_g2Gateway = gateway; - CRepeaterData* rpt = m_cache->findRepeater(repeater); - m_g2Port = rpt != NULL ? rpt->getG2Port() : G2_DV_PORT; - - m_g2Header->setDestination(m_g2Address, m_g2Port); + m_g2Header->setDestination(m_g2Address, G2_DV_PORT); m_g2Header->setRepeaters(m_g2Gateway, m_g2Repeater); m_g2Handler->writeHeader(*m_g2Header); @@ -1264,7 +1258,6 @@ void CRepeaterHandler::resolveRepeaterInt(const wxString& repeater, const wxStri m_g2User.Clear(); m_g2Repeater.Clear(); m_g2Gateway.Clear(); - m_g2Port = G2_DV_PORT; delete m_g2Header; m_g2Header = NULL; @@ -1466,7 +1459,6 @@ void CRepeaterHandler::clockInt(unsigned int ms) m_g2User.Clear(); m_g2Repeater.Clear(); m_g2Gateway.Clear(); - m_g2Port = G2_DV_PORT; delete m_g2Header; m_g2Header = NULL; @@ -1991,8 +1983,7 @@ void CRepeaterHandler::g2CommandHandler(const wxString& callsign, const wxString m_g2Status = G2_OK; m_g2Address = data->getAddress(); m_g2Gateway = data->getGateway(); - m_g2Port = data->getG2Port(); - header.setDestination(m_g2Address, m_g2Port); + header.setDestination(m_g2Address, G2_DV_PORT); header.setRepeaters(m_g2Gateway, m_g2Repeater); m_g2Handler->writeHeader(header); delete data; @@ -2034,9 +2025,7 @@ void CRepeaterHandler::g2CommandHandler(const wxString& callsign, const wxString m_g2Address = data->getAddress(); m_g2Repeater = data->getRepeater(); m_g2Gateway = data->getGateway(); - m_g2Port = data->getG2Port(); - wxLogMessage(wxT("%s is trying to G2 route to gateway %s on port %d"), user.c_str(), m_g2Gateway.c_str(), m_g2Port); - header.setDestination(m_g2Address, m_g2Port); + header.setDestination(m_g2Address, G2_DV_PORT); header.setRepeaters(m_g2Gateway, m_g2Repeater); m_g2Handler->writeHeader(header); diff --git a/Common/RepeaterHandler.h b/Common/RepeaterHandler.h index df16c5a..05baca2 100644 --- a/Common/RepeaterHandler.h +++ b/Common/RepeaterHandler.h @@ -232,7 +232,6 @@ private: wxString m_g2Gateway; CHeaderData* m_g2Header; in_addr m_g2Address; - unsigned int m_g2Port; // Link info LINK_STATUS m_linkStatus; diff --git a/StarNetServer/StarNetServerThread.cpp b/StarNetServer/StarNetServerThread.cpp index 7b31214..2b86002 100644 --- a/StarNetServer/StarNetServerThread.cpp +++ b/StarNetServer/StarNetServerThread.cpp @@ -505,15 +505,15 @@ void CStarNetServerThread::processDCS() void CStarNetServerThread::processG2() { - in_addr incomingAddress; - unsigned int incomingPort; - for (;;) { - G2_TYPE type = m_g2Handler->read(incomingAddress, incomingPort); + G2_TYPE type = m_g2Handler->read(); switch (type) { + case GT_NONE: + return; + case GT_HEADER: { - CHeaderData* header = m_g2Handler->readHeader(incomingAddress, incomingPort); + CHeaderData* header = m_g2Handler->readHeader(); if (header != NULL) { // wxLogMessage(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); CG2Handler::process(*header); @@ -523,17 +523,13 @@ void CStarNetServerThread::processG2() break; case GT_AMBE: { - CAMBEData* data = m_g2Handler->readAMBE(incomingAddress, incomingPort); + CAMBEData* data = m_g2Handler->readAMBE(); if (data != NULL) { CG2Handler::process(*data); delete data; } } break; - - default: - //Probably someone punching a UDP hole to us - return; } } } diff --git a/ircDDBGateway/IRCDDBGatewayThread.cpp b/ircDDBGateway/IRCDDBGatewayThread.cpp index a15819a..9da5110 100644 --- a/ircDDBGateway/IRCDDBGatewayThread.cpp +++ b/ircDDBGateway/IRCDDBGatewayThread.cpp @@ -72,7 +72,6 @@ m_dextraPool(NULL), m_dplusPool(NULL), m_dcsPool(NULL), m_g2Handler(NULL), -m_natTraversal(NULL), m_aprsWriter(NULL), m_irc(NULL), m_cache(), @@ -218,11 +217,6 @@ void CIRCDDBGatewayThread::run() m_g2Handler = NULL; } - if(m_g2Handler != NULL) { - m_natTraversal = new CNatTraversalHandler(); - m_natTraversal->setG2Handler(m_g2Handler); - } - // Wait here until we have the essentials to run while (!m_killed && (m_dextraPool == NULL || m_dplusPool == NULL || m_dcsPool == NULL || m_g2Handler == NULL || (m_icomRepeaterHandler == NULL && m_hbRepeaterHandler == NULL && m_dummyRepeaterHandler == NULL) || m_gatewayCallsign.IsEmpty())) ::wxMilliSleep(500UL); // 1/2 sec @@ -725,7 +719,7 @@ void CIRCDDBGatewayThread::processIrcDDB() if (!address.IsEmpty()) { wxLogMessage(wxT("USER: %s %s %s %s"), user.c_str(), repeater.c_str(), gateway.c_str(), address.c_str()); m_cache.updateUser(user, repeater, gateway, address, timestamp, DP_DEXTRA, false, false); - m_natTraversal->traverseNatG2(address); + m_g2Handler->punchUDPHole(address); } else { wxLogMessage(wxT("USER: %s NOT FOUND"), user.c_str()); } @@ -738,16 +732,14 @@ void CIRCDDBGatewayThread::processIrcDDB() if (!res) break; + CRepeaterHandler::resolveRepeater(repeater, gateway, address, DP_DEXTRA); if (!address.IsEmpty()) { wxLogMessage(wxT("REPEATER: %s %s %s"), repeater.c_str(), gateway.c_str(), address.c_str()); m_cache.updateRepeater(repeater, gateway, address, DP_DEXTRA, false, false); - m_natTraversal->traverseNatG2(address); + m_g2Handler->punchUDPHole(address); } else { wxLogMessage(wxT("REPEATER: %s NOT FOUND"), repeater.c_str()); } - - //resolve after updating cache so CRepeaterHandler gets latest g2 port from cache - CRepeaterHandler::resolveRepeater(repeater, gateway, address, DP_DEXTRA); } break; @@ -762,7 +754,7 @@ void CIRCDDBGatewayThread::processIrcDDB() if (!address.IsEmpty()) { wxLogMessage(wxT("GATEWAY: %s %s"), gateway.c_str(), address.c_str()); m_cache.updateGateway(gateway, address, DP_DEXTRA, false, false); - m_natTraversal->traverseNatG2(address); + m_g2Handler->punchUDPHole(address); } else { wxLogMessage(wxT("GATEWAY: %s NOT FOUND"), gateway.c_str()); } @@ -1033,29 +1025,22 @@ void CIRCDDBGatewayThread::processDCS() void CIRCDDBGatewayThread::processG2() { - in_addr remoteAddress; - unsigned int remotePort; - for (;;) { - G2_TYPE type = m_g2Handler->read(remoteAddress, remotePort); + G2_TYPE type = m_g2Handler->read(); switch (type) { case GT_HEADER: { - CHeaderData* header = m_g2Handler->readHeader(remoteAddress, remotePort); - + CHeaderData* header = m_g2Handler->readHeader(); if (header != NULL) { // wxLogMessage(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3()); CG2Handler::process(*header); - m_cache.updateGatewayG2(header-> getRptCall1(), remoteAddress, remotePort); - delete header; } } break; case GT_AMBE: { - CAMBEData* data = m_g2Handler->readAMBE(remoteAddress, remotePort); - + CAMBEData* data = m_g2Handler->readAMBE(); if (data != NULL) { CG2Handler::process(*data); delete data; @@ -1064,12 +1049,6 @@ void CIRCDDBGatewayThread::processG2() break; default: - //Probably someone punching a UDP hole to us, keep track of that - if(remoteAddress.s_addr != INADDR_NONE && remotePort > 0 && remotePort < 65536) { - wxLogMessage(wxT("Incoming G2 UDP traversal from %s:%i"), ::inet_ntoa(remoteAddress), remotePort); - m_cache.updateGatewayG2(wxT(""), remoteAddress, remotePort); - } - return; } } diff --git a/ircDDBGateway/IRCDDBGatewayThread.h b/ircDDBGateway/IRCDDBGatewayThread.h index 6862b63..e3cc863 100644 --- a/ircDDBGateway/IRCDDBGatewayThread.h +++ b/ircDDBGateway/IRCDDBGatewayThread.h @@ -28,7 +28,6 @@ #include "IRCDDBGatewayStatusData.h" #include "DCSProtocolHandlerPool.h" #include "G2ProtocolHandler.h" -#include "NatTraversalHandler.h" #include "RemoteHandler.h" #include "CacheManager.h" #include "CallsignList.h" @@ -93,7 +92,6 @@ private: CDPlusProtocolHandlerPool* m_dplusPool; CDCSProtocolHandlerPool* m_dcsPool; CG2ProtocolHandler* m_g2Handler; - CNatTraversalHandler* m_natTraversal; CAPRSWriter* m_aprsWriter; CIRCDDB* m_irc; CCacheManager m_cache;