#5 Remove nat traversal handler

pull/32/head
Geoffrey Merck 4 years ago
parent 5fb9b57626
commit a150b9d35c

@ -76,7 +76,6 @@ m_dextraPool(NULL),
m_dplusPool(NULL),
m_dcsPool(NULL),
m_g2Handler(NULL),
m_natTraversal(NULL),
m_aprsWriter(NULL),
m_irc(NULL),
m_cache(),
@ -207,11 +206,6 @@ void* CDStarGatewayThread::Entry()
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.empty()))
::std::this_thread::sleep_for(std::chrono::milliseconds(500UL)); // 1/2 sec

@ -37,7 +37,6 @@
#include "Timer.h"
#include "Defs.h"
#include "Thread.h"
#include "NatTraversalHandler.h"
class CDStarGatewayThread : public CThread{
public:
@ -104,7 +103,6 @@ private:
CDPlusProtocolHandlerPool* m_dplusPool;
CDCSProtocolHandlerPool* m_dcsPool;
CG2ProtocolHandler* m_g2Handler;
CNatTraversalHandler* m_natTraversal;
CAPRSHandler* m_aprsWriter;
CIRCDDB* m_irc;
CCacheManager m_cache;

@ -1,60 +0,0 @@
/*
* Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA
*
* 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 (auto it = m_g2cache.begin(); it != m_g2cache.end(); ++it)
delete it->second;
m_g2cache.clear();
}
void CNatTraversalHandler::setG2Handler(CG2ProtocolHandler * handler)
{
m_g2Handler = handler;
}
void CNatTraversalHandler::traverseNatG2(const std::string& 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);
}
}
}

@ -1,77 +0,0 @@
/*
* Copyright (C) 2010,2011,2012,2013,2014,2015,2016,2017,2018 by Jonathan Naylor G4KLX
* Copyright (c) 2021-2022 by Geoffrey Merck F4FXL / KC3FRA
*
* 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 <string>
#include <unordered_map>
#include <ctime>
enum NAT_TRAVERSAL_TYPE {
NTT_G2,
//NTT_DEXTRA
//NTT_DCS
//NTT_DPLUS
};
class CNatTraversalRecord {
public:
CNatTraversalRecord(const std::string& 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:
std::string m_address;
std::time_t m_timestamp;
};
/*
* 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 std::string& address);
private:
std::unordered_map<std::string, CNatTraversalRecord*> m_g2cache;
CG2ProtocolHandler* m_g2Handler;
};
#endif
Loading…
Cancel
Save

Powered by TurnKey Linux.