]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move autoconnect next-server to TreeSocket::cull, and drop autoconnect reference...
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 9 Oct 2009 21:31:50 +0000 (21:31 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 9 Oct 2009 21:31:50 +0000 (21:31 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11811 e03df62e-2008-0410-955e-edbf42e46eb7

src/inspsocket.cpp
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/resolvers.cpp
src/modules/m_spanningtree/treesocket1.cpp
src/modules/m_spanningtree/treesocket2.cpp

index 60c69559d4e034c9fdff803ebeb8e62572d85f11..73f469a0513dabe232884c0104f8e7055aa4d732 100644 (file)
@@ -441,6 +441,8 @@ BufferedSocket::~BufferedSocket()
 
 void StreamSocket::HandleEvent(EventType et, int errornum)
 {
+       if (!error.empty())
+               return;
        BufferedSocketError errcode = I_ERR_OTHER;
        switch (et)
        {
index 23523107af5308b4e4ea617920964c3b89019da9..e71e55ae842281860f89ee04f2dc33851ffda099 100644 (file)
@@ -243,25 +243,41 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
        }
 }
 
-void ModuleSpanningTree::ConnectServer(Autoconnect* y)
+void ModuleSpanningTree::ConnectServer(Autoconnect* a, bool on_timer)
 {
-       if (!y)
+       if (!a)
                return;
-       y->position++;
-       while (y->position < (int)y->servers.size())
+       for(unsigned int j=0; j < a->servers.size(); j++)
        {
-               Link* x = Utils->FindLink(y->servers[y->position]);
+               if (Utils->FindServer(a->servers[j]))
+               {
+                       // found something in this block. Should the server fail,
+                       // we want to start at the start of the list, not in the
+                       // middle where we left off
+                       a->position = -1;
+                       return;
+               }
+       }
+       if (on_timer && a->position >= 0)
+               return;
+       if (!on_timer && a->position < 0)
+               return;
+
+       a->position++;
+       while (a->position < (int)a->servers.size())
+       {
+               Link* x = Utils->FindLink(a->servers[a->position]);
                if (x)
                {
                        ServerInstance->SNO->WriteToSnoMask('l', "AUTOCONNECT: Auto-connecting server \002%s\002", x->Name.c_str());
-                       ConnectServer(x, y);
+                       ConnectServer(x, a);
                        return;
                }
-               y->position++;
+               a->position++;
        }
        // Autoconnect chain has been fully iterated; start at the beginning on the
        // next AutoConnectServers run
-       y->position = -1;
+       a->position = -1;
 }
 
 void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
@@ -303,7 +319,6 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
                {
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(),strerror(errno));
                        ServerInstance->GlobalCulls.AddItem(newsocket);
-                       ConnectServer(y);
                }
        }
        else
@@ -317,7 +332,7 @@ void ModuleSpanningTree::ConnectServer(Link* x, Autoconnect* y)
                catch (ModuleException& e)
                {
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",x->Name.c_str(), e.GetReason());
-                       ConnectServer(y);
+                       ConnectServer(y, false);
                }
        }
 }
@@ -330,28 +345,13 @@ void ModuleSpanningTree::AutoConnectServers(time_t curtime)
                if (curtime >= x->NextConnectTime)
                {
                        x->NextConnectTime = curtime + x->Period;
-                       for(unsigned int j=0; j < x->servers.size(); j++)
-                       {
-                               if (Utils->FindServer(x->servers[j]))
-                               {
-                                       // found something in this block. Should the server fail,
-                                       // we want to start at the start of the list, not in the
-                                       // middle where we left off
-                                       x->position = -1;
-                                       goto dupe_found; // next autoconnect block
-                               }
-                       }
-                       // only start a new chain if we aren't running
-                       if (x->position == -1)
-                               ConnectServer(x);
+                       ConnectServer(x, true);
                }
