improved sendPing to use cache->findNameNick()

pull/14/head
Tom Early 6 years ago
parent 210d69ac9c
commit 3eafd5e37d

@ -1328,9 +1328,9 @@ void CQnetGateway::ProcessModem()
Index[i] = get_yrcall_rptr(user, rptr, gate, addr, 'R'); Index[i] = get_yrcall_rptr(user, rptr, gate, addr, 'R');
if (Index[i]--) { /* it is a repeater */ if (Index[i]--) { /* it is a repeater */
std::string from = OWNER.substr(0, 7); // std::string from = OWNER.substr(0, 7);
from.append(1, i+'A'); // from.append(1, i+'A');
ii[Index[i]]->sendPing(user, from); // ii[Index[i]]->sendPing(user, from);
to_remote_g2[i].streamid = dsvt.streamid; to_remote_g2[i].streamid = dsvt.streamid;
if (addr.npos == addr.find(':') && af_family[Index[i]] == AF_INET6) 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()); 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 */ /* one radio user on a repeater module at a time */
if (to_remote_g2[i].toDstar.AddressIsZero()) { 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 */ /* 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; to_remote_g2[i].streamid = dsvt.streamid;
if (addr.npos == addr.find(':') && af_family[Index[i]] == AF_INET6) 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()); 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 */ /* Used to validate MYCALL input */
try { 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) { } catch (std::regex_error &e) {
printf("Regular expression error: %s\n", e.what()); printf("Regular expression error: %s\n", e.what());
return true; return true;
@ -2369,7 +2371,7 @@ bool CQnetGateway::Init(char *cfgfile)
for (int j=0; j<2; j++) { for (int j=0; j<2; j++) {
if (ircddb[j].ip.empty()) if (ircddb[j].ip.empty())
continue; 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(); bool ok = ii[j]->open();
if (!ok) { if (!ok) {
printf("%s open failed\n", ircddb[j].ip.c_str()); printf("%s open failed\n", ircddb[j].ip.c_str());

@ -4,13 +4,14 @@
#include "IRCDDBApp.h" #include "IRCDDBApp.h"
#include "IRCutils.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); client = new IRCClient(app, update_channel, hostName, port, callsign, password, versionInfo);
} }

@ -2,6 +2,8 @@
#include <string> #include <string>
#include "../CacheManager.h"
enum IRCDDB_RESPONSE_TYPE { enum IRCDDB_RESPONSE_TYPE {
IDRT_NONE, IDRT_NONE,
IDRT_USER, IDRT_USER,
@ -22,7 +24,7 @@ class IRCClient;
class CIRCDDB class CIRCDDB
{ {
public: 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(); ~CIRCDDB();
// returns the socket family type // returns the socket family type
@ -128,4 +130,5 @@ public:
private: private:
IRCDDBApp *app; IRCDDBApp *app;
IRCClient *client; IRCClient *client;
CCacheManager *cache;
}; };

@ -11,7 +11,7 @@ unsigned int IRCDDBAppGateObject::counter = 0;
time_t IRCDDBAppRptrObject::maxTime((time_t)950000000); // February 2000 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; wdTimer = -1;
sendQ = NULL; 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]$"); timePattern = std::regex("^((2[0-3])|([01][0-9])):[0-5][0-9]:[0-5][0-9]$");
dbPattern = std::regex("^[0-9A-Z_]{8}$"); dbPattern = std::regex("^[0-9A-Z_]{8}$");
modulePattern = std::regex("^.*[ABCD]D?$"); modulePattern = std::regex("^.*[ABCD]D?$");
this->cache = cache;
} }
IRCDDBApp::~IRCDDBApp() IRCDDBApp::~IRCDDBApp()
@ -340,35 +341,26 @@ void IRCDDBApp::userChanOp(const std::string &nick, bool op)
userMapMutex.unlock(); 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) 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(name[name.length()-1]))
while (isspace(t[t.length()-1])) name.pop_back();
t.pop_back(); ToLower(name);
ToLower(t);
userMapMutex.lock(); auto nick = cache->findNameNick(name);
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();
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; static const int numberOfTables = 2;

@ -59,7 +59,7 @@ public:
class IRCDDBApp class IRCDDBApp
{ {
public: public:
IRCDDBApp(const std::string &update_channel); IRCDDBApp(const std::string &update_channel, CCacheManager *cache);
~IRCDDBApp(); ~IRCDDBApp();
void userJoin(const std::string &nick, const std::string &name, const std::string &host); void userJoin(const std::string &nick, const std::string &name, const std::string &host);
@ -115,6 +115,7 @@ private:
std::future<void> worker_thread; std::future<void> worker_thread;
IRCMessageQueue *sendQ; IRCMessageQueue *sendQ;
IRCMessageQueue replyQ; IRCMessageQueue replyQ;
CCacheManager *cache;
std::map<std::string, IRCDDBAppGateObject> user; std::map<std::string, IRCDDBAppGateObject> user;
std::mutex userMapMutex; std::mutex userMapMutex;

Loading…
Cancel
Save

Powered by TurnKey Linux.