Efficiency improvements for the block list checking.
This commit is contained in:
parent
51fc88f6e4
commit
d0602d9aa6
3 changed files with 33 additions and 13 deletions
|
@ -54,6 +54,9 @@ bool CBlockList::check(const unsigned char* callsign) const
|
|||
{
|
||||
assert(callsign != NULL);
|
||||
|
||||
if (m_callsigns.empty())
|
||||
return false;
|
||||
|
||||
std::string call = std::string((char*)callsign, YSF_CALLSIGN_LENGTH);
|
||||
std::for_each(call.begin(), call.end(), [](char& 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) {
|
||||
const std::string blocked = *it;
|
||||
if (call.find(blocked) != std::string::npos)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CBlockList::clock(unsigned int ms)
|
||||
|
|
|
@ -19,6 +19,6 @@
|
|||
#if !defined(VERSION_H)
|
||||
#define VERSION_H
|
||||
|
||||
const char* VERSION = "20210213";
|
||||
const char* VERSION = "20210214";
|
||||
|
||||
#endif
|
||||
|
|
|
@ -199,17 +199,16 @@ void CYSFReflector::run()
|
|||
unsigned char src[YSF_CALLSIGN_LENGTH];
|
||||
unsigned char dst[YSF_CALLSIGN_LENGTH];
|
||||
|
||||
for (;;) {
|
||||
bool blocked;
|
||||
bool blocked = false;
|
||||
bool checked = false;
|
||||
|
||||
for (;;) {
|
||||
unsigned char buffer[200U];
|
||||
sockaddr_storage addr;
|
||||
unsigned int addrLen;
|
||||
|
||||
unsigned int len = network.readData(buffer, 200U, addr, addrLen);
|
||||
if (len > 0U) {
|
||||
blocked = false;
|
||||
|
||||
CYSFRepeater* rpt = findRepeater(addr);
|
||||
if (::memcmp(buffer, "YSFP", 4U) == 0) {
|
||||
if (rpt == NULL) {
|
||||
|
@ -238,8 +237,25 @@ void CYSFReflector::run()
|
|||
}
|
||||
network.setCount(m_repeaters.size());
|
||||
} 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?
|
||||
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()) {
|
||||
::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);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LogDebug("Data from %10.10s at %10.10s blocked", buffer + 14U, buffer + 4U);
|
||||
blocked = true;
|
||||
}
|
||||
|
||||
if (!blocked) {
|
||||
watchdogTimer.start();
|
||||
|
||||
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) {
|
||||
blocked = false;
|
||||
checked = false;
|
||||
|
||||
LogMessage("Received end of transmission");
|
||||
watchdogTimer.stop();
|
||||
}
|
||||
|
@ -322,6 +336,9 @@ void CYSFReflector::run()
|
|||
|
||||
watchdogTimer.clock(ms);
|
||||
if (watchdogTimer.isRunning() && watchdogTimer.hasExpired()) {
|
||||
checked = false;
|
||||
blocked = false;
|
||||
|
||||
LogMessage("Network watchdog has expired");
|
||||
watchdogTimer.stop();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue