Clean up the gateway configuration.

This commit is contained in:
Jonathan Naylor 2016-10-17 17:33:49 +01:00
parent de483c5f51
commit 728c87a8e7
4 changed files with 62 additions and 83 deletions

View File

@ -45,8 +45,7 @@ m_lookupName(),
m_lookupTime(0U),
m_logFilePath(),
m_logFileRoot(),
m_networkEnabled(false),
m_networkDataPort(0U),
m_networkPort(0U),
m_networkHosts(),
m_networkReloadTime(0U),
m_networkParrotAddress("127.0.0.1"),
@ -120,10 +119,8 @@ bool CConf::read()
else if (::strcmp(key, "FileRoot") == 0)
m_logFileRoot = value;
} else if (section == SECTION_NETWORK) {
if (::strcmp(key, "Enable") == 0)
m_networkEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "DataPort") == 0)
m_networkDataPort = (unsigned int)::atoi(value);
if (::strcmp(key, "Port") == 0)
m_networkPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Hosts") == 0)
m_networkHosts = value;
else if (::strcmp(key, "ReloadTime") == 0)
@ -189,14 +186,9 @@ std::string CConf::getLogFileRoot() const
return m_logFileRoot;
}
bool CConf::getNetworkEnabled() const
unsigned int CConf::getNetworkPort() const
{
return m_networkEnabled;
}
unsigned int CConf::getNetworkDataPort() const
{
return m_networkDataPort;
return m_networkPort;
}
std::string CConf::getNetworkHosts() const

View File

@ -46,8 +46,7 @@ public:
std::string getLogFileRoot() const;
// The Network section
bool getNetworkEnabled() const;
unsigned int getNetworkDataPort() const;
unsigned int getNetworkPort() const;
std::string getNetworkHosts() const;
unsigned int getNetworkReloadTime() const;
std::string getNetworkParrotAddress() const;
@ -69,8 +68,7 @@ private:
std::string m_logFilePath;
std::string m_logFileRoot;
bool m_networkEnabled;
unsigned int m_networkDataPort;
unsigned int m_networkPort;
std::string m_networkHosts;
unsigned int m_networkReloadTime;
std::string m_networkParrotAddress;

View File

