]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/utils.cpp
Introduce Stats::Context, pass it to the OnStats hook and switch all code to it
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.cpp
index fd51fb6b4c9d88802b9f340846e9836937f7ce7e..bbda2634d5ae6b67c3e7209ff2e346d801cf5104 100644 (file)
@@ -31,7 +31,6 @@
 
 SpanningTreeUtilities* Utils = NULL;
 
-/* Create server sockets off a listener. */
 ModResult ModuleSpanningTree::OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server)
 {
        if (from->bind_tag->getString("type") != "servers")
@@ -52,12 +51,6 @@ ModResult ModuleSpanningTree::OnAcceptConnection(int newsock, ListenSocket* from
        return MOD_RES_DENY;
 }
 
-/** Yay for fast searches!
- * This is hundreds of times faster than recursion
- * or even scanning a linked list, especially when
- * there are more than a few servers to deal with.
- * (read as: lots).
- */
 TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
 {
        if (InspIRCd::IsSID(ServerName))
@@ -101,10 +94,7 @@ TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
 }
 
 /** Find the first server matching a given glob mask.
- * Theres no find-using-glob method of hash_map [awwww :-(]
- * so instead, we iterate over the list using an iterator
- * and match each one until we get a hit. Yes its slow,
- * deal with it.
+ * We iterate over the list and match each one until we get a hit.
  */
 TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
 {
@@ -127,8 +117,9 @@ TreeServer* SpanningTreeUtilities::FindServerID(const std::string &id)
 
 SpanningTreeUtilities::SpanningTreeUtilities(ModuleSpanningTree* C)
        : Creator(C), TreeRoot(NULL)
+       , PingFreq(60) // XXX: TreeServer constructor reads this and TreeRoot is created before the config is read, so init it to something (value doesn't matter) to avoid a valgrind warning in TimerManager on unload
 {
-       ServerInstance->Timers->AddTimer(&RefreshTimer);
+       ServerInstance->Timers.AddTimer(&RefreshTimer);
 }
 
 CullResult SpanningTreeUtilities::cull()
@@ -155,7 +146,7 @@ SpanningTreeUtilities::~SpanningTreeUtilities()
        delete TreeRoot;
 }
 
-/* returns a list of DIRECT servernames for a specific channel */
+// Returns a list of DIRECT servers for a specific channel
 void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list)
 {
        unsigned int minrank = 0;
@@ -166,9 +157,8 @@ void SpanningTreeUtilities::GetListOfServersForChannel(Channel* c, TreeSocketSet
                        minrank = mh->GetPrefixRank();
        }
 
-       const UserMembList *ulist = c->GetUsers();
-
-       for (UserMembCIter i = ulist->begin(); i != ulist->end(); i++)
+       const Channel::MemberMap& ulist = c->GetUsers();
+       for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i)
        {
                if (IS_LOCAL(i->first))
                        continue;
@@ -214,7 +204,9 @@ bool SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, const std::stri
 void SpanningTreeUtilities::DoOneToOne(const CmdBuilder& params, Server* server)
 {
        TreeServer* ts = static_cast<TreeServer*>(server);
-       ts->GetSocket()->WriteLine(params);
+       TreeSocket* sock = ts->GetSocket();
+       if (sock)
+               sock->WriteLine(params);
 }
 
 void SpanningTreeUtilities::RefreshIPCache()
@@ -259,7 +251,6 @@ void SpanningTreeUtilities::ReadConfiguration()
        HideULines = security->getBool("hideulines");
        AnnounceTSChange = options->getBool("announcets");
        AllowOptCommon = options->getBool("allowmismatch");
-       ChallengeResponse = !security->getBool("disablehmac");
        quiet_bursts = ServerInstance->Config->ConfValue("performance")->getBool("quietbursts");
        PingWarnTime = options->getInt("pingwarning");
        PingFreq = options->getInt("serverpingfreq");
@@ -301,8 +292,8 @@ void SpanningTreeUtilities::ReadConfiguration()
                if (L->Name.find('.') == std::string::npos)
                        throw ModuleException("The link name '"+assign(L->Name)+"' is invalid as it must contain at least one '.' character");
 
-               if (L->Name.length() > 64)
-                       throw ModuleException("The link name '"+assign(L->Name)+"' is invalid as it is longer than 64 characters");
+               if (L->Name.length() > ServerInstance->Config->Limits.MaxHost)
+                       throw ModuleException("The link name '"+assign(L->Name)+"' is invalid as it is longer than " + ConvToStr(ServerInstance->Config->Limits.MaxHost) + " characters");
 
                if (L->RecvPass.empty())
                        throw ModuleException("Invalid configuration for server '"+assign(L->Name)+"', recvpass not defined");
@@ -363,7 +354,7 @@ Link* SpanningTreeUtilities::FindLink(const std::string& name)
        for (std::vector<reference<Link> >::iterator i = LinkBlocks.begin(); i != LinkBlocks.end(); ++i)
        {
                Link* x = *i;
-               if (InspIRCd::Match(x->Name.c_str(), name.c_str()))
+               if (InspIRCd::Match(x->Name.c_str(), name.c_str(), rfc_case_insensitive_map))
                {
                        return x;
                }