Remove the xreflector callsign server.

This commit is contained in:
Jonathan Naylor 2018-09-19 21:36:55 +01:00
parent 25f135b923
commit 4550bf73a3
6 changed files with 1 additions and 246 deletions

View file

@ -1,173 +0,0 @@
/*
* Copyright (C) 2012,2013,2014 by Jonathan Naylor G4KLX
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "TCPReaderWriterClient.h"
#include "CallsignServer.h"
#include "DStarDefines.h"
#include "Utils.h"
#include "Defs.h"
const wxString CALLSERVER_HOSTNAME = wxT("dns.xreflector.net");
const unsigned int CALLSERVER_PORT = 20001U;
const unsigned int TCP_TIMEOUT = 10U;
CCallsignServer::CCallsignServer(const wxString& callsign, const wxString& address, CCacheManager* cache) :
wxThread(wxTHREAD_JOINABLE),
m_callsign(callsign),
m_address(address),
m_cache(cache),
m_timer(1U, 1U * 3600U), // 1 hour
m_killed(false)
{
wxASSERT(!callsign.IsEmpty());
wxASSERT(cache != NULL);
}
CCallsignServer::~CCallsignServer()
{
}
void CCallsignServer::start()
{
process(CALLSERVER_HOSTNAME, CALLSERVER_PORT);
Create();
Run();
}
void* CCallsignServer::Entry()
{
wxLogMessage(wxT("Starting the Callsign Server thread"));
m_timer.start();
try {
while (!m_killed) {
if (m_timer.hasExpired()) {
process(CALLSERVER_HOSTNAME, CALLSERVER_PORT);
m_timer.start();
}
Sleep(1000UL);
m_timer.clock();
}
}
catch (std::exception& e) {
wxString message(e.what(), wxConvLocal);
wxLogError(wxT("Exception raised in the Callsign Server thread - \"%s\""), message.c_str());
}
catch (...) {
wxLogError(wxT("Unknown exception raised in the Callsign Server thread"));
}
wxLogMessage(wxT("Stopping the Callsign Server thread"));
return NULL;
}
void CCallsignServer::stop()
{
m_killed = true;
Wait();
}
void CCallsignServer::process(const wxString& hostname, unsigned int port)
{
CTCPReaderWriterClient socket(hostname, port, m_address);
bool ret = socket.open();
if (!ret) {
wxLogMessage(wxT("Cannot connect to %s"), hostname.c_str());
return;
}
// Space for 5000 entries
unsigned int length = 5000U * (6U + 1U + 15U + 1U);
unsigned char* buffer = new unsigned char[length + 1U];
::memset(buffer, ' ', 29U);
for (unsigned int i = 0U; i < m_callsign.Len() && i < LONG_CALLSIGN_LENGTH - 1U; i++)
buffer[i + 0U] = m_callsign.GetChar(i);
::memcpy(buffer + 9U, "ircDDB Gateway", 14U);
socket.write(buffer, 29U);
unsigned int offset = 0U;
int n = socket.read(buffer, length, TCP_TIMEOUT);
if (n >= 0)
offset += n;
while (n >= 0 && offset < length) {
n = socket.read(buffer + offset, length - offset, TCP_TIMEOUT);
if (n == 0)
Sleep(TCP_TIMEOUT * 1000UL);
else if (n > 0)
offset += n;
}
buffer[offset] = 0x00U;
unsigned int count = 0U;
char* p = (char*)buffer;
for (;;) {
// Split into lines
char* p1 = ::strchr(p, 0x0A);
if (p1 != NULL)
*p1 = 0x00;
if (::strncmp(p, "DCS", 3U) == 0) {
char* p2 = ::strtok(p, " \t\r\n");
char* p3 = ::strtok(NULL, " \t\r\n");
if (p2 != NULL && p3 != NULL) {
wxString name = wxString(p2, wxConvLocal);
wxString address = wxString(p3, wxConvLocal);
if (!address.IsSameAs(wxT("0.0.0.0"))) {
wxLogMessage(wxT("DCS: %s\t%s"), name.c_str(), address.c_str());
name.resize(LONG_CALLSIGN_LENGTH - 1U, wxT(' '));
name.Append(wxT("G"));
m_cache->updateGateway(name, address, DP_DCS, false, true);
count++;
}
}
}
if (p1 == NULL)
break;
p = p1 + 1U;
}
wxLogMessage(wxT("Registered with %s using callsign %s"), hostname.c_str(), m_callsign.Left(LONG_CALLSIGN_LENGTH - 1U).c_str());
wxLogMessage(wxT("Loaded %u DCS reflectors from %s"), count, hostname.c_str());
delete[] buffer;
socket.close();
}

View file

@ -1,54 +0,0 @@
/*
* Copyright (C) 2012,2014 by Jonathan Naylor G4KLX
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CallsignServer_H
#define CallsignServer_H
#include "CacheManager.h"
#include "Timer.h"
#include <wx/wx.h>
#if defined(__WINDOWS__)
#include "Inaddr.h"
#else
#include <netinet/in.h>
#endif
class CCallsignServer : public wxThread {
public:
CCallsignServer(const wxString& callsign, const wxString& address, CCacheManager* cache);
virtual ~CCallsignServer();
virtual void start();
virtual void* Entry();
virtual void stop();
private:
wxString m_callsign;
wxString m_address;
CCacheManager* m_cache;
CTimer m_timer;
bool m_killed;
void process(const wxString& hostname, unsigned int port);
};
#endif

View file

@ -154,7 +154,6 @@
<ClCompile Include="AudioUnit.cpp" />
<ClCompile Include="CacheManager.cpp" />
<ClCompile Include="CallsignList.cpp" />
<ClCompile Include="CallsignServer.cpp" />
<ClCompile Include="CCITTChecksum.cpp" />
<ClCompile Include="ConnectData.cpp" />
<ClCompile Include="DCSHandler.cpp" />
@ -219,7 +218,6 @@
<ClInclude Include="AudioUnit.h" />
<ClInclude Include="CacheManager.h" />
<ClInclude Include="CallsignList.h" />
<ClInclude Include="CallsignServer.h" />
<ClInclude Include="CCITTChecksum.h" />
<ClInclude Include="ConnectData.h" />
<ClInclude Include="DCSHandler.h" />

View file

@ -35,9 +35,6 @@
<ClCompile Include="CallsignList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CallsignServer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="CCITTChecksum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -226,9 +223,6 @@
<ClInclude Include="CallsignList.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CallsignServer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="CCITTChecksum.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -1,5 +1,5 @@
OBJECTS = AMBEData.o AnnouncementUnit.o APRSCollector.o APRSWriter.o APRSWriterThread.o AudioUnit.o CacheManager.o CallsignList.o \
CallsignServer.o CCITTChecksum.o ConnectData.o DCSHandler.o DCSProtocolHandler.o \
CCITTChecksum.o ConnectData.o DCSHandler.o DCSProtocolHandler.o \
DCSProtocolHandlerPool.o DDData.o DDHandler.o DExtraHandler.o DExtraProtocolHandler.o DExtraProtocolHandlerPool.o \
DPlusAuthenticator.o DPlusHandler.o DPlusProtocolHandler.o DPlusProtocolHandlerPool.o DRATSServer.o DTMF.o \
DummyRepeaterProtocolHandler.o DVTOOLFileReader.o EchoUnit.o G2Handler.o G2ProtocolHandler.o GatewayCache.o \

View file

@ -20,7 +20,6 @@
#include "IRCDDBGatewayDefs.h"
#include "RepeaterHandler.h"
#include "StarNetHandler.h"
#include "CallsignServer.h"
#include "DExtraHandler.h"
#include "DPlusHandler.h"
#include "HeaderLogger.h"
@ -320,12 +319,6 @@ void CIRCDDBGatewayThread::run()
m_statusFileTimer.start();
CCallsignServer* server = NULL;
if (m_dextraEnabled || m_dcsEnabled) {
server = new CCallsignServer(m_gatewayCallsign, m_gatewayAddress, &m_cache);
server->start();
}
wxStopWatch stopWatch;
stopWatch.Start();
@ -413,9 +406,6 @@ void CIRCDDBGatewayThread::run()
if (m_ddModeEnabled)
CDDHandler::finalise();
if (server != NULL)
server->stop();
m_dextraPool->close();
delete m_dextraPool;