@ -161,22 +161,18 @@ void CP25Gateway::run()
unsigned int rptPort = m_conf.getRptPort();
CNetwork localNetwork(m_conf.getMyPort(), m_conf.getCallsign(), false);
ret = localNetwork.open();
if (!ret) {
::LogFinalise();
return;
}
CNetwork* remoteNetwork = NULL;
if (m_conf.getNetworkEnabled()) {
remoteNetwork = new CNetwork(m_conf.getNetworkDataPort(), m_conf.getCallsign(), m_conf.getNetworkDebug());
ret = remoteNetwork->open();
if (!ret) {
localNetwork.close();
::LogFinalise();
return;
}
CNetwork remoteNetwork(m_conf.getNetworkPort(), m_conf.getCallsign(), m_conf.getNetworkDebug());
ret = remoteNetwork.open();
if (!ret) {
localNetwork.close();
::LogFinalise();
return;
}
CReflectors reflectors(m_conf.getNetworkHosts(), m_conf.getNetworkReloadTime());
@ -202,24 +198,22 @@ void CP25Gateway::run()
in_addr currentAddr;
unsigned int currentPort = 0U;
if (remoteNetwork != NULL) {
unsigned int id = m_conf.getNetworkStartup();
if (id != 9999U) {
CP25Reflector* reflector = reflectors.find(id);
if (reflector != NULL) {
currentId = id;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
unsigned int id = m_conf.getNetworkStartup();
if (id != 9999U) {
CP25Reflector* reflector = reflectors.find(id);
if (reflector != NULL) {
currentId = id;
currentAddr = reflector->m_address;
currentPort = reflector->m_port;
pollTimer.start();
lostTimer.start();
pollTimer.start();
lostTimer.start();
remoteNetwork->writePoll(currentAddr, currentPort);
remoteNetwork->writePoll(currentAddr, currentPort);
remoteNetwork->writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
LogMessage("Linked at startup to reflector %u", currentId);
}
LogMessage("Linked at startup to reflector %u", currentId);
}
}
@ -229,33 +223,31 @@ void CP25Gateway::run()
unsigned int port;
// From the reflector to the MMDVM
if (remoteNetwork != NULL) {
unsigned int len = remoteNetwork->readData(buffer, 200U, address, port);
if (len > 0U) {
// If we're linked and it's from the right place, send it on
if (currentId != 9999U && currentAddr.s_addr == address.s_addr && currentPort == port) {
// Don't pass reflector control data through to the MMDVM
if (buffer[0U] != 0xF0U && buffer[0U] != 0xF1U) {
// Rewrite the LCF and the destination TG
if (buffer[0U] == 0x64U) {
buffer[1U] = 0x00U; // LCF is for TGs
} else if (buffer[0U] == 0x65U) {
buffer[1U] = (currentId >> 16) & 0xFFU;
buffer[2U] = (currentId >> 8) & 0xFFU;
buffer[3U] = (currentId >> 0) & 0xFFU;
}
localNetwork.writeData(buffer, len, rptAddr, rptPort);
unsigned int len = remoteNetwork.readData(buffer, 200U, address, port);
if (len > 0U) {
// If we're linked and it's from the right place, send it on
if (currentId != 9999U && currentAddr.s_addr == address.s_addr && currentPort == port) {
// Don't pass reflector control data through to the MMDVM
if (buffer[0U] != 0xF0U && buffer[0U] != 0xF1U) {
// Rewrite the LCF and the destination TG
if (buffer[0U] == 0x64U) {
buffer[1U] = 0x00U; // LCF is for TGs
} else if (buffer[0U] == 0x65U) {
buffer[1U] = (currentId >> 16) & 0xFFU;
buffer[2U] = (currentId >> 8) & 0xFFU;
buffer[3U] = (currentId >> 0) & 0xFFU;
}
// Any network activity is proof that the reflector is alive
lostTimer.start();
localNetwork.writeData(buffer, len, rptAddr, rptPort);
}
// Any network activity is proof that the reflector is alive
lostTimer.start();
}
}
// From the MMDVM to the reflector or control data
unsigned int len = localNetwork.readData(buffer, 200U, address, port);
len = localNetwork.readData(buffer, 200U, address, port);
if (len > 0U) {
if (buffer[0U] == 0x65U) {
dstId = (buffer[1U] << 16) & 0xFF0000U;
@ -276,10 +268,11 @@ void CP25Gateway::run()
std::string callsign = lookup->find(srcId);
LogMessage("Unlinked from reflector %u by %s", currentId, callsign.c_str());
if (remoteNetwork != NULL && currentId != 9999U) {
remoteNetwork->writeUnlink(currentAddr, currentPort);
remoteNetwork->writeUnlink(currentAddr, currentPort);
remoteNetwork->writeUnlink(currentAddr, currentPort);
if (currentId != 9999U) {
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
pollTimer.stop();
lostTimer.stop();
}
@ -296,19 +289,18 @@ void CP25Gateway::run()
std::string callsign = lookup->find(srcId);
LogMessage("Linked to reflector %u by %s", currentId, callsign.c_str());
if (remoteNetwork != NULL) {
remoteNetwork->writePoll(currentAddr, currentPort);
remoteNetwork->writePoll(currentAddr, currentPort);
remoteNetwork->writePoll(currentAddr, currentPort);
pollTimer.start();
lostTimer.start();
}
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
pollTimer.start();
lostTimer.start();
}
}
}
// If we're linked and we have a network, send it on
if (currentId != 9999U && remoteNetwork != NULL) {
if (currentId != 9999U) {
// Rewrite the LCF and the destination TG
if (buffer[0U] == 0x64U) {
buffer[1U] = 0x00U; // LCF is for TGs
@ -318,7 +310,7 @@ void CP25Gateway::run()
buffer[3U] = (currentId >> 0) & 0xFFU;
}
remoteNetwork->writeData(buffer, len, currentAddr, currentPort);
remoteNetwork.writeData(buffer, len, currentAddr, currentPort);
}
}
@ -329,8 +321,8 @@ void CP25Gateway::run()
pollTimer.clock(ms);
if (pollTimer.isRunning() && pollTimer.hasExpired()) {
if (currentId != 9999U && remoteNetwork != NULL)
remoteNetwork->writePoll(currentAddr, currentPort);
if (currentId != 9999U)
remoteNetwork.writePoll(currentAddr, currentPort);
pollTimer.start();
}
@ -340,6 +332,7 @@ void CP25Gateway::run()
LogWarning("No response from %u, unlinking", currentId);
currentId = 9999U;
}
lostTimer.stop();
}
@ -354,10 +347,7 @@ void CP25Gateway::run()
localNetwork.close();
if (remoteNetwork != NULL) {
remoteNetwork->close();
delete remoteNetwork;
}
remoteNetwork.close();
lookup->stop();

View File

@ -14,8 +14,7 @@ FilePath=.
FileRoot=P25Gateway
[Network]
Enable=1
DataPort=42010
Port=42010
Hosts=P25Hosts.txt
ReloadTime=60
ParrotAddress=127.0.0.1