From d1c55b93944997ec1892bac8bc574bc714e8f847 Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Fri, 2 Nov 2018 09:17:18 +0100 Subject: [PATCH] Add UDP Hole Punching for G2 --- Common/G2ProtocolHandler.cpp | 12 ++++++++++++ Common/G2ProtocolHandler.h | 2 ++ ircDDBGateway/IRCDDBGatewayThread.cpp | 3 +++ 3 files changed, 17 insertions(+) diff --git a/Common/G2ProtocolHandler.cpp b/Common/G2ProtocolHandler.cpp index 8f68b98..e1e49af 100644 --- a/Common/G2ProtocolHandler.cpp +++ b/Common/G2ProtocolHandler.cpp @@ -144,6 +144,18 @@ CAMBEData* CG2ProtocolHandler::readAMBE() return data; } +void CG2ProtocolHandler::PunchUDPHole(const wxString& 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); +} + void CG2ProtocolHandler::close() { m_socket.close(); diff --git a/Common/G2ProtocolHandler.h b/Common/G2ProtocolHandler.h index 3a87834..b6ca32e 100644 --- a/Common/G2ProtocolHandler.h +++ b/Common/G2ProtocolHandler.h @@ -52,6 +52,8 @@ public: CHeaderData* readHeader(); CAMBEData* readAMBE(); + void PunchUDPHole(const wxString& addr); + void close(); private: diff --git a/ircDDBGateway/IRCDDBGatewayThread.cpp b/ircDDBGateway/IRCDDBGatewayThread.cpp index 268a04d..3ce9762 100644 --- a/ircDDBGateway/IRCDDBGatewayThread.cpp +++ b/ircDDBGateway/IRCDDBGatewayThread.cpp @@ -719,6 +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_g2Handler->PunchUDPHole(address); } else { wxLogMessage(wxT("USER: %s NOT FOUND"), user.c_str()); } @@ -735,6 +736,7 @@ void CIRCDDBGatewayThread::processIrcDDB() 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_g2Handler->PunchUDPHole(address); } else { wxLogMessage(wxT("REPEATER: %s NOT FOUND"), repeater.c_str()); } @@ -752,6 +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_g2Handler->PunchUDPHole(address); } else { wxLogMessage(wxT("GATEWAY: %s NOT FOUND"), gateway.c_str()); }