summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-19 02:00:04 +0000
committerpeavey <peavey@e03df62e-2008-0410-955e-edbf42e46eb7>2008-09-19 02:00:04 +0000
commitb7a20454ce09b3e8f81ca76d86b45993e3be0a86 (patch)
tree1db9c2e920350b36610e098dd7fab54a24f7eaf8
parente1a9c3a9bc1e8afc90548a10f714c3f30794a9ec (diff)
Implement timeout on outgoing server connections as per our docs <link:timeout>
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10558 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/m_spanningtree/main.cpp16
-rw-r--r--src/modules/m_spanningtree/main.h4
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp2
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp2
-rw-r--r--src/modules/m_spanningtree/utils.h3
5 files changed, 27 insertions, 0 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index c14687804..264ee1078 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -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)
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index 861bf7e14..8cfcaaa02 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -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);
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 589e05bcd..09c3158cc 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -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
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index c2664a65e..c1b45237d 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -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())
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index 1022c1796..839c1899c 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -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;