#5 Reeanbale NatTraversal

pull/32/head
Geoffrey Merck 4 years ago
parent 1be24fa41d
commit 0d0efba655

@ -7,7 +7,20 @@
}
],
"files.associations": {
"new": "cpp"
"new": "cpp",
"exception": "cpp",
"*.tcc": "cpp",
"typeinfo": "cpp",
"limits": "cpp",
"tuple": "cpp",
"bitset": "cpp",
"fstream": "cpp",
"istream": "cpp",
"mutex": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stop_token": "cpp",
"streambuf": "cpp"
},
"editor.tokenColorCustomizations": {
"textMateRules": [

16
.vscode/tasks.json vendored

@ -8,9 +8,13 @@
"type": "shell",
"command": "make",
"args": [
"-j3", "ENABLE_DEBUG=1"
"-j3",
"ENABLE_DEBUG=1"
],
"group": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
@ -19,12 +23,10 @@
"command": "make",
"args": [
"-j3",
"tests", "ENABLE_DEBUG=1"
"tests",
"ENABLE_DEBUG=1"
],
"group": {
"kind": "build",
"isDefault": true
},
"group": "build",
"problemMatcher": []
}
]

@ -733,6 +733,7 @@ void CDStarGatewayThread::processIrcDDB()
m_statusTimer2.start();
}
// Process incoming ircDDB messages, updating the caches
for (;;) {
IRCDDB_RESPONSE_TYPE type = m_irc->getMessageType();

@ -206,3 +206,5 @@ bool CG2Handler::clockInt(unsigned int ms)
return false;
}

