diff options
author | Adam <Adam@anope.org> | 2012-11-05 22:17:47 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-11-06 11:02:12 -0500 |
commit | 53b2bdfe5e157a9e5ca5d08873edebcd04511ae1 (patch) | |
tree | f94c8603ffe475405ea668c629eddd7c8ba0891e | |
parent | 27ab6a686cb271ea8eae7a243906af5bebeb83d7 (diff) |
Use std::tr1::unordered_map for a few of the larger maps
41 files changed, 182 insertions, 65 deletions
diff --git a/include/account.h b/include/account.h index 7b98525e4..8ed1f06a4 100644 --- a/include/account.h +++ b/include/account.h @@ -20,8 +20,8 @@ #include "memo.h" #include "base.h" -typedef Anope::insensitive_map<NickAlias *> nickalias_map; -typedef Anope::insensitive_map<NickCore *> nickcore_map; +typedef Anope::hash_map<NickAlias *> nickalias_map; +typedef Anope::hash_map<NickCore *> nickcore_map; extern CoreExport serialize_checker<nickalias_map> NickAliasList; extern CoreExport serialize_checker<nickcore_map> NickCoreList; diff --git a/include/anope.h b/include/anope.h index 421f688ef..b6033b15c 100644 --- a/include/anope.h +++ b/include/anope.h @@ -15,9 +15,6 @@ namespace Anope { - template<typename T> class map : public std::map<string, T> { }; - template<typename T> class insensitive_map : public std::map<string, T, ci::less> { }; - /** * A wrapper string class around all the other string classes, this class will * allow us to only require one type of string everywhere that can be converted @@ -232,7 +229,7 @@ namespace Anope /** * Get the string in lowercase. */ - inline string lower() + inline string lower() const { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) @@ -243,7 +240,7 @@ namespace Anope /** * Get the string in uppercase. */ - inline string upper() + inline string upper() const { Anope::string new_string = *this; for (size_type i = 0; i < new_string.length(); ++i) @@ -286,6 +283,25 @@ namespace Anope inline const string operator+(const char *_str, const string &str) { string tmp(_str); tmp += str; return tmp; } inline const string operator+(const std::string &_str, const string &str) { string tmp(_str); tmp += str; return tmp; } + struct hash + { + inline size_t operator()(const string &s) const + { + return std::tr1::hash<std::string>()(s.lower().str()); + } + }; + + struct compare + { + inline bool operator()(const string &s1, const string &s2) const + { + return s1.equals_ci(s2); + } + }; + + template<typename T> class map : public std::map<string, T, ci::less> { }; + template<typename T> class hash_map : public std::tr1::unordered_map<string, T, hash, compare> { }; + static const char *const compiled = __TIME__ " " __DATE__; /** The current system time, which is pretty close to being accurate. diff --git a/include/bots.h b/include/bots.h index 19f921dbb..888e8d217 100644 --- a/include/bots.h +++ b/include/bots.h @@ -14,11 +14,9 @@ #include "commands.h" -typedef Anope::insensitive_map<BotInfo *> botinfo_map; -typedef Anope::map<BotInfo *> botinfouid_map; +typedef Anope::map<BotInfo *> botinfo_map; -extern CoreExport serialize_checker<botinfo_map> BotListByNick; -extern CoreExport serialize_checker<botinfouid_map> BotListByUID; +extern CoreExport serialize_checker<botinfo_map> BotListByNick, BotListByUID; /** Flags settable on a bot */ diff --git a/include/channels.h b/include/channels.h index 2c2fbb66d..da65c1a9c 100644 --- a/include/channels.h +++ b/include/channels.h @@ -14,7 +14,8 @@ #include "modes.h" #include "serialize.h" -typedef Anope::insensitive_map<Channel *> channel_map; +typedef Anope::hash_map<Channel *> channel_map; + extern CoreExport channel_map ChannelList; struct UserContainer : public Extensible diff --git a/include/commands.h b/include/commands.h index 08fb85d41..333d6882a 100644 --- a/include/commands.h +++ b/include/commands.h @@ -30,7 +30,7 @@ const Anope::string CommandFlagStrings[] = { struct CommandInfo { - typedef Anope::insensitive_map<CommandInfo> map; + typedef Anope::map<CommandInfo> map; Anope::string name; Anope::string permission; diff --git a/include/extensible.h b/include/extensible.h index 162a2cf6f..6db4cf112 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -25,7 +25,7 @@ template<typename T> struct CoreExport ExtensibleItemClass : T, ExtensibleItem class CoreExport Extensible { private: - typedef Anope::map<ExtensibleItem *> extensible_map; + typedef std::map<Anope::string, ExtensibleItem *> extensible_map; extensible_map extension_items; public: diff --git a/include/hashcomp.h b/include/hashcomp.h index f3621a52f..9f9be9793 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -16,6 +16,12 @@ #include <string> #include <locale> +#ifndef _WIN32 +#include <tr1/unordered_map> +#else +#include <unordered_map> +#endif + #include "services.h" namespace Anope diff --git a/include/regchannel.h b/include/regchannel.h index 12ef308b4..a692dda4a 100644 --- a/include/regchannel.h +++ b/include/regchannel.h @@ -18,7 +18,7 @@ #include "serialize.h" #include "bots.h" -typedef Anope::insensitive_map<ChannelInfo *> registered_channel_map; +typedef Anope::hash_map<ChannelInfo *> registered_channel_map; extern CoreExport serialize_checker<registered_channel_map> RegisteredChannelList; diff --git a/include/serialize.h b/include/serialize.h index 407540999..53bd096de 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -109,7 +109,7 @@ class CoreExport SerializeType typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &); static std::vector<Anope::string> type_order; - static Anope::map<SerializeType *> types; + static std::map<Anope::string, SerializeType *> types; Anope::string name; unserialize_func unserialize; diff --git a/include/service.h b/include/service.h index 98e2d82aa..95c650076 100644 --- a/include/service.h +++ b/include/service.h @@ -17,14 +17,14 @@ class CoreExport Service : public virtual Base { - static Anope::map<Anope::map<Service *> > services; + static std::map<Anope::string, std::map<Anope::string, Service *> > services; public: static Service *FindService(const Anope::string &t, const Anope::string &n) { - Anope::map<Anope::map<Service *> >::iterator it = services.find(t); + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t); if (it != services.end()) { - Anope::map<Service *>::iterator it2 = it->second.find(n); + std::map<Anope::string, Service *>::iterator it2 = it->second.find(n); if (it2 != it->second.end()) return it2->second; } @@ -35,9 +35,9 @@ class CoreExport Service : public virtual Base static std::vector<Anope::string> GetServiceKeys(const Anope::string &t) { std::vector<Anope::string> keys; - Anope::map<Anope::map<Service *> >::iterator it = services.find(t); + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = services.find(t); if (it != services.end()) - for (Anope::map<Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) + for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) keys.push_back(it2->first); return keys; } @@ -58,7 +58,7 @@ class CoreExport Service : public virtual Base void Register() { - Anope::map<Service *> &smap = services[this->type]; + std::map<Anope::string, Service *> &smap = services[this->type]; if (smap.find(this->name) != smap.end()) throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); smap[this->name] = this; @@ -66,7 +66,7 @@ class CoreExport Service : public virtual Base void Unregister() { - Anope::map<Service *> &smap = services[this->type]; + std::map<Anope::string, Service *> &smap = services[this->type]; smap.erase(this->name); if (smap.empty()) services.erase(this->type); diff --git a/include/sockets.h b/include/sockets.h index 7074522e0..6fa6c4075 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -90,7 +90,15 @@ class CoreExport cidr cidr(const Anope::string &ip, unsigned char len); Anope::string mask() const; bool match(sockaddrs &other); + bool operator<(const cidr &other) const; + bool operator==(const cidr &other) const; + bool operator!=(const cidr &other) const; + + struct hash + { + size_t operator()(const cidr &s) const; + }; }; class SocketException : public CoreException diff --git a/include/users.h b/include/users.h index 8757778b3..17f3fac9f 100644 --- a/include/users.h +++ b/include/users.h @@ -15,8 +15,9 @@ #include "commands.h" #include "account.h" -extern CoreExport Anope::insensitive_map<User *> UserListByNick; -extern CoreExport Anope::map<User *> UserListByUID; +typedef Anope::hash_map<User *> user_map; + +extern CoreExport user_map UserListByNick, UserListByUID; class CoreExport ChannelStatus : public Flags<ChannelModeName, CMODE_END * 2> { diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp index 176040b10..a4a7c2586 100644 --- a/modules/commands/bs_botlist.cpp +++ b/modules/commands/bs_botlist.cpp @@ -29,7 +29,7 @@ class CommandBSBotList : public Command list.addColumn("Nick").addColumn("Mask"); - for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) { BotInfo *bi = it->second; diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index 6c0dfa386..1425d1636 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -95,7 +95,7 @@ class CommandCSAKick : public Command { /* Match against all currently online users with equal or * higher access. - Viper */ - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u2 = it->second; diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index cbbd1c35c..d2686e013 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -21,7 +21,7 @@ enum TypeInfo struct SeenInfo; static SeenInfo *FindInfo(const Anope::string &nick); -typedef Anope::insensitive_map<SeenInfo *> database_map; +typedef Anope::hash_map<SeenInfo *> database_map; database_map database; struct SeenInfo : Serializable diff --git a/modules/commands/ns_ghost.cpp b/modules/commands/ns_ghost.cpp index 92d1840af..e7289f728 100644 --- a/modules/commands/ns_ghost.cpp +++ b/modules/commands/ns_ghost.cpp @@ -171,7 +171,7 @@ class NSGhost : public Module ~NSGhost() { - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) it->second->Shrink("ns_ghost_info"); } diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index ff840d353..f09d1f87a 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -163,7 +163,7 @@ class CommandOSAKill : public Command x->UID = XLineManager::GenerateUID(); unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (akills->Check(it->second, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index 2850e0203..0272742c1 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -153,9 +153,14 @@ class CommandOSUserList : public Command } else { + /* Historically this has been ordered, so... */ + Anope::map<User *> ordered_map; + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + ordered_map[it->first] = it->second; + source.Reply(_("Users list:")); - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (Anope::map<User *>::const_iterator it = ordered_map.begin(); it != ordered_map.end(); ++it) { User *u2 = it->second; diff --git a/modules/commands/os_login.cpp b/modules/commands/os_login.cpp index c282b9662..7b223eb1f 100644 --- a/modules/commands/os_login.cpp +++ b/modules/commands/os_login.cpp @@ -121,7 +121,7 @@ class OSLogin : public Module ~OSLogin() { - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) it->second->Shrink("os_login_password_correct"); } diff --git a/modules/commands/os_noop.cpp b/modules/commands/os_noop.cpp index 21ec0dd91..edb5b2eca 100644 --- a/modules/commands/os_noop.cpp +++ b/modules/commands/os_noop.cpp @@ -41,7 +41,7 @@ class CommandOSNOOP : public Command Anope::string reason = "NOOP command used by " + source.GetNick(); /* Kill all the IRCops of the server */ - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end();) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) { User *u2 = it->second; ++it; diff --git a/modules/commands/os_session.h b/modules/commands/os_session.h index ee37a7594..070975fd2 100644 --- a/modules/commands/os_session.h +++ b/modules/commands/os_session.h @@ -27,7 +27,7 @@ struct Exception : Serializable class SessionService : public Service { public: - typedef std::map<cidr, Session *> SessionMap; + typedef std::tr1::unordered_map<cidr, Session *, cidr::hash> SessionMap; typedef std::vector<Exception *> ExceptionVector; SessionService(Module *m) : Service(m, "SessionService", "session") { } diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp index a418396bd..83f13a90a 100644 --- a/modules/commands/os_stats.cpp +++ b/modules/commands/os_stats.cpp @@ -12,6 +12,7 @@ /*************************************************************************/ #include "module.h" +#include "os_session.h" struct Stats : Serializable { @@ -155,12 +156,52 @@ class CommandOSStats : public Command return; } + template<typename T> void GetHashStats(const T& map, size_t& entries, size_t& buckets, size_t& max_chain) + { + entries = map.size(), buckets = map.bucket_count(), max_chain = 0; + for (size_t i = 0; i < buckets; ++i) + if (map.bucket_size(i) > max_chain) + max_chain = map.bucket_size(i); + } + + void DoStatsHash(CommandSource &source) + { + size_t entries, buckets, max_chain; + + GetHashStats(UserListByNick, entries, buckets, max_chain); + source.Reply(_("Users (nick): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + + if (!UserListByUID.empty()) + { + GetHashStats(UserListByUID, entries, buckets, max_chain); + source.Reply(_("Users (uid): %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + } + + GetHashStats(ChannelList, entries, buckets, max_chain); + source.Reply(_("Channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + + GetHashStats(*RegisteredChannelList, entries, buckets, max_chain); + source.Reply(_("Registered channels: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + + GetHashStats(*NickAliasList, entries, buckets, max_chain); + source.Reply(_("Registered nicknames: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + + GetHashStats(*NickCoreList, entries, buckets, max_chain); + source.Reply(_("Registered nick groups: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + + if (session_service) + { + GetHashStats(session_service->GetSessions(), entries, buckets, max_chain); + source.Reply(_("Sessions: %lu entries, %lu buckets, longest chain is %d"), entries, buckets, max_chain); + } + } + public: CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1), akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline") { this->SetDesc(_("Show status of Services and network")); - this->SetSyntax(_("[AKILL | ALL | RESET | UPLINK]")); + this->SetSyntax(_("[AKILL | ALL | HASH | RESET | UPLINK]")); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override @@ -179,7 +220,10 @@ class CommandOSStats : public Command if (extra.equals_ci("ALL") || extra.equals_ci("UPLINK")) this->DoStatsUplink(source); - if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("UPLINK")) + if (extra.equals_ci("ALL") || extra.equals_ci("HASH")) + this->DoStatsHash(source); + + if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("UPLINK") && !extra.equals_ci("HASH")) source.Reply(_("Unknown STATS option \002%s\002."), extra.c_str()); } @@ -200,6 +244,8 @@ class CommandOSStats : public Command "The \002UPLINK\002 option displays information about the current\n" "server Anope uses as an uplink to the network.\n" " \n" + "The \002HASH\002 option displays information about the hash maps.\n" + " \n" "The \002ALL\002 displays the user and uptime statistics, and\n" "everything you'd see with the \002UPLINK\002 option.")); return true; diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index 8cd3d9f7a..ea7f7840d 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -357,7 +357,7 @@ class CommandOSSNLine : public CommandOSSXLineBase x->UID = XLineManager::GenerateUID(); unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (this->xlm()->Check(it->second, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -386,7 +386,7 @@ class CommandOSSNLine : public CommandOSSXLineBase Anope::string rreason = "G-Lined: " + reason; - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *user = it->second; ++it; @@ -560,7 +560,7 @@ class CommandOSSQLine : public CommandOSSXLineBase x->UID = XLineManager::GenerateUID(); unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (this->xlm()->Check(it->second, x)) ++affected; float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; @@ -607,7 +607,7 @@ class CommandOSSQLine : public CommandOSSXLineBase } else { - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *user = it->second; ++it; diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp index 1017db8cc..e6d430556 100644 --- a/modules/database/db_plain.cpp +++ b/modules/database/db_plain.cpp @@ -731,7 +731,7 @@ class DBPlain : public Module //FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na)); } - for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) + for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) { BotInfo *bi = it->second; diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index c5be3c3fa..4a5362bcc 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -198,7 +198,7 @@ class BahamutIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index 88d10a841..52f58f254 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -127,7 +127,7 @@ class HybridProto : public IRCDProto * No user (this akill was just added), and contains nick and/or realname. * Find users that match and ban them. */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h index a10deea4f..38ad32e26 100644 --- a/modules/protocol/inspircd-ts6.h +++ b/modules/protocol/inspircd-ts6.h @@ -151,7 +151,7 @@ class InspIRCdTS6Proto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index d1ee82bbb..10a47ae3e 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -116,7 +116,7 @@ class InspIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 97d2b6259..3d925bd4a 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -534,7 +534,7 @@ class ProtoInspIRCd : public Module void OnServerSync(Server *s) anope_override { if (nickserv) - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 2d3a3c4f2..8dbdfb2ff 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -630,7 +630,7 @@ class ProtoInspIRCd : public Module void OnServerSync(Server *s) anope_override { if (nickserv) - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 5f1af0cec..948a715ac 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -107,7 +107,7 @@ class PlexusProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; @@ -757,7 +757,7 @@ class ProtoPlexus : public Module void OnServerSync(Server *s) anope_override { if (nickserv) - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 4acf5e79a..317ced1ff 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -97,7 +97,7 @@ class RatboxProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; @@ -631,7 +631,7 @@ class ProtoRatbox : public Module void OnServerSync(Server *s) anope_override { if (nickserv) - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; if (u->server == s && !u->IsIdentified()) diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index 1e89f4795..03a63687f 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -88,7 +88,7 @@ class UnrealIRCdProto : public IRCDProto if (!u) { /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) if (x->manager->Check(it->second, x)) this->SendAkill(it->second, x); return; diff --git a/src/base.cpp b/src/base.cpp index 492ef4628..af2b38fde 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -6,7 +6,7 @@ #include "access.h" #include "bots.h" -Anope::map<Anope::map<Service *> > Service::services; +std::map<Anope::string, std::map<Anope::string, Service *> > Service::services; void RegisterTypes() { diff --git a/src/bots.cpp b/src/bots.cpp index 95e28e5f0..7bb5ace5d 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -18,8 +18,7 @@ #include "extern.h" #include "serialize.h" -serialize_checker<botinfo_map> BotListByNick("BotInfo"); -serialize_checker<botinfouid_map> BotListByUID("BotInfo"); +serialize_checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo"); BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), Serializable("BotInfo"), botmodes(bmodes) { diff --git a/src/botserv.cpp b/src/botserv.cpp index 27666f7ec..04949b427 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -27,7 +27,7 @@ BotInfo* findbot(const Anope::string &nick) BotInfo *bi = NULL; if (isdigit(nick[0]) && ircdproto->RequiresID) { - botinfouid_map::iterator it = BotListByUID->find(nick); + botinfo_map::iterator it = BotListByUID->find(nick); if (it != BotListByUID->end()) bi = it->second; } diff --git a/src/main.cpp b/src/main.cpp index 26e7e67ff..2cbacbb0f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,7 +118,7 @@ UplinkSocket::~UplinkSocket() { FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect()); - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; diff --git a/src/serialize.cpp b/src/serialize.cpp index 45a43fb8e..a84d103f5 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -16,7 +16,7 @@ #include "modules.h" std::vector<Anope::string> SerializeType::type_order; -Anope::map<SerializeType *> SerializeType::types; +std::map<Anope::string, SerializeType *> SerializeType::types; std::list<Serializable *> *Serializable::serializable_items; stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0) @@ -204,7 +204,7 @@ Module* SerializeType::GetOwner() const SerializeType *SerializeType::Find(const Anope::string &name) { - Anope::map<SerializeType *>::iterator it = types.find(name); + std::map<Anope::string, SerializeType *>::iterator it = types.find(name); if (it != types.end()) return it->second; return NULL; diff --git a/src/servers.cpp b/src/servers.cpp index 8c134848b..3a44c8e65 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -91,7 +91,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A } /* We make the bots go online */ - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(), it_end = UserListByNick.end(); it != it_end; ++it) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { User *u = it->second; @@ -130,7 +130,7 @@ Server::~Server() if (Capab.count("NOQUIT") > 0 || Capab.count("QS") > 0) { - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) { User *u = it->second; ++it; diff --git a/src/sockets.cpp b/src/sockets.cpp index 5cf567de5..861df6976 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -295,6 +295,44 @@ bool cidr::operator<(const cidr &other) const } } +bool cidr::operator==(const cidr &other) const +{ + return !(*this < other) && !(other < *this); +} + +bool cidr::operator!=(const cidr &other) const +{ + return !(*this == other); +} + +size_t cidr::hash::operator()(const cidr &s) const +{ + switch (s.addr.sa.sa_family) + { + case AF_INET: + { + unsigned int m = 0xFFFFFFFFU >> (32 - s.cidr_len); + return s.addr.sa4.sin_addr.s_addr & m; + } + case AF_INET6: + { + size_t h = 0; + + for (int i = 0; i < s.cidr_len / 8; ++i) + h ^= (s.addr.sa6.sin6_addr.s6_addr[i] << ((i * 8) % sizeof(size_t))); + + int remaining = s.cidr_len % 8; + unsigned char m = 0xFF << (8 - remaining); + + h ^= s.addr.sa6.sin6_addr.s6_addr[s.cidr_len / 8] & m; + + return h; + } + default: + throw CoreException("Unknown AFTYPE for cidr"); + } +} + /** Receive something from the buffer * @param s The socket * @param buf The buf to read to diff --git a/src/users.cpp b/src/users.cpp index 187e55808..684817d2e 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -22,8 +22,7 @@ #include "opertype.h" #include "extern.h" -Anope::insensitive_map<User *> UserListByNick; -Anope::map<User *> UserListByUID; +user_map UserListByNick, UserListByUID; int32_t opcnt = 0; uint32_t usercnt = 0, maxusercnt = 0; @@ -856,13 +855,13 @@ User *finduser(const Anope::string &nick) { if (isdigit(nick[0]) && ircdproto->RequiresID) { - Anope::map<User *>::iterator it = UserListByUID.find(nick); + user_map::iterator it = UserListByUID.find(nick); if (it != UserListByUID.end()) return it->second; } else { - Anope::insensitive_map<User *>::iterator it = UserListByNick.find(nick); + user_map::iterator it = UserListByNick.find(nick); if (it != UserListByNick.end()) return it->second; } |