|
|
|
|
@ -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);
|
|
|
|
|
}
|