summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/users.h2
-rw-r--r--src/configreader.cpp5
-rw-r--r--src/users.cpp39
3 files changed, 30 insertions, 16 deletions
diff --git a/include/users.h b/include/users.h
index ce8f4eb28..d94511660 100644
--- a/include/users.h
+++ b/include/users.h
@@ -830,7 +830,7 @@ namespace irc
/** Sets of time and users in whowas list
*/
- typedef std::map<time_t, irc::string> whowas_users_fifo;
+ typedef std::map<time_t,irc::string> whowas_users_fifo;
/** Called every hour by the core to remove expired entries
*/
diff --git a/src/configreader.cpp b/src/configreader.cpp
index df1b5f944..b1fbea0f8 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -334,8 +334,11 @@ bool ValidateWhoWas(ServerConfig* conf, const char* tag, const char* value, void
conf->WhoWasMaxGroups = 0;
if (conf->WhoWasMaxKeep < 3600)
+ {
conf->WhoWasMaxKeep = 3600;
-
+ conf->GetInstance()->Log(DEFAULT,"WARNING: <whowas:maxkeep> value less than 3600, setting to default 3600");
+ }
+ conf->GetInstance()->Log(DEBUG,"whowas:groupsize:%d maxgroups:%d maxkeep:%d",conf->WhoWasGroupSize,conf->WhoWasMaxGroups,conf->WhoWasMaxKeep);
irc::whowas::PruneWhoWas(conf->GetInstance(), conf->GetInstance()->Time());
return true;
}
diff --git a/src/users.cpp b/src/users.cpp
index f3278186b..184eef8ef 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -861,7 +861,7 @@ namespace irc
free(gecos);
}
- /* every hour, run this function which removes all entries over 3 days */
+ /* every hour, run this function which removes all entries older than Config->WhoWasMaxKeep */
void MaintainWhoWas(InspIRCd* ServerInstance, time_t t)
{
for (whowas_users::iterator iter = ServerInstance->whowas.begin(); iter != ServerInstance->whowas.end(); iter++)
@@ -881,15 +881,19 @@ namespace irc
/* on rehash, refactor maps according to new conf values */
void PruneWhoWas(InspIRCd* ServerInstance, time_t t)
{
+ /* config values */
int groupsize = ServerInstance->Config->WhoWasGroupSize;
int maxgroups = ServerInstance->Config->WhoWasMaxGroups;
int maxkeep = ServerInstance->Config->WhoWasMaxKeep;
- int groupcount = 0;
+ int groupcount = ServerInstance->whowas.size();
+ /* iterate whowas_fifo oldest first */
for (whowas_users_fifo::iterator iter = ServerInstance->whowas_fifo.begin(); iter != ServerInstance->whowas_fifo.end(); iter++)
{
- groupcount++;
-
+ /** prune all groups that has expired due to new maxkeep time and
+ * also any group number higher than new maxgroups. The oldest are
+ * removed first due to iteration over whowas_fifo
+ */
if (groupcount > maxgroups || iter->first < t - maxkeep)
{
whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
@@ -906,21 +910,21 @@ namespace irc
ServerInstance->whowas_fifo.erase(iter->first);
}
else {
+ /* also trim individual groupsizes in case groupsize should have been lowered */
whowas_set* n = (whowas_set*)ServerInstance->whowas.find(iter->second)->second;
if (n->size())
{
- int nickcount = 0;
- while (n->begin() != n->end())
+ int nickcount = n->size();
+ while (n->begin() != n->end() && nickcount > groupsize)
{
- nickcount++;
- if (nickcount > groupsize){
- WhoWasGroup *a = *(n->begin());
- DELETE(a);
- n->erase(n->begin());
- }
+ WhoWasGroup *a = *(n->begin());
+ DELETE(a);
+ n->erase(n->begin());
+ nickcount--;
}
}
}
+ groupcount--;
}
}
};
@@ -929,6 +933,12 @@ namespace irc
/* adds or updates an entry in the whowas list */
void userrec::AddToWhoWas()
{
+ /* if whowas disabled */
+ if (ServerInstance->Config->WhoWasGroupSize == 0 || ServerInstance->Config->WhoWasMaxGroups == 0)
+ {
+ return;
+ }
+
irc::whowas::whowas_users::iterator iter = ServerInstance->whowas.find(this->nick);
ServerInstance->Log(DEBUG,"Add to whowas lists");
@@ -943,6 +953,7 @@ void userrec::AddToWhoWas()
ServerInstance->whowas_fifo[ServerInstance->Time()] = this->nick;
if ((int)(ServerInstance->whowas.size()) > ServerInstance->Config->WhoWasMaxGroups)
{
+ ServerInstance->Log(DEBUG,"Maxgroups of %d reached deleting oldest group '%s'",ServerInstance->Config->WhoWasMaxGroups, ServerInstance->whowas_fifo.begin()->second.c_str());
ServerInstance->whowas.erase(ServerInstance->whowas_fifo.begin()->second);
ServerInstance->whowas_fifo.erase(ServerInstance->whowas_fifo.begin());
}
@@ -953,9 +964,9 @@ void userrec::AddToWhoWas()
ServerInstance->Log(DEBUG,"Using existing whowas group for %s",this->nick);
- if ((int)(group->size()) > ServerInstance->Config->WhoWasMaxGroups)
+ if ((int)(group->size()) >= ServerInstance->Config->WhoWasGroupSize)
{
- ServerInstance->Log(DEBUG,"Trimming existing group to ten entries for %s",this->nick);
+ ServerInstance->Log(DEBUG,"Trimming existing group '%s' to %d entries",this->nick, ServerInstance->Config->WhoWasGroupSize);
irc::whowas::WhoWasGroup *a = (irc::whowas::WhoWasGroup*)*(group->begin());
DELETE(a);
group->pop_front();