From 67e3dfa0fb911b183ceca767f525087ee16acf6e Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 5 Dec 2005 22:00:42 +0000 Subject: Optimizing spanning tree git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2204 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index cbf7f5b06..8227d1a0b 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -69,6 +69,7 @@ void ReadConfiguration(bool rebind); class TreeServer { TreeServer* Parent; + TreeServer* Route; std::vector Children; std::string ServerName; std::string ServerDesc; @@ -97,6 +98,7 @@ class TreeServer VersionString = ""; UserCount = OperCount = 0; VersionString = GetVersionString(); + Route = this; } TreeServer(std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock) : Parent(Above), ServerName(Name), ServerDesc(Desc), Socket(Sock) @@ -105,6 +107,18 @@ class TreeServer UserCount = OperCount = 0; this->SetNextPingTime(time(NULL) + 60); this->SetPingFlag(); + + // find the 'route' for this server (e.g. the one directly connected + // to the local server, which we can use to reach it) + Route = Above; + if (Route != TreeRoot) + while (Route->GetParent() != TreeRoot) + Route = Route->GetParent(); + } + + TreeServer* GetRoute() + { + return Route; } std::string GetName() @@ -246,14 +260,12 @@ std::vector LinkBlocks; TreeServer* RouteEnumerate(TreeServer* Current, std::string ServerName) { if (Current->GetName() == ServerName) - return Current; + return Current->GetRoute(); for (unsigned int q = 0; q < Current->ChildCount(); q++) { TreeServer* found = RouteEnumerate(Current->GetChild(q),ServerName); if (found) - { - return found; - } + return found->GetRoute(); } return NULL; } @@ -269,22 +281,7 @@ TreeServer* BestRouteTo(std::string ServerName) } // first, find the server by recursively walking the tree TreeServer* Found = RouteEnumerate(TreeRoot,ServerName); - // did we find it? If not, they did something wrong, abort. - if (!Found) - { - return NULL; - } - else - { - // The server exists, follow its parent nodes until - // the parent of the current is 'TreeRoot', we know - // then that this is a directly-connected server. - while ((Found) && (Found->GetParent() != TreeRoot)) - { - Found = Found->GetParent(); - } - return Found; - } + return Found; } bool LookForServer(TreeServer* Current, std::string ServerName) -- cgit v1.2.3