@ -41,7 +41,7 @@ m_port(0U)
CG2ProtocolHandler::~CG2ProtocolHandler()
{
delete[] m_buffer;
portmap.clear();
m_portmap.clear();
}
bool CG2ProtocolHandler::open()
@ -59,8 +59,8 @@ bool CG2ProtocolHandler::writeHeader(const CHeaderData& header)
#endif
in_addr addr = header.getYourAddress();
auto found = portmap.find(addr.s_addr);
unsigned int port = (portmap.end()==found) ? header.getYourPort() : found->second;
auto found = m_portmap.find(addr.s_addr);
unsigned int port = (m_portmap.end()==found) ? header.getYourPort() : found->second;
for (unsigned int i = 0U; i < 5U; i++) {
bool res = m_socket.write(buffer, length, addr, port);
@ -81,8 +81,8 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data)
#endif
in_addr addr = data.getYourAddress();
auto found = portmap.find(addr.s_addr);
unsigned int port = (portmap.end()==found) ? data.getYourPort() : found->second;
auto found = m_portmap.find(addr.s_addr);
unsigned int port = (m_portmap.end()==found) ? data.getYourPort() : found->second;
return m_socket.write(buffer, length, addr, port);
}
@ -110,13 +110,13 @@ bool CG2ProtocolHandler::readPackets()
m_length = length;
// save the incoming port (this is to enable mobile hotspots)
if (portmap.end() == portmap.find(m_address.s_addr)) {
if (m_portmap.end() == m_portmap.find(m_address.s_addr)) {
CLog::logInfo("new address %s on port %u\n", inet_ntoa(m_address), m_port);
portmap[m_address.s_addr] = m_port;
m_portmap[m_address.s_addr] = m_port;
} else {
if (portmap[m_address.s_addr] != m_port) {
CLog::logInfo("new port for %s is %u, was %u\n", inet_ntoa(m_address), m_port, portmap[m_address.s_addr]);
portmap[m_address.s_addr] = m_port;
if (m_portmap[m_address.s_addr] != m_port) {
CLog::logInfo("new port for %s is %u, was %u\n", inet_ntoa(m_address), m_port, m_portmap[m_address.s_addr]);
m_portmap[m_address.s_addr] = m_port;
}
}
@ -170,3 +170,15 @@ void CG2ProtocolHandler::close()
{
m_socket.close();
}
void CG2ProtocolHandler::traverseNat(const std::string& address)
{
unsigned char buffer[1];
::memset(buffer, 0, 1);
in_addr addr = CUDPReaderWriter::lookup(address);
//wxLogError(wxT("Punching hole to %s"), address.mb_str());
m_socket.write(buffer, 1, addr, G2_DV_PORT);
}

@ -47,9 +47,10 @@ public:
CAMBEData* readAMBE();
void close();
void traverseNat(const std::string& address);
private:
std::unordered_map<uint32_t, unsigned int> portmap;
std::unordered_map<uint32_t, unsigned int> m_portmap;
CUDPReaderWriter m_socket;
G2_TYPE m_type;

@ -634,6 +634,8 @@ bool IRCDDBApp::findUser(const std::string& usrCall)
return true;
}
void IRCDDBApp::msgChannel(IRCMessage *m)
{
if (0==m->getPrefixNick().compare(0, 2, "s-") && m->numParams>=2) // server msg

@ -67,6 +67,8 @@ public:
bool findRepeater(const std::string& s);
bool findGateway(const std::string& s);
bool notifyRepeaterNatTraversal(const std::string& repeater);
bool sendHeard(const std::string& myCall, const std::string& myCallExt, const std::string& yourCall, const std::string& rpt1, const std::string& rpt2, unsigned char flag1,
unsigned char flag2, unsigned char flag3, const std::string& destination, const std::string& tx_msg, const std::string& tx_stats);

@ -400,7 +400,7 @@ bool CIRCDDBClient::receiveUser(std::string& userCallsign, std::string& repeater
address = m->getParam(3);
timeStamp = m->getParam(4);
CLog::logTrace("IRC Receive User %s %s %s %s %s", userCallsign.c_str(), repeaterCallsign.c_str(), gatewayCallsign.c_str(), address.c_str(), timeStamp.c_str());
//CLog::logTrace("IRC Receive User %s %s %s %s %s", userCallsign.c_str(), repeaterCallsign.c_str(), gatewayCallsign.c_str(), address.c_str(), timeStamp.c_str());
delete m;
return true;

@ -1,5 +1,6 @@
/*
* 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
@ -16,8 +17,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if defined(ENABLE_NAT_TRAVERSAL)
#include "NatTraversalHandler.h"
const unsigned int CACHE_SIZE = 500U;
@ -31,8 +30,10 @@ m_g2Handler(NULL)
CNatTraversalHandler::~CNatTraversalHandler()
{
for (CNatTraversalCache_t::iterator it = m_g2cache.begin(); it != m_g2cache.end(); ++it)
for (auto it = m_g2cache.begin(); it != m_g2cache.end(); ++it)
delete it->second;
m_g2cache.clear();
}
void CNatTraversalHandler::setG2Handler(CG2ProtocolHandler * handler)
@ -40,7 +41,7 @@ void CNatTraversalHandler::setG2Handler(CG2ProtocolHandler * handler)
m_g2Handler = handler;
}
void CNatTraversalHandler::traverseNatG2(const wxString& address)
void CNatTraversalHandler::traverseNatG2(const std::string& address)
{
if(m_g2Handler != NULL){
CNatTraversalRecord* record = m_g2cache[address];
@ -57,5 +58,3 @@ void CNatTraversalHandler::traverseNatG2(const wxString& address)
}
}
}
#endif

@ -1,5 +1,6 @@
/*
* 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
@ -16,7 +17,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if defined(ENABLE_NAT_TRAVERSAL)
#ifndef NatTraversalHandler_H
#define NatTraversalHandler_H
@ -24,7 +24,8 @@
#include "G2ProtocolHandler.h"
#include <wx/wx.h>
#include <string>
#include <unordered_map>
#include <ctime>
enum NAT_TRAVERSAL_TYPE {
@ -36,7 +37,7 @@ enum NAT_TRAVERSAL_TYPE {
class CNatTraversalRecord {
public:
CNatTraversalRecord(const wxString& address) :
CNatTraversalRecord(const std::string& address) :
m_address(address),
m_timestamp(0)
{
@ -53,12 +54,10 @@ public:
}
private:
wxString m_address;
std::string 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
*/
@ -68,13 +67,11 @@ public:
~CNatTraversalHandler();
void setG2Handler(CG2ProtocolHandler* handler);
void traverseNatG2(const wxString& address);
void traverseNatG2(const std::string& address);
private:
CNatTraversalCache_t m_g2cache;
std::unordered_map<std::string, CNatTraversalRecord*> m_g2cache;
CG2ProtocolHandler* m_g2Handler;
};
#endif
#endif
Loading…
Cancel
Save

Powered by TurnKey Linux.