A number of major and minor fixes.

This commit is contained in:
Jonathan Naylor 2018-03-27 08:13:54 +01:00
parent 7a36995e81
commit 7f0b9aae89
15 changed files with 120 additions and 108 deletions

View File

@ -150,7 +150,7 @@ bool CConf::read()
else if (::strcmp(key, "ParrotPort") == 0)
m_networkParrotPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Startup") == 0)
m_networkStartup = (unsigned int)::atoi(value);
m_networkStartup = (unsigned short)::atoi(value);
else if (::strcmp(key, "InactivityTimeout") == 0)
m_networkInactivityTimeout = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0)
@ -258,7 +258,7 @@ unsigned int CConf::getNetworkParrotPort() const
return m_networkParrotPort;
}
unsigned int CConf::getNetworkStartup() const
unsigned short CConf::getNetworkStartup() const
{
return m_networkStartup;
}

View File

@ -58,7 +58,7 @@ public:
unsigned int getNetworkReloadTime() const;
std::string getNetworkParrotAddress() const;
unsigned int getNetworkParrotPort() const;
unsigned int getNetworkStartup() const;
unsigned short getNetworkStartup() const;
unsigned int getNetworkInactivityTimeout() const;
bool getNetworkDebug() const;
@ -87,7 +87,7 @@ private:
unsigned int m_networkReloadTime;
std::string m_networkParrotAddress;
unsigned int m_networkParrotPort;
unsigned int m_networkStartup;
unsigned short m_networkStartup;
unsigned int m_networkInactivityTimeout;
bool m_networkDebug;
};

View File