-dupe_found:;
        }
 }
 
 void ModuleSpanningTree::DoConnectTimeout(time_t curtime)
 {
-       std::vector<Autoconnect*> failovers;
        std::map<TreeSocket*, std::pair<std::string, int> >::iterator i = Utils->timeoutlist.begin();
        while (i != Utils->timeoutlist.end())
        {
@@ -362,18 +362,11 @@ void ModuleSpanningTree::DoConnectTimeout(time_t curtime)
                if (curtime > s->age + p.second)
                {
                        ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002 (timeout of %d seconds)",p.first.c_str(),p.second);
-                       if (s->myautoconnect)
-                               failovers.push_back(s->myautoconnect);
                        Utils->timeoutlist.erase(me);
                        s->Close();
                        ServerInstance->GlobalCulls.AddItem(s);
                }
        }
-       for(unsigned int j=0; j < failovers.size(); j++)
-       {
-               if (failovers[j]->position >= 0)
-                       ConnectServer(failovers[j]);
-       }
 }
 
 ModResult ModuleSpanningTree::HandleVersion(const std::vector<std::string>& parameters, User* user)
index 1057fcdfc511ee45432447e86bad9ac2a4d9b033..66b396171160e8c793ec9576a92791e05a4f1ac0 100644 (file)
@@ -124,7 +124,7 @@ class ModuleSpanningTree : public Module
 
        /** Connect the next autoconnect server
         */
-       void ConnectServer(Autoconnect* y);
+       void ConnectServer(Autoconnect* y, bool on_timer);
 
        /** Check if any servers are due to be autoconnected
         */
index b95ba79c3dff1aa3eee8b64a8ff8d2a36155ceeb..0133b332a47ca21f1b71fa439a4fa973b84354a1 100644 (file)
@@ -55,7 +55,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
                        /* Something barfed, show the opers */
                        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",MyLink->Name.c_str(),strerror(errno));
                        ServerInstance->GlobalCulls.AddItem(newsocket);
-                       Utils->Creator->ConnectServer(myautoconnect);
+                       Utils->Creator->ConnectServer(myautoconnect, false);
                }
        }
 }
@@ -71,6 +71,6 @@ void ServernameResolver::OnError(ResolverError e, const std::string &errormessag
                return;
        }
        ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s", MyLink->Name.c_str(), errormessage.c_str() );
-       Utils->Creator->ConnectServer(myautoconnect);
+       Utils->Creator->ConnectServer(myautoconnect, false);
 }
 
index 432ee2a098d7a8a57c6b5dc43fb06e5c9e685dbd..7e62d6a2c69988ae4789ce32e2865794e114874c 100644 (file)
@@ -106,6 +106,8 @@ void TreeSocket::CleanNegotiationInfo()
 bool TreeSocket::cull()
 {
        Utils->timeoutlist.erase(this);
+       if (myautoconnect)
+               Utils->Creator->ConnectServer(myautoconnect, false);
        return this->BufferedSocket::cull();
 }
 
@@ -150,7 +152,6 @@ void TreeSocket::OnError(BufferedSocketError e)
        {
                case I_ERR_CONNECT:
                        ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Connection to \002%s\002 refused", myhost.c_str());
-                       Utils->Creator->ConnectServer(myautoconnect);
                break;
                case I_ERR_SOCKET:
                        ServerInstance->SNO->WriteToSnoMask('l', "Connection failed: Could not create socket (%s)", strerror(errno));
index c670e4b9a73966f5cb232d0c7551c64dc0508f24..11c9c04f93eacb5f6cff72d3a9f35598bd9fa180 100644 (file)
@@ -161,6 +161,11 @@ void TreeSocket::ProcessLine(std::string &line)
                                this->LinkState = CONNECTED;
 
                                Utils->timeoutlist.erase(this);
+                               if (myautoconnect)
+                               {
+                                       myautoconnect->position = -1;
+                                       myautoconnect = NULL;
+                               }
 
                                Link* lnk = Utils->FindLink(InboundServerName);
 
@@ -534,7 +539,6 @@ void TreeSocket::OnTimeout()
        if (this->LinkState == CONNECTING)
        {
                ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
-               Utils->Creator->ConnectServer(myautoconnect);
        }
 }