From b6de4410321b26eb4a591d2693078a5ef5c7e582 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 4 Dec 2005 19:25:33 +0000 Subject: Server to server ping checks git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2161 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp index 4b446aa3c..439bd9fd6 100644 --- a/src/modules/m_spanningtree.cpp +++ b/src/modules/m_spanningtree.cpp @@ -308,6 +308,8 @@ class TreeSocket : public InspSocket std::string InboundDescription; int num_lost_users; int num_lost_servers; + time_t NextPing; + bool LastPingWasGood; public: @@ -351,6 +353,27 @@ class TreeSocket : public InspSocket } return true; } + + void SetNextPingTime(time_t t) + { + this->NextPing = t; + LastPingWasGood = false; + } + + time_t NextPingTime() + { + return this->NextPing; + } + + bool AnsweredLastPing() + { + return LastPingWasGood; + } + + void SetPingFlag() + { + LastPingWasGood = true; + } virtual void OnError(InspSocketError e) { @@ -842,6 +865,27 @@ class TreeSocket : public InspSocket return true; } + bool LocalPong(std::string prefix, std::deque params) + { + if (params.size() < 1) + return true; + TreeServer* ServerSource = FindServer(prefix); + if (ServerSource) + { + ServerSource->SetPingFlag(); + } + return true; + } + + bool LocalPing(std::string prefix, std::deque params) + { + if (params.size() < 1) + return true; + std::string stufftobounce = params[0]; + this->WriteLine(":"+Srv->GetServerName()+" PONG "+stufftobounce); + return true; + } + bool RemoteServer(std::string prefix, std::deque params) { if (params.size() < 4) @@ -1137,6 +1181,14 @@ class TreeSocket : public InspSocket { return this->RemoteRehash(prefix,params); } + else if (command == "PING") + { + return this->LocalPing(prefix,params); + } + else if (command == "PONG") + { + return this->LocalPong(prefix,params); + } else if (command == "SQUIT") { if (params.size() == 2) @@ -1609,6 +1661,34 @@ class ModuleSpanningTree : public Module return 1; } + void DoPingChecks(time_t curtime) + { + for (unsigned int j = 0; j < TreeRoot->ChildCount(); j++) + { + TreeServer* serv = TreeRoot->GetChild(j); + TreeSocket* sock = serv->GetSocket(); + if (sock) + { + if (serv->NextPingTime() > curtime) + { + if (serv->AnsweredLastPing()) + { + sock->WriteLine(":"+Srv->GetServerName()+" PING "+serv->GetName()); + serv->SetNextPingTime(curtime + 60); + } + else + { + // they didnt answer, boot them + WriteOpers("*** Server \002%s\002 pinged out",serv->GetName().c_str()); + sock->Squit(serv,"Ping timeout"); + sock->Close(); + return; + } + } + } + } + } + void AutoConnectServers(time_t curtime) { for (std::vector::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++) @@ -1807,6 +1887,7 @@ class ModuleSpanningTree : public Module virtual void OnBackgroundTimer(time_t curtime) { AutoConnectServers(curtime); + DoPingChecks(curtime); } virtual void OnUserJoin(userrec* user, chanrec* channel) -- cgit v1.2.3