@ -212,11 +212,11 @@ void CNXDNGateway::run()
unsigned short dstId = 0U;
bool grp = false;
unsigned int currentId = 9999U;
unsigned short currentId = 9999U;
in_addr currentAddr;
unsigned int currentPort = 0U;
unsigned int id = m_conf.getNetworkStartup();
unsigned short id = m_conf.getNetworkStartup();
if (id != 9999U) {
CNXDNReflector* reflector = reflectors.find(id);
if (reflector != NULL) {
@ -228,9 +228,9 @@ void CNXDNGateway::run()
pollTimer.start();
lostTimer.start();
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
LogMessage("Linked at startup to reflector %u", currentId);
}
@ -290,9 +290,9 @@ void CNXDNGateway::run()
if (voice != NULL && dstId == 9999U)
voice->unlinked();
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
inactivityTimer.stop();
pollTimer.stop();
@ -314,9 +314,9 @@ void CNXDNGateway::run()
if (voice != NULL)
voice->linkedTo(currentId);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
inactivityTimer.start();
pollTimer.start();
@ -357,9 +357,9 @@ void CNXDNGateway::run()
if (currentId != 9999U) {
LogMessage("Unlinking from %u due to inactivity", currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
remoteNetwork.writeUnlink(currentAddr, currentPort, currentId);
if (voice != NULL)
voice->unlinked();
@ -375,7 +375,7 @@ void CNXDNGateway::run()
pollTimer.clock(ms);
if (pollTimer.isRunning() && pollTimer.hasExpired()) {
if (currentId != 9999U)
remoteNetwork.writePoll(currentAddr, currentPort);
remoteNetwork.writePoll(currentAddr, currentPort, currentId);
pollTimer.start();
}

View File

@ -79,7 +79,7 @@ bool CNXDNNetwork::writeData(const unsigned char* data, unsigned int length, uns
return m_socket.write(buffer, 43U, address, port);
}
bool CNXDNNetwork::writePoll(const in_addr& address, unsigned int port)
bool CNXDNNetwork::writePoll(const in_addr& address, unsigned int port, unsigned short tg)
{
assert(port > 0U);
@ -94,13 +94,16 @@ bool CNXDNNetwork::writePoll(const in_addr& address, unsigned int port)
for (unsigned int i = 0U; i < 10U; i++)
data[i + 5U] = m_callsign.at(i);
if (m_debug)
CUtils::dump(1U, "NXDN Network Poll Sent", data, 15U);
data[15U] = (tg >> 8) & 0xFFU;
data[16U] = (tg >> 0) & 0xFFU;
return m_socket.write(data, 15U, address, port);
if (m_debug)
CUtils::dump(1U, "NXDN Network Poll Sent", data, 17U);
return m_socket.write(data, 17U, address, port);
}
bool CNXDNNetwork::writeUnlink(const in_addr& address, unsigned int port)
bool CNXDNNetwork::writeUnlink(const in_addr& address, unsigned int port, unsigned short tg)
{
assert(port > 0U);
@ -115,10 +118,13 @@ bool CNXDNNetwork::writeUnlink(const in_addr& address, unsigned int port)
for (unsigned int i = 0U; i < 10U; i++)
data[i + 5U] = m_callsign.at(i);
if (m_debug)
CUtils::dump(1U, "NXDN Network Unlink Sent", data, 15U);
data[15U] = (tg >> 8) & 0xFFU;
data[16U] = (tg >> 0) & 0xFFU;
return m_socket.write(data, 15U, address, port);
if (m_debug)
CUtils::dump(1U, "NXDN Network Unlink Sent", data, 17U);
return m_socket.write(data, 17U, address, port);
}
unsigned int CNXDNNetwork::readData(unsigned char* data, unsigned int length, in_addr& address, unsigned int& port)
@ -130,7 +136,7 @@ unsigned int CNXDNNetwork::readData(unsigned char* data, unsigned int length, in
if (len <= 0)
return 0U;
if ((::memcmp(data, "NXDNP", 5U) == 0 && len == 15) || (::memcmp(data, "NXDND", 5U) == 0 && len == 43)) {
if ((::memcmp(data, "NXDNP", 5U) == 0 && len == 17) || (::memcmp(data, "NXDND", 5U) == 0 && len == 43)) {
if (m_debug)
CUtils::dump(1U, "NXDN Network Data Received", data, len);

View File

@ -33,9 +33,9 @@ public:
bool writeData(const unsigned char* data, unsigned int length, unsigned short srcId, unsigned short dstId, bool grp, const in_addr& address, unsigned int port);
bool writePoll(const in_addr& address, unsigned int port);
bool writePoll(const in_addr& address, unsigned int port, unsigned short tg);
bool writeUnlink(const in_addr& address, unsigned int port);
bool writeUnlink(const in_addr& address, unsigned int port, unsigned short tg);
unsigned int readData(unsigned char* data, unsigned int length, in_addr& address, unsigned int& port);

View File

@ -77,7 +77,7 @@ bool CReflectors::load()
in_addr address = CUDPSocket::lookup(host);
if (address.s_addr != INADDR_NONE) {
CNXDNReflector* refl = new CNXDNReflector;
refl->m_id = (unsigned int)::atoi(p1);
refl->m_id = (unsigned short)::atoi(p1);
refl->m_address = address;
refl->m_port = (unsigned int)::atoi(p3);
@ -106,7 +106,7 @@ bool CReflectors::load()
in_addr address = CUDPSocket::lookup(host);
if (address.s_addr != INADDR_NONE) {
CNXDNReflector* refl = new CNXDNReflector;
refl->m_id = (unsigned int)::atoi(p1);
refl->m_id = (unsigned short)::atoi(p1);
refl->m_address = address;
refl->m_port = (unsigned int)::atoi(p3);
@ -138,7 +138,7 @@ bool CReflectors::load()
return true;
}
CNXDNReflector* CReflectors::find(unsigned int id)
CNXDNReflector* CReflectors::find(unsigned short id)
{
for (std::vector<CNXDNReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it) {
if (id == (*it)->m_id)

View File

@ -28,13 +28,13 @@
class CNXDNReflector {
public:
CNXDNReflector() :
m_id(),
m_id(0U),
m_address(),
m_port(0U)
{
}
unsigned int m_id;
unsigned short m_id;
in_addr m_address;
unsigned int m_port;
};
@ -48,7 +48,7 @@ public:
bool load();
CNXDNReflector* find(unsigned int id);
CNXDNReflector* find(unsigned short id);
void clock(unsigned int ms);

View File

@ -4,7 +4,7 @@ CFLAGS = -g -O3 -Wall -std=c++0x -pthread
LIBS = -lpthread
LDFLAGS = -g
OBJECTS = Network.o NXDNParrot.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o
OBJECTS = NXDNNetwork.o NXDNParrot.o Parrot.o StopWatch.o Thread.o Timer.o UDPSocket.o
all: NXDNParrot

View File

@ -16,31 +16,31 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Network.h"
#include "NXDNNetwork.h"
#include <cstdio>
#include <cassert>
#include <cstring>
CNetwork::CNetwork(unsigned int port) :
CNXDNNetwork::CNXDNNetwork(unsigned int port) :
m_socket(port),
m_address(),
m_port(0U)
{
}
CNetwork::~CNetwork()
CNXDNNetwork::~CNXDNNetwork()
{
}
bool CNetwork::open()
bool CNXDNNetwork::open()
{
::fprintf(stdout, "Opening NXDN network connection\n");
return m_socket.open();
}
bool CNetwork::write(const unsigned char* data, unsigned int length)
bool CNXDNNetwork::write(const unsigned char* data, unsigned int length)
{
if (m_port == 0U)
return true;
@ -50,7 +50,7 @@ bool CNetwork::write(const unsigned char* data, unsigned int length)
return m_socket.write(data, length, m_address, m_port);
}
unsigned int CNetwork::read(unsigned char* data, unsigned int len)
unsigned int CNXDNNetwork::read(unsigned char* data, unsigned int len)
{
in_addr address;
unsigned int port;
@ -61,7 +61,7 @@ unsigned int CNetwork::read(unsigned char* data, unsigned int len)
m_address.s_addr = address.s_addr;
m_port = port;
if (::memcmp(data, "NXDNP", 5U) == 0 && length == 15) { // A poll
if (::memcmp(data, "NXDNP", 5U) == 0 && length == 17) { // A poll
write(data, length);
return 0U;
} else if (::memcmp(data, "NXDND", 5U) == 0 && length == 43) {
@ -71,12 +71,12 @@ unsigned int CNetwork::read(unsigned char* data, unsigned int len)
}
}
void CNetwork::end()
void CNXDNNetwork::end()
{
m_port = 0U;
}
void CNetwork::close()
void CNXDNNetwork::close()
{
m_socket.close();

View File

@ -16,18 +16,18 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef Network_H
#define Network_H
#ifndef NXDNNetwork_H
#define NXDNNetwork_H
#include "UDPSocket.h"
#include <cstdint>
#include <string>
class CNetwork {
class CNXDNNetwork {
public:
CNetwork(unsigned int port);
~CNetwork();
CNXDNNetwork(unsigned int port);
~CNXDNNetwork();
bool open();

View File

@ -16,11 +16,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "StopWatch.h"
#include "NXDNNetwork.h"
#include "NXDNParrot.h"
#include "Parrot.h"
#include "Network.h"
#include "StopWatch.h"
#include "Version.h"
#include "Parrot.h"
#include "Thread.h"
#include "Timer.h"
@ -59,7 +59,7 @@ CNXDNParrot::~CNXDNParrot()
void CNXDNParrot::run()
{
CParrot parrot(180U);
CNetwork network(m_port);
CNXDNNetwork network(m_port);
bool ret = network.open();
if (!ret)

View File

@ -146,7 +146,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Network.h" />
<ClInclude Include="NXDNNetwork.h" />
<ClInclude Include="NXDNParrot.h" />
<ClInclude Include="Parrot.h" />
<ClInclude Include="StopWatch.h" />
@ -156,7 +156,7 @@
<ClInclude Include="Version.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Network.cpp" />
<ClCompile Include="NXDNNetwork.cpp" />
<ClCompile Include="NXDNParrot.cpp" />
<ClCompile Include="Parrot.cpp" />
<ClCompile Include="StopWatch.cpp" />

View File

@ -11,9 +11,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Network.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NXDNParrot.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -35,11 +32,11 @@
<ClInclude Include="Thread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="NXDNNetwork.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Network.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NXDNParrot.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -58,5 +55,8 @@
<ClCompile Include="Thread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="NXDNNetwork.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -102,7 +102,7 @@ unsigned int CNXDNNetwork::read(unsigned char* data, unsigned int length, in_add
if (::memcmp(data, "NXDN", 4U) != 0)
return 0U;
if (len != 15 && len != 43)
if (len != 17 && len != 43)
return 0U;
if (m_debug)

View File

@ -214,7 +214,9 @@ void CNXDNReflector::run()
if (len > 0U) {
CNXDNRepeater* rpt = findRepeater(address, port);
if (::memcmp(buffer, "NXDNP", 5U) == 0 && len == 15U) {
if (::memcmp(buffer, "NXDNP", 5U) == 0 && len == 17U) {
unsigned short id = (buffer[15U] << 8) | buffer[16U];
if (id == tg) {
if (rpt == NULL) {
rpt = new CNXDNRepeater;
rpt->m_timer.start();
@ -230,7 +232,10 @@ void CNXDNReflector::run()
// Return the poll
nxdnNetwork.write(buffer, len, address, port);
} else if (::memcmp(buffer, "NXDNU", 5U) == 0 && len == 15U) {
}
} else if (::memcmp(buffer, "NXDNU", 5U) == 0 && len == 17U) {
unsigned short id = (buffer[15U] << 8) | buffer[16U];
if (id == tg) {
if (rpt != NULL) {
std::string callsign = std::string((char*)(buffer + 5U), 10U);
LogMessage("Removing %s (%s:%u)", callsign.c_str(), ::inet_ntoa(address), port);
@ -244,6 +249,7 @@ void CNXDNReflector::run()
delete rpt;
}
}
} else if (::memcmp(buffer, "NXDND", 5U) == 0 && len == 43U) {
if (rpt != NULL) {
unsigned short srcId = (buffer[5U] << 8) | buffer[6U];