1
0
Fork 0

Efficiency improvements for the block list checking.

master
Jonathan Naylor 4 years ago
parent 51fc88f6e4
commit d0602d9aa6

@ -54,6 +54,9 @@ bool CBlockList::check(const unsigned char* callsign) const
{ {
assert(callsign != NULL); assert(callsign != NULL);
if (m_callsigns.empty())
return false;
std::string call = std::string((char*)callsign, YSF_CALLSIGN_LENGTH); std::string call = std::string((char*)callsign, YSF_CALLSIGN_LENGTH);
std::for_each(call.begin(), call.end(), [](char& c) { std::for_each(call.begin(), call.end(), [](char& c) {
c = std::toupper(c); c = std::toupper(c);
@ -62,10 +65,10 @@ bool CBlockList::check(const unsigned char* callsign) const
for (std::vector<std::string>::const_iterator it = m_callsigns.cbegin(); it != m_callsigns.cend(); ++it) { for (std::vector<std::string>::const_iterator it = m_callsigns.cbegin(); it != m_callsigns.cend(); ++it) {
const std::string blocked = *it; const std::string blocked = *it;
if (call.find(blocked) != std::string::npos) if (call.find(blocked) != std::string::npos)
return false; return true;
} }
return true; return false;
} }
void CBlockList::clock(unsigned int ms) void CBlockList::clock(unsigned int ms)

@ -19,6 +19,6 @@
#if !defined(VERSION_H) #if !defined(VERSION_H)
#define VERSION_H #define VERSION_H
const char* VERSION = "20210213"; const char* VERSION = "20210214";
#endif #endif

@ -199,17 +199,16 @@ void CYSFReflector::run()
unsigned char src[YSF_CALLSIGN_LENGTH]; unsigned char src[YSF_CALLSIGN_LENGTH];
unsigned char dst[YSF_CALLSIGN_LENGTH]; unsigned char dst[YSF_CALLSIGN_LENGTH];
for (;;) { bool blocked = false;
bool blocked; bool checked = false;
for (;;) {
unsigned char buffer[200U]; unsigned char buffer[200U];
sockaddr_storage addr; sockaddr_storage addr;
unsigned int addrLen; unsigned int addrLen;
unsigned int len = network.readData(buffer, 200U, addr, addrLen); unsigned int len = network.readData(buffer, 200U, addr, addrLen);
if (len > 0U) { if (len > 0U) {
blocked = false;
CYSFRepeater* rpt = findRepeater(addr); CYSFRepeater* rpt = findRepeater(addr);
if (::memcmp(buffer, "YSFP", 4U) == 0) { if (::memcmp(buffer, "YSFP", 4U) == 0) {
if (rpt == NULL) { if (rpt == NULL) {
@ -238,8 +237,25 @@ void CYSFReflector::run()
} }
network.setCount(m_repeaters.size()); network.setCount(m_repeaters.size());
} else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) { } else if (::memcmp(buffer + 0U, "YSFD", 4U) == 0 && rpt != NULL) {
// Check for a change of user
if (watchdogTimer.isRunning() && ::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) {
if (::memcmp(buffer + 14U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(src, "??????????", YSF_CALLSIGN_LENGTH) == 0)
checked = false;
if (::memcmp(buffer + 24U, " ", YSF_CALLSIGN_LENGTH) != 0 && ::memcmp(dst, "??????????", YSF_CALLSIGN_LENGTH) == 0)
checked = false;
}
// Is this user allowed? // Is this user allowed?
if (blockList.check(buffer + 14U)) { if (!checked) {
blocked = blockList.check(buffer + 14U);
checked = true;
if (blocked)
LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U);
}
if (!blocked) {
if (!watchdogTimer.isRunning()) { if (!watchdogTimer.isRunning()) {
::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH); ::memcpy(tag, buffer + 4U, YSF_CALLSIGN_LENGTH);
@ -272,12 +288,7 @@ void CYSFReflector::run()
LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U); LogMessage("Received data from %10.10s to %10.10s at %10.10s", src, dst, buffer + 4U);
} }
} }
} else {
LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U);
blocked = true;
}
if (!blocked) {
watchdogTimer.start(); watchdogTimer.start();
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) { for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
@ -286,6 +297,9 @@ void CYSFReflector::run()
} }
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
blocked = false;
checked = false;
LogMessage("Received end of transmission"); LogMessage("Received end of transmission");
watchdogTimer.stop(); watchdogTimer.stop();
} }
@ -322,6 +336,9 @@ void CYSFReflector::run()
watchdogTimer.clock(ms); watchdogTimer.clock(ms);
if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) { if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) {
checked = false;
blocked = false;
LogMessage("Network watchdog has expired"); LogMessage("Network watchdog has expired");
watchdogTimer.stop(); watchdogTimer.stop();
} }

Loading…
Cancel
Save