From: danieldg Date: Fri, 9 Oct 2009 21:31:50 +0000 (+0000) Subject: Move autoconnect next-server to TreeSocket::cull, and drop autoconnect reference... X-Git-Tag: v2.0.23~1442 X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=ae4c387422251da208c4b5492a9ebe72d524805e;p=user%2Fhenk%2Fcode%2Finspircd.git Move autoconnect next-server to TreeSocket::cull, and drop autoconnect reference once a connection is complete git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11811 e03df62e-2008-0410-955e-edbf42e46eb7 --- diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 60c69559d..73f469a05 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -441,6 +441,8 @@ BufferedSocket::~BufferedSocket() void StreamSocket::HandleEvent(EventType et, int errornum) { + if (!error.empty()) + return; BufferedSocketError errcode = I_ERR_OTHER; switch (et) { diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 23523107a..e71e55ae8 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -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 failovers; std::map >::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& parameters, User* user) diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 1057fcdfc..66b396171 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -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 */ diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp index b95ba79c3..0133b332a 100644 --- a/src/modules/m_spanningtree/resolvers.cpp +++ b/src/modules/m_spanningtree/resolvers.cpp @@ -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); } diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index 432ee2a09..7e62d6a2c 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -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)); diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index c670e4b9a..11c9c04f9 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -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); } }