From 4cdde6e77525350692f3a3776691102ff15ba96c Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 23 Nov 2015 11:22:03 +0100 Subject: core_whowas Remove dead code --- src/coremods/core_whowas.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index d73fdf491..53c978ae8 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -47,23 +47,18 @@ CmdResult CommandWhowas::Handle (const std::vector& parameters, Use else { const WhoWas::Nick::List& list = nick->entries; - if (!list.empty()) + for (WhoWas::Nick::List::const_iterator i = list.begin(); i != list.end(); ++i) { - for (WhoWas::Nick::List::const_iterator i = list.begin(); i != list.end(); ++i) - { - WhoWas::Entry* u = *i; + WhoWas::Entry* u = *i; - user->WriteNumeric(RPL_WHOWASUSER, "%s %s %s * :%s", parameters[0].c_str(), - u->ident.c_str(),u->dhost.c_str(),u->gecos.c_str()); + user->WriteNumeric(RPL_WHOWASUSER, "%s %s %s * :%s", parameters[0].c_str(), u->ident.c_str(),u->dhost.c_str(),u->gecos.c_str()); - if (user->HasPrivPermission("users/auspex")) - user->WriteNumeric(RPL_WHOWASIP, "%s :was connecting from *@%s", - parameters[0].c_str(), u->host.c_str()); + if (user->HasPrivPermission("users/auspex")) + user->WriteNumeric(RPL_WHOWASIP, "%s :was connecting from *@%s", parameters[0].c_str(), u->host.c_str()); - std::string signon = InspIRCd::TimeString(u->signon); - bool hide_server = (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")); - user->WriteNumeric(RPL_WHOISSERVER, "%s %s :%s", parameters[0].c_str(), (hide_server ? ServerInstance->Config->HideWhoisServer.c_str() : u->server.c_str()), signon.c_str()); - } + std::string signon = InspIRCd::TimeString(u->signon); + bool hide_server = (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")); + user->WriteNumeric(RPL_WHOISSERVER, "%s %s :%s", parameters[0].c_str(), (hide_server ? ServerInstance->Config->HideWhoisServer.c_str() : u->server.c_str()), signon.c_str()); } } -- cgit v1.2.3 From bf2f81811fe1869a98861b2d5edc0fba8f884123 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 23 Nov 2015 11:37:26 +0100 Subject: core_whowas Add WhoWas::Manager::PurgeNick() --- include/commands/cmd_whowas.h | 10 ++++++++++ src/coremods/core_whowas.cpp | 37 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/include/commands/cmd_whowas.h b/include/commands/cmd_whowas.h index cd2101e9f..aaea31864 100644 --- a/include/commands/cmd_whowas.h +++ b/include/commands/cmd_whowas.h @@ -172,6 +172,16 @@ namespace WhoWas /** Shrink all data structures to honor the current settings */ void Prune(); + + /** Remove a nick (and all entries belonging to it) from the database + * @param it Iterator to the nick to purge + */ + void PurgeNick(whowas_users::iterator it); + + /** Remove a nick (and all entries belonging to it) from the database + * @param nick Nick to purge + */ + void PurgeNick(WhoWas::Nick* nick); }; } diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 53c978ae8..12ab940dd 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -119,10 +119,7 @@ void WhoWas::Manager::Add(User* user) if (whowas.size() > this->MaxGroups) { // Too many nicks, remove the nick which was inserted the longest time ago from both the map and the fifo - nick = whowas_fifo.front(); - whowas_fifo.pop_front(); - whowas.erase(nick->nick); - delete nick; + PurgeNick(whowas_fifo.front()); } } else @@ -150,18 +147,7 @@ void WhoWas::Manager::Prune() { WhoWas::Nick* nick = whowas_fifo.front(); if ((whowas_fifo.size() > this->MaxGroups) || (nick->addtime < min)) - { - /* hopefully redundant integrity check, but added while debugging r6216 */ - if (!whowas.erase(nick->nick)) - { - /* this should never happen, if it does maps are corrupt */ - ServerInstance->Logs->Log("WHOWAS", LOG_DEFAULT, "BUG: Whowas maps got corrupted! (1)"); - return; - } - - whowas_fifo.pop_front(); - delete nick; - } + PurgeNick(nick); else break; } @@ -218,6 +204,25 @@ void WhoWas::Manager::UpdateConfig(unsigned int NewGroupSize, unsigned int NewMa Prune(); } +void WhoWas::Manager::PurgeNick(whowas_users::iterator it) +{ + WhoWas::Nick* nick = it->second; + whowas_fifo.erase(nick); + whowas.erase(it); + delete nick; +} + +void WhoWas::Manager::PurgeNick(WhoWas::Nick* nick) +{ + whowas_users::iterator it = whowas.find(nick->nick); + if (it == whowas.end()) + { + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in whowas database, please report"); + return; + } + PurgeNick(it); +} + WhoWas::Entry::Entry(User* user) : host(user->host) , dhost(user->dhost) -- cgit v1.2.3 From 133b7fade64bd0ab9360dd0998b0d5ad170e230b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Mon, 23 Nov 2015 11:42:49 +0100 Subject: core_whowas Purge nicks as soon as they no longer have any entries --- src/coremods/core_whowas.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 12ab940dd..79ce94cc9 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -76,11 +76,7 @@ const WhoWas::Nick* WhoWas::Manager::FindNick(const std::string& nickname) const whowas_users::const_iterator it = whowas.find(nickname); if (it == whowas.end()) return NULL; - - const Nick* nick = it->second; - if (nick->entries.empty()) - return NULL; - return nick; + return it->second; } WhoWas::Manager::Stats WhoWas::Manager::GetStats() const @@ -153,7 +149,7 @@ void WhoWas::Manager::Prune() } /* Then cut the whowas sets to new size (groupsize) */ - for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ++i) + for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ) { WhoWas::Nick::List& list = i->second->entries; while (list.size() > this->GroupSize) @@ -161,6 +157,11 @@ void WhoWas::Manager::Prune() delete list.front(); list.pop_front(); } + + if (list.empty()) + PurgeNick(i++); + else + ++i; } } @@ -168,7 +169,7 @@ void WhoWas::Manager::Prune() void WhoWas::Manager::Maintain() { time_t min = ServerInstance->Time() - this->MaxKeep; - for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ++i) + for (whowas_users::iterator i = whowas.begin(); i != whowas.end(); ) { WhoWas::Nick::List& list = i->second->entries; while (!list.empty() && list.front()->signon < min) @@ -176,6 +177,11 @@ void WhoWas::Manager::Maintain() delete list.front(); list.pop_front(); } + + if (list.empty()) + PurgeNick(i++); + else + ++i; } } -- cgit v1.2.3