]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Implement timeout on outgoing server connections as per our docs <link:timeout>
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 19 Sep 2008 02:00:04 +0000 (02:00 +0000)
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>
Fri, 19 Sep 2008 02:00:04 +0000 (02:00 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10558 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/treesocket1.cpp
src/modules/m_spanningtree/treesocket2.cpp
src/modules/m_spanningtree/utils.h

index c14687804ee8332be0d877f8e45b3169aadab72c..264ee1078cbc6fe9a4a9f25ecf238ca6c29ad35a 100644 (file)
@@ -333,6 +333,21 @@ void ModuleSpanningTree::AutoConnectServers(time_t curtime)
        }
 }
 
+void ModuleSpanningTree::DoConnectTimeout(time_t curtime)
+{
+       for (std::map<TreeSocket*, std::pair<std::string, int> >::iterator i = Utils->timeoutlist.begin(); i != Utils->timeoutlist.end(); i++)
+       {
+               TreeSocket* s = i->first;
+               std::pair<std::string, int> p = i->second;
+               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);
+                       ServerInstance->SE->DelFd(s);
+                       s->Close();
+               }
+       }                                                    
+}
+
 int ModuleSpanningTree::HandleVersion(const std::vector<std::string>& parameters, User* user)
 {
        // we've already checked if pcnt > 0, so this is safe
@@ -573,6 +588,7 @@ void ModuleSpanningTree::OnBackgroundTimer(time_t curtime)
 {
        AutoConnectServers(curtime);
        DoPingChecks(curtime);
+       DoConnectTimeout(curtime);
 }
 
 void ModuleSpanningTree::OnUserJoin(User* user, Channel* channel, bool sync, bool &silent)
index 861bf7e14f2eccfe86367ced062af86d25d25a75..8cfcaaa02052a0d25fd98f9d120344514fe02818 100644 (file)
@@ -124,6 +124,10 @@ class ModuleSpanningTree : public Module
         */
        void AutoConnectServers(time_t curtime);
 
+       /** Check if any connecting servers should timeout
+        */
+       void DoConnectTimeout(time_t curtime);
+
        /** Handle remote VERSON
         */
        int HandleVersion(const std::vector<std::string>& parameters, User* user);
index 589e05bcd95777674c2cae1a15087f9148ba3fce..09c3158cccf980ad3f6ce029710d936a8b88f1b5 100644 (file)
@@ -43,6 +43,7 @@ TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string sh
        theirchallenge.clear();
        ourchallenge.clear();
        this->LinkState = CONNECTING;
+       Utils->timeoutlist[this] = std::pair<std::string, int>(ServerName,maxtime);
        if (Hook)
                BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
 }
@@ -81,6 +82,7 @@ TreeSocket::~TreeSocket()
 {
        if (Hook)
                BufferedSocketUnhookRequest(this, (Module*)Utils->Creator, Hook).Send();
+       Utils->timeoutlist.erase(this);
 }
 
 /** When an outbound connection finishes connecting, we receive
index c2664a65e6b209298906b145ed2fe1c9e80cd542..c1b45237df2dfc0c85de78e6504472a54547bbee 100644 (file)
@@ -175,6 +175,8 @@ bool TreeSocket::ProcessLine(std::string &line)
                                this->LinkState = CONNECTED;
                                Link* lnk = Utils->FindLink(InboundServerName);
 
+                               Utils->timeoutlist.erase(this);
+
                                Node = new TreeServer(this->Utils, this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
 
                                if (Node->DuplicateID())
index 1022c179663924117991ccd53c7e8cfe90e9e49f..839c1899cc05dfeef626d4a3d1261078d036425d 100644 (file)
@@ -109,6 +109,9 @@ class SpanningTreeUtilities : public classbase
        /** Hash of servers currently bursting but not initialized as connected
         */
        std::map<irc::string,TreeSocket*> burstingserverlist;
+       /** List of all outgoing sockets and their timeouts
+        */
+       std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
        /** Holds the data from the <link> tags in the conf
         */
        std::vector<Link> LinkBlocks;