1
0
Fork 0

Fix the duplicates in the reflector, hopefully.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 8d341393ab
commit d97305d0e4

@ -186,6 +186,30 @@ void CYSFReflector::run()
for (;;) { for (;;) {
unsigned char buffer[200U]; unsigned char buffer[200U];
// Refresh/add repeaters based on their polls/simulated polls
in_addr address;
unsigned int port;
std::string callsign;
bool ret = network.readPoll(callsign, address, port);
if (ret) {
CYSFRepeater* rpt = findRepeater(callsign, address, port);
if (rpt == NULL) {
LogMessage("Adding %s", callsign.c_str());
rpt = new CYSFRepeater;
rpt->m_timer.start();
rpt->m_callsign = callsign;
rpt->m_address = address;
rpt->m_port = port;
m_repeaters.push_back(rpt);
network.setCount(m_repeaters.size());
} else {
rpt->m_timer.start();
rpt->m_callsign = callsign;
rpt->m_address = address;
rpt->m_port = port;
}
}
unsigned int len = network.readData(buffer); unsigned int len = network.readData(buffer);
if (len > 0U) { if (len > 0U) {
if (!watchdogTimer.isRunning()) { if (!watchdogTimer.isRunning()) {
@ -225,13 +249,9 @@ void CYSFReflector::run()
if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) { if (::memcmp(tag, buffer + 4U, YSF_CALLSIGN_LENGTH) == 0) {
watchdogTimer.start(); watchdogTimer.start();
std::string callsign = std::string((char*)(buffer + 4U), YSF_CALLSIGN_LENGTH); for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
CYSFRepeater* rpt = findRepeater(callsign); if ((*it)->m_callsign != callsign)
if (rpt != NULL) { network.writeData(buffer, (*it)->m_address, (*it)->m_port);
for (std::vector<CYSFRepeater*>::const_iterator it = m_repeaters.begin(); it != m_repeaters.end(); ++it) {
if ((*it)->m_callsign != callsign)
network.writeData(buffer, (*it)->m_address, (*it)->m_port);
}
} }
if ((buffer[34U] & 0x01U) == 0x01U) { if ((buffer[34U] & 0x01U) == 0x01U) {
@ -241,29 +261,6 @@ void CYSFReflector::run()
} }
} }
// Refresh/add repeaters based on their polls
std::string callsign;
in_addr address;
unsigned int port;
bool ret = network.readPoll(callsign, address, port);
if (ret) {
CYSFRepeater* rpt = findRepeater(callsign);
if (rpt == NULL) {
LogMessage("Adding %s", callsign.c_str());
rpt = new CYSFRepeater;
rpt->m_timer.start();
rpt->m_callsign = callsign;
rpt->m_address = address;
rpt->m_port = port;
m_repeaters.push_back(rpt);
network.setCount(m_repeaters.size());
} else {
rpt->m_timer.start();
rpt->m_address = address;
rpt->m_port = port;
}
}
unsigned int ms = stopWatch.elapsed(); unsigned int ms = stopWatch.elapsed();
stopWatch.start(); stopWatch.start();
@ -315,10 +312,10 @@ void CYSFReflector::run()
::LogFinalise(); ::LogFinalise();
} }
CYSFRepeater* CYSFReflector::findRepeater(const std::string& callsign) const CYSFRepeater* CYSFReflector::findRepeater(const std::string& callsign, const in_addr& address, unsigned int port) const
{ {
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) {
if ((*it)->m_callsign == callsign) if ((*it)->m_callsign == callsign || (address.s_addr == (*it)->m_address.s_addr && (*it)->m_port == port))
return *it; return *it;
} }

@ -66,7 +66,7 @@ private:
CConf m_conf; CConf m_conf;
std::vector<CYSFRepeater*> m_repeaters; std::vector<CYSFRepeater*> m_repeaters;
CYSFRepeater* findRepeater(const std::string& callsign) const; CYSFRepeater* findRepeater(const std::string& callsign, const in_addr& address, unsigned int port) const;
void dumpRepeaters() const; void dumpRepeaters() const;
}; };

Loading…
Cancel
Save