diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-04 19:25:33 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-04 19:25:33 +0000 |
commit | b6de4410321b26eb4a591d2693078a5ef5c7e582 (patch) | |
tree | 49b827af162ad65dd58264886dd6a4916e7d66a5 /src | |
parent | cf6c6cd7d41561c020e0f96ab1c36090a78cb8aa (diff) |
Server to server ping checks
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2161 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/m_spanningtree.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
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<std::string> params) + { + if (params.size() < 1) + return true; + TreeServer* ServerSource = FindServer(prefix); + if (ServerSource) + { + ServerSource->SetPingFlag(); + } + return true; + } + + bool LocalPing(std::string prefix, std::deque<std::string> 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<std::string> 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<Link>::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) |