std::string Type;
std::string Reason;
std::string IP;
+ time_t Expiry;
BanCacheHit(InspIRCd *Instance, const std::string &ip, const std::string &type, const std::string &reason)
{
this->Type = type;
this->Reason = reason;
this->IP = ip;
+ this->Expiry = time(NULL) + 60; // XXX changeme
}
};
* @param type The type of bancache entries to remove (e.g. 'G')
* @param positive Remove either positive (true) or negative (false) hits.
*/
- int RemoveEntries(const std::string &type, bool positive);
+ unsigned int RemoveEntries(const std::string &type, bool positive);
BanCacheManager(InspIRCd *Instance)
{
{
BanCacheHit *b;
-
if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry..
return NULL;
if (i == this->BanHash->end())
return NULL; // free and safe
else
+ {
+ if (time(NULL) > i->second->Expiry)
+ {
+ ServerInstance->Log(DEBUG, "Hit on " + ip + " is out of date, removing!");
+ RemoveHit(i->second);
+ return NULL; // out of date
+ }
+
return i->second; // hit.
+ }
}
bool BanCacheManager::RemoveHit(BanCacheHit *b)
return true;
}
-int BanCacheManager::RemoveEntries(const std::string &type, bool positive)
+unsigned int BanCacheManager::RemoveEntries(const std::string &type, bool positive)
{
int removed = 0;
/* we need to remove this one. */
delete b;
b = NULL;
- BanHash->erase(n);
+ BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
removed++;
}
}
safei++;
/* Safe to delete items here through iterator 'n' */
+ BanCacheHit *b = n->second;
- /* Actually inserts a std::pair */
- NewHash->insert(*n);
+ if (time(NULL) > b->Expiry)
+ {
+ /* we need to remove this one. */
+ delete b;
+ b = NULL;
+ BanHash->erase(n); // WORD TO THE WISE: don't use RemoveHit here, because we MUST remove the iterator in a safe way.
+ }
+ else
+ {
+ /* Actually inserts a std::pair */
+ NewHash->insert(*n);
+ }
/* End of safe section */