mirror of
https://github.com/g4klx/ircDDBGateway.git
synced 2026-01-03 23:09:57 +01:00
Unfix address and port
This commit is contained in:
parent
05e66c15d1
commit
21b1b967be
|
|
@ -29,9 +29,7 @@ CG2ProtocolHandler::CG2ProtocolHandler(unsigned int port, const wxString& addr)
|
|||
m_socket(addr, port),
|
||||
m_type(GT_NONE),
|
||||
m_buffer(NULL),
|
||||
m_length(0U),
|
||||
m_address(),
|
||||
m_port(0U)
|
||||
m_length(0U)
|
||||
{
|
||||
m_buffer = new unsigned char[BUFFER_LENGTH];
|
||||
}
|
||||
|
|
@ -76,23 +74,23 @@ bool CG2ProtocolHandler::writeAMBE(const CAMBEData& data)
|
|||
return m_socket.write(buffer, length, data.getYourAddress(), data.getYourPort());
|
||||
}
|
||||
|
||||
G2_TYPE CG2ProtocolHandler::read()
|
||||
G2_TYPE CG2ProtocolHandler::read(in_addr& incomingAddress, unsigned int& incomingPort)
|
||||
{
|
||||
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();
|
||||
res = readPackets(incomingAddress, incomingPort);
|
||||
|
||||
return m_type;
|
||||
}
|
||||
|
||||
bool CG2ProtocolHandler::readPackets()
|
||||
bool CG2ProtocolHandler::readPackets(in_addr& incomingAddress, unsigned int& incomingPort)
|
||||
{
|
||||
m_type = GT_NONE;
|
||||
|
||||
// No more data?
|
||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, m_address, m_port);
|
||||
int length = m_socket.read(m_buffer, BUFFER_LENGTH, incomingAddress, incomingPort);
|
||||
if (length <= 0)
|
||||
return false;
|
||||
|
||||
|
|
@ -111,7 +109,7 @@ bool CG2ProtocolHandler::readPackets()
|
|||
}
|
||||
}
|
||||
|
||||
CHeaderData* CG2ProtocolHandler::readHeader()
|
||||
CHeaderData* CG2ProtocolHandler::readHeader(in_addr incomingAddress, unsigned int incomingPort)
|
||||
{
|
||||
if (m_type != GT_HEADER)
|
||||
return NULL;
|
||||
|
|
@ -119,7 +117,7 @@ CHeaderData* CG2ProtocolHandler::readHeader()
|
|||
CHeaderData* header = new CHeaderData;
|
||||
|
||||
// G2 checksums are unreliable
|
||||
bool res = header->setG2Data(m_buffer, m_length, false, m_address, m_port);
|
||||
bool res = header->setG2Data(m_buffer, m_length, false, incomingAddress, incomingPort);
|
||||
if (!res) {
|
||||
delete header;
|
||||
return NULL;
|
||||
|
|
@ -128,14 +126,14 @@ CHeaderData* CG2ProtocolHandler::readHeader()
|
|||
return header;
|
||||
}
|
||||
|
||||
CAMBEData* CG2ProtocolHandler::readAMBE()
|
||||
CAMBEData* CG2ProtocolHandler::readAMBE(in_addr incomingAddress, unsigned int incomingPort)
|
||||
{
|
||||
if (m_type != GT_AMBE)
|
||||
return NULL;
|
||||
|
||||
CAMBEData* data = new CAMBEData;
|
||||
|
||||
bool res = data->setG2Data(m_buffer, m_length, m_address, m_port);
|
||||
bool res = data->setG2Data(m_buffer, m_length, incomingAddress, incomingPort);
|
||||
if (!res) {
|
||||
delete data;
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ public:
|
|||
bool writeHeader(const CHeaderData& header);
|
||||
bool writeAMBE(const CAMBEData& data);
|
||||
|
||||
G2_TYPE read();
|
||||
CHeaderData* readHeader();
|
||||
CAMBEData* readAMBE();
|
||||
G2_TYPE read(in_addr& incomingAddress, unsigned int& incomingPort);
|
||||
CHeaderData* readHeader(in_addr incomingAddress, unsigned int incomingPort);
|
||||
CAMBEData* readAMBE(in_addr incomingAddress, unsigned int incomingPort);
|
||||
|
||||
void punchUDPHole(const wxString& addr);
|
||||
|
||||
|
|
@ -61,10 +61,8 @@ private:
|
|||
G2_TYPE m_type;
|
||||
unsigned char* m_buffer;
|
||||
unsigned int m_length;
|
||||
in_addr m_address;
|
||||
unsigned int m_port;
|
||||
|
||||
bool readPackets();
|
||||
bool readPackets(in_addr& incomingAddress, unsigned int& incomingPort);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ public:
|
|||
private:
|
||||
wxString m_gateway;
|
||||
in_addr m_address;
|
||||
|
||||
//the incoming G2 port, usually the default one unless the calling hotspot is behind a NAT, therefore keep track of it and use it to answer back instead of the default one
|
||||
unsigned int m_G2Port;
|
||||
DSTAR_PROTOCOL m_protocol;
|
||||
bool m_addrLock;
|
||||
bool m_protoLock;
|
||||
|
|
|
|||
|
|
@ -505,15 +505,15 @@ void CStarNetServerThread::processDCS()
|
|||
|
||||
void CStarNetServerThread::processG2()
|
||||
{
|
||||
in_addr incomingAddress;
|
||||
unsigned int incomingPort;
|
||||
|
||||
for (;;) {
|
||||
G2_TYPE type = m_g2Handler->read();
|
||||
G2_TYPE type = m_g2Handler->read(incomingAddress, incomingPort);
|
||||
|
||||
switch (type) {
|
||||
case GT_NONE:
|
||||
return;
|
||||
|
||||
case GT_HEADER: {
|
||||
CHeaderData* header = m_g2Handler->readHeader();
|
||||
CHeaderData* header = m_g2Handler->readHeader(incomingAddress, incomingPort);
|
||||
if (header != NULL) {
|
||||
// wxLogMessage(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());
|
||||
CG2Handler::process(*header);
|
||||
|
|
@ -523,13 +523,17 @@ void CStarNetServerThread::processG2()
|
|||
break;
|
||||
|
||||
case GT_AMBE: {
|
||||
CAMBEData* data = m_g2Handler->readAMBE();
|
||||
CAMBEData* data = m_g2Handler->readAMBE(incomingAddress, incomingPort);
|
||||
if (data != NULL) {
|
||||
CG2Handler::process(*data);
|
||||
delete data;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
//Probably someone punching a UDP hole to us
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1025,12 +1025,15 @@ void CIRCDDBGatewayThread::processDCS()
|
|||
|
||||
void CIRCDDBGatewayThread::processG2()
|
||||
{
|
||||
in_addr incomingAddress;
|
||||
unsigned int incomingPort;
|
||||
|
||||
for (;;) {
|
||||
G2_TYPE type = m_g2Handler->read();
|
||||
G2_TYPE type = m_g2Handler->read(incomingAddress, incomingPort);
|
||||
|
||||
switch (type) {
|
||||
case GT_HEADER: {
|
||||
CHeaderData* header = m_g2Handler->readHeader();
|
||||
CHeaderData* header = m_g2Handler->readHeader(incomingAddress, incomingPort);
|
||||
if (header != NULL) {
|
||||
// wxLogMessage(wxT("G2 header - My: %s/%s Your: %s Rpt1: %s Rpt2: %s Flags: %02X %02X %02X"), header->getMyCall1().c_str(), header->getMyCall2().c_str(), header->getYourCall().c_str(), header->getRptCall1().c_str(), header->getRptCall2().c_str(), header->getFlag1(), header->getFlag2(), header->getFlag3());
|
||||
CG2Handler::process(*header);
|
||||
|
|
@ -1040,7 +1043,7 @@ void CIRCDDBGatewayThread::processG2()
|
|||
break;
|
||||
|
||||
case GT_AMBE: {
|
||||
CAMBEData* data = m_g2Handler->readAMBE();
|
||||
CAMBEData* data = m_g2Handler->readAMBE(incomingAddress, incomingPort);
|
||||
if (data != NULL) {
|
||||
CG2Handler::process(*data);
|
||||
delete data;
|
||||
|
|
@ -1049,6 +1052,7 @@ void CIRCDDBGatewayThread::processG2()
|
|||
break;
|
||||
|
||||
default:
|
||||
//Probably someone punching a UDP hole to us
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue