From 0e9c1bb2f254e8dded48053f18391e3de68954ff Mon Sep 17 00:00:00 2001 From: Geoffrey Merck F4FXL - KC3FRA Date: Wed, 21 Nov 2018 20:42:52 +0100 Subject: [PATCH] More meaningful variaable names ans recognize incoming UDP punch --- Common/G2ProtocolHandler.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Common/G2ProtocolHandler.cpp b/Common/G2ProtocolHandler.cpp index 3320b5d..84040eb 100644 --- a/Common/G2ProtocolHandler.cpp +++ b/Common/G2ProtocolHandler.cpp @@ -74,31 +74,36 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data) return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort()); } -G2_TYPE CG2ProtocolHandler::read(in_addr& incomingAddress, unsigned int& incomingPort) +G2_TYPE CG2ProtocolHandler::read(in_addr& remoteAddress, unsigned int& remotePort) { 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(incomingAddress, incomingPort); + res = readPackets(remoteAddress, remotePort); return m_type; } -bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& incomingPort) +bool CG2ProtocolHandler::readPackets(in_addr& remoteAddress, unsigned int& remotePort) { m_type = GT_NONE; - - incomingPort = 0; + remotePort = 0; // No more data? - int length = m_socket.read(m_buffer, BUFFER_LENGTH, incomingAddress, incomingPort); + int length = m_socket.read(m_buffer, BUFFER_LENGTH, remoteAddress, remotePort); if (length <= 0) return false; + if(length >= 1) + wxLogMessage(wxT("bla %i"), length); + 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? @@ -111,7 +116,7 @@ bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& inc } } -CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned int incomingPort) +CHeaderData* CG2ProtocolHandler::readHeader(in_addr remoteAddress, unsigned int remotePort) { if (m_type != GT_HEADER) return NULL; @@ -119,7 +124,7 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned in CHeaderData* header = new CHeaderData; // G2 checksums are unreliable - bool res = header->setG2Data(m_buffer, m_length, false, incomingAddress, incomingPort); + bool res = header->setG2Data(m_buffer, m_length, false, remoteAddress, remotePort); if (!res) { delete header; return NULL; @@ -128,14 +133,15 @@ CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned in return header; } -CAMBEData* CG2ProtocolHandler::readAMBE(in_addr incomingAddress, unsigned int incomingPort) +CAMBEData* CG2ProtocolHandler::readAMBE(in_addr remoteAddress, unsigned int remotePort) { if (m_type != GT_AMBE) return NULL; CAMBEData* data = new CAMBEData; - bool res = data->setG2Data(m_buffer, m_length, incomingAddress, incomingPort); + bool res = data->setG2Data(m_buffer, m_length, remoteAddress, remotePort +); if (!res) { delete data; return NULL;