From 3eafd5e37dc34692884949770497f9e04e4fed24 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Fri, 20 Mar 2020 06:32:25 -0700 Subject: [PATCH] improved sendPing to use cache->findNameNick() --- QnetGateway.cpp | 18 ++++++++++-------- ircddb/IRCDDB.cpp | 7 ++++--- ircddb/IRCDDB.h | 5 ++++- ircddb/IRCDDBApp.cpp | 42 +++++++++++++++++------------------------- ircddb/IRCDDBApp.h | 3 ++- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 9c1b931..b5c6157 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -1328,9 +1328,9 @@ void CQnetGateway::ProcessModem() Index[i] = get_yrcall_rptr(user, rptr, gate, addr, 'R'); if (Index[i]--) { /* it is a repeater */ - std::string from = OWNER.substr(0, 7); - from.append(1, i+'A'); - ii[Index[i]]->sendPing(user, from); + // std::string from = OWNER.substr(0, 7); + // from.append(1, i+'A'); + // ii[Index[i]]->sendPing(user, from); to_remote_g2[i].streamid = dsvt.streamid; if (addr.npos == addr.find(':') && af_family[Index[i]] == AF_INET6) fprintf(stderr, "ERROR using IRC[%d]: IP returned from cache is IPV4, %s, but family is AF_INET6!\n", Index[i], addr.c_str()); @@ -1383,10 +1383,12 @@ void CQnetGateway::ProcessModem() /* one radio user on a repeater module at a time */ if (to_remote_g2[i].toDstar.AddressIsZero()) { + if (std::regex_match(user.c_str(), preg)) { + // don't do a ping to a routing group + std::string from((const char *)dsvt.hdr.rpt1, 8); + ii[Index[i]]->sendPing(gate, from); + } /* set the destination */ - std::string from = OWNER.substr(0, 7); - from.append(1, i+'A'); - ii[Index[i]]->sendPing(rptr, from); to_remote_g2[i].streamid = dsvt.streamid; if (addr.npos == addr.find(':') && af_family[Index[i]] == AF_INET6) fprintf(stderr, "ERROR using IRC[%d]: IP returned from cache, %s, is IPV4 but family is AF_INET6!\n", Index[i], addr.c_str()); @@ -2277,7 +2279,7 @@ bool CQnetGateway::Init(char *cfgfile) /* Used to validate MYCALL input */ try { - preg = std::regex("^(([1-9][A-Z])|([A-Z][0-9])|([A-Z][A-Z][0-9]))[0-9A-Z]*[A-Z][ ]*[ A-RT-Z]$", std::regex::extended); + preg = std::regex("^(([1-9][A-Z])|([A-PR-Z][0-9])|([A-PR-Z][A-Z][0-9]))[0-9A-Z]*[A-Z][ ]*[ A-RT-Z]$", std::regex::extended); } catch (std::regex_error &e) { printf("Regular expression error: %s\n", e.what()); return true; @@ -2369,7 +2371,7 @@ bool CQnetGateway::Init(char *cfgfile) for (int j=0; j<2; j++) { if (ircddb[j].ip.empty()) continue; - ii[j] = new CIRCDDB(ircddb[j].ip, ircddb[j].port, owner, IRCDDB_PASSWORD[j], GW_VERSION.c_str()); + ii[j] = new CIRCDDB(ircddb[j].ip, ircddb[j].port, owner, IRCDDB_PASSWORD[j], GW_VERSION.c_str(), &cache); bool ok = ii[j]->open(); if (!ok) { printf("%s open failed\n", ircddb[j].ip.c_str()); diff --git a/ircddb/IRCDDB.cpp b/ircddb/IRCDDB.cpp index 3c203c0..c273017 100644 --- a/ircddb/IRCDDB.cpp +++ b/ircddb/IRCDDB.cpp @@ -4,13 +4,14 @@ #include "IRCDDBApp.h" #include "IRCutils.h" -CIRCDDB::CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo) +CIRCDDB::CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo, CCacheManager *cache) { - std::string update_channel = "#dstar"; + this->cache = cache; - app = new IRCDDBApp(update_channel); + const std::string update_channel("#dstar"); + app = new IRCDDBApp(update_channel, cache); client = new IRCClient(app, update_channel, hostName, port, callsign, password, versionInfo); } diff --git a/ircddb/IRCDDB.h b/ircddb/IRCDDB.h index ff18167..e200c82 100644 --- a/ircddb/IRCDDB.h +++ b/ircddb/IRCDDB.h @@ -2,6 +2,8 @@ #include +#include "../CacheManager.h" + enum IRCDDB_RESPONSE_TYPE { IDRT_NONE, IDRT_USER, @@ -22,7 +24,7 @@ class IRCClient; class CIRCDDB { public: - CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo); + CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo, CCacheManager *cache); ~CIRCDDB(); // returns the socket family type @@ -128,4 +130,5 @@ public: private: IRCDDBApp *app; IRCClient *client; + CCacheManager *cache; }; diff --git a/ircddb/IRCDDBApp.cpp b/ircddb/IRCDDBApp.cpp index 5a2bb08..17bf864 100644 --- a/ircddb/IRCDDBApp.cpp +++ b/ircddb/IRCDDBApp.cpp @@ -11,7 +11,7 @@ unsigned int IRCDDBAppGateObject::counter = 0; time_t IRCDDBAppRptrObject::maxTime((time_t)950000000); // February 2000 -IRCDDBApp::IRCDDBApp(const std::string &u_chan) +IRCDDBApp::IRCDDBApp(const std::string &u_chan, CCacheManager *cache) { wdTimer = -1; sendQ = NULL; @@ -31,6 +31,7 @@ IRCDDBApp::IRCDDBApp(const std::string &u_chan) timePattern = std::regex("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$"); dbPattern = std::regex("^[0-9A-Z_]{8}$"); modulePattern = std::regex("^.*[ABCD]D?$"); + this->cache = cache; } IRCDDBApp::~IRCDDBApp() @@ -340,35 +341,26 @@ void IRCDDBApp::userChanOp(const std::string &nick, bool op) userMapMutex.unlock(); } +// to is the gateway to which we are sending the message, (the gateway last used by URCall) +// from is the repeater we are expecting the receive the the ping +// this will open the routing port on the target void IRCDDBApp::sendPing(const std::string &to, const std::string &from) { - std::string t = to.substr(0, 7); + std::string name = to.substr(0, 7); - ReplaceChar(t, '_', ' '); - while (isspace(t[t.length()-1])) - t.pop_back(); - ToLower(t); + while (isspace(name[name.length()-1])) + name.pop_back(); + ToLower(name); - userMapMutex.lock(); - for (int j=1; j <= 4; j++) { - std::string ircUser = t + std::string("-") + std::to_string(j); - - if (1 == user.count(ircUser)) { - std::string f(from); - ReplaceChar(f, ' ', '_'); - IRCMessage *rm = new IRCMessage(ircUser, "IDRT_PING"); - rm->addParam(f); - std::string out; - rm->composeMessage(out); - out.pop_back(); - out.pop_back(); - //printf("IRCDDBApp::sendPing: %s\n", out.c_str()); - sendQ->putMessage(rm); - break; - } - } - userMapMutex.unlock(); + auto nick = cache->findNameNick(name); + if (! nick.empty()) { + std::string rptr(from); + ReplaceChar(rptr, ' ', '_'); + IRCMessage *m = new IRCMessage(nick, "IDRT_PING"); + m->addParam(rptr); + sendQ->putMessage(m); + } } static const int numberOfTables = 2; diff --git a/ircddb/IRCDDBApp.h b/ircddb/IRCDDBApp.h index 532abd3..75b1b74 100644 --- a/ircddb/IRCDDBApp.h +++ b/ircddb/IRCDDBApp.h @@ -59,7 +59,7 @@ public: class IRCDDBApp { public: - IRCDDBApp(const std::string &update_channel); + IRCDDBApp(const std::string &update_channel, CCacheManager *cache); ~IRCDDBApp(); void userJoin(const std::string &nick, const std::string &name, const std::string &host); @@ -115,6 +115,7 @@ private: std::future worker_thread; IRCMessageQueue *sendQ; IRCMessageQueue replyQ; + CCacheManager *cache; std::map user; std::mutex userMapMutex;