diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-01-06 01:15:58 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-01-06 01:15:58 +0000 |
commit | 01d7b8e2463c3cb8e1f220e64abd5d560b886bc7 (patch) | |
tree | d2cac8f5b6632680cea7a6cdb3a9de17d4031893 /src | |
parent | ef8c1e5e6542a4cb9f24ab0a3a480ca1c0230e86 (diff) |
Add bancache expiry stuff, currently records expire 60 seconds after creation. Live, we will want perhaps an hour before expiry.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8640 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/bancache.cpp | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/bancache.cpp b/src/bancache.cpp index 05c014de3..24578b379 100644 --- a/src/bancache.cpp +++ b/src/bancache.cpp @@ -20,7 +20,6 @@ BanCacheHit *BanCacheManager::AddHit(const std::string &ip, const std::string &t { BanCacheHit *b; - if (this->BanHash->find(ip) != this->BanHash->end()) // can't have two cache entries on the same IP, sorry.. return NULL; @@ -37,7 +36,16 @@ BanCacheHit *BanCacheManager::GetHit(const std::string &ip) 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) @@ -63,7 +71,7 @@ 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; @@ -84,7 +92,7 @@ int BanCacheManager::RemoveEntries(const std::string &type, bool positive) /* 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++; } } @@ -108,9 +116,20 @@ void BanCacheManager::RehashCache() 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 */ |