1
0
mirror of https://github.com/anope/anope.git synced 2026-07-05 22:53:13 +02:00

Speed up akill xline checks

Cache xline nick, user, host, etc instead of rebuilding it everytime its
requested. Store users ip in sockaddr form and not string form to
prevent having to rebuild sockaddrs when checking xlines.

Also do not try to convert empty config values in Config::Get as this
can be rather common if a non string configuration value is not set, and
the cost of the ConvertException is great.
This commit is contained in:
Adam
2014-05-20 21:10:49 -04:00
parent 20ce170024
commit 866f3f32ab
20 changed files with 115 additions and 112 deletions
-2
View File
@@ -158,8 +158,6 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
if (c->CheckDelete())
delete c;
else
c->CheckModes();
}
}
}
+1 -1
View File
@@ -867,7 +867,7 @@ bool Entry::Matches(User *u, bool full) const
}
}
else if (!this->host.empty() && !Anope::Match(u->GetDisplayedHost(), this->host) && !Anope::Match(u->GetCloakedHost(), this->host) &&
(!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip, this->host))))
(!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip.addr(), this->host))))
ret = false;
if (!this->real.empty() && !Anope::Match(u->realname, this->real))
+8 -7
View File
@@ -96,9 +96,9 @@ bool sockaddrs::ipv6() const
return sa.sa_family == AF_INET6;
}
bool sockaddrs::operator()() const
bool sockaddrs::valid() const
{
return valid();
return size() != 0;
}
bool sockaddrs::operator==(const sockaddrs &other) const
@@ -180,11 +180,6 @@ void sockaddrs::ntop(int type, const void *src)
this->clear();
}
bool sockaddrs::valid() const
{
return size() != 0;
}
cidr::cidr(const Anope::string &ip)
{
bool ipv6 = ip.find(':') != Anope::string::npos;
@@ -221,6 +216,12 @@ cidr::cidr(const Anope::string &ip, unsigned char len)
this->cidr_len = len;
}
cidr::cidr(const sockaddrs &a, unsigned char len) : addr(a)
{
this->cidr_ip = a.addr();
this->cidr_len = len;
}
Anope::string cidr::mask() const
{
if ((this->addr.ipv6() && this->cidr_len == 128) || (!this->addr.ipv6() && this->cidr_len == 32))
+2 -3
View File
@@ -33,7 +33,7 @@ time_t MaxUserTime = 0;
std::list<User *> User::quitting_users;
User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account)
User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &uip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) : ip(uip)
{
if (snick.empty() || sident.empty() || shost.empty())
throw CoreException("Bad args passed to User::User");
@@ -49,7 +49,6 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
this->host = shost;
this->vhost = svhost;
this->chost = svhost;
this->ip = sip;
this->server = sserver;
this->realname = srealname;
this->timestamp = this->signon = ts;
@@ -72,7 +71,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
{
++sserver->users;
if (server->IsSynced())
Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!sip.empty() && sip != host ? "[" + sip + "] " : "") << "connected to the network (" << sserver->GetName() << ")";
Log(this, "connect") << (!vhost.empty() && vhost != host ? "(" + vhost + ") " : "") << "(" << srealname << ") " << (!uip.empty() && uip != host ? "[" + uip + "] " : "") << "connected to the network (" << sserver->GetName() << ")";
}
if (UserListByNick.size() > MaxUserCount)
+56 -46
View File
@@ -24,7 +24,7 @@
std::list<XLineManager *> XLineManager::XLineManagers;
Serialize::Checker<std::multimap<Anope::string, XLine *, ci::less> > XLineManager::XLinesByUID("XLine");
void XLine::InitRegex()
void XLine::Init()
{
if (this->mask.length() >= 2 && this->mask[0] == '/' && this->mask[this->mask.length() - 1] == '/' && !Config->GetBlock("options")->Get<const Anope::string>("regexengine").empty())
{
@@ -43,82 +43,92 @@ void XLine::InitRegex()
}
}
}
size_t nick_t = this->mask.find('!');
if (nick_t != Anope::string::npos)
nick = this->mask.substr(0, nick_t);
size_t user_t = this->mask.find('!'), host_t = this->mask.find('@');
if (host_t != Anope::string::npos)
{
if (user_t != Anope::string::npos && host_t > user_t)
user = this->mask.substr(user_t + 1, host_t - user_t - 1);
else
user = this->mask.substr(0, host_t);
}
size_t real_t = this->mask.find('#');
if (host_t != Anope::string::npos)
{
if (real_t != Anope::string::npos && real_t > host_t)
host = this->mask.substr(host_t + 1, real_t - host_t - 1);
else
host = this->mask.substr(host_t + 1);
}
else
{
if (real_t != Anope::string::npos)
host = this->mask.substr(0, real_t);
else
host = this->mask;
}
if (real_t != Anope::string::npos)
real = this->mask.substr(real_t + 1);
if (host.find('/') != Anope::string::npos)
{
c = new cidr(host);
if (!c->valid())
{
delete c;
c = NULL;
}
}
}
XLine::XLine(const Anope::string &ma, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(Me->GetName()), created(0), expires(0), reason(r), id(uid)
{
regex = NULL;
manager = NULL;
c = NULL;
this->InitRegex();
this->Init();
}
XLine::XLine(const Anope::string &ma, const Anope::string &b, const time_t ex, const Anope::string &r, const Anope::string &uid) : Serializable("XLine"), mask(ma), by(b), created(Anope::CurTime), expires(ex), reason(r), id(uid)
{
regex = NULL;
manager = NULL;
c = NULL;
this->InitRegex();
this->Init();
}
XLine::~XLine()
{
delete regex;
delete c;
}
Anope::string XLine::GetNick() const
const Anope::string &XLine::GetNick() const
{
size_t nick_t = this->mask.find('!');
if (nick_t == Anope::string::npos)
return "";
return this->mask.substr(0, nick_t);
return nick;
}
Anope::string XLine::GetUser() const
const Anope::string &XLine::GetUser() const
{
size_t user_t = this->mask.find('!'), host_t = this->mask.find('@');
if (host_t != Anope::string::npos)
{
if (user_t != Anope::string::npos && host_t > user_t)
return this->mask.substr(user_t + 1, host_t - user_t - 1);
else
return this->mask.substr(0, host_t);
}
else
return "";
return user;
}
Anope::string XLine::GetHost() const
const Anope::string &XLine::GetHost() const
{
size_t host_t = this->mask.find('@'), real_t = this->mask.find('#');
if (host_t != Anope::string::npos)
{
if (real_t != Anope::string::npos && real_t > host_t)
return this->mask.substr(host_t + 1, real_t - host_t - 1);
else
return this->mask.substr(host_t + 1);
}
else
{
if (real_t != Anope::string::npos)
return this->mask.substr(0, real_t);
else
return this->mask;
}
return host;
}
Anope::string XLine::GetReal() const
const Anope::string &XLine::GetReal() const
{
size_t real_t = this->mask.find('#');
if (real_t != Anope::string::npos)
return this->mask.substr(real_t + 1);
else
return "";
return real;
}
Anope::string XLine::GetReason() const