diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-24 01:49:07 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-05-24 01:49:07 +0000 |
commit | 5b08c0883c83c95ceca07e590620fe254b17f6ab (patch) | |
tree | 7ea4f795eb8a18530e231dc5ce2bac41027c3eb4 /src | |
parent | 0a1ef900f98881a03dfa0945ff1eddfa8b1dfba5 (diff) |
Added ping checks for server links (experimental)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1481 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.cpp | 4 | ||||
-rw-r--r-- | src/connection.cpp | 31 | ||||
-rw-r--r-- | src/servers.cpp | 10 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/commands.cpp b/src/commands.cpp index 916c9bc10..b66ad514c 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -2809,6 +2809,8 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve char buffer[MAXBUF]; int MOD_RESULT = 0; + ircd_connector* cn = source->FindHost(tcp_host); + switch(token) { // Y <TS> @@ -2857,6 +2859,8 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve // ? // pong case '!': + if (cn) + cn->ResetPing(); break; // * // no operation diff --git a/src/connection.cpp b/src/connection.cpp index c7221ce74..2f6cbd6d5 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -82,6 +82,8 @@ ircd_connector::ircd_connector() port = 0; sendq = ""; WriteError = ""; + nextping = TIME+30; + replied = false; } char* ircd_connector::GetServerIP() @@ -179,6 +181,35 @@ bool ircd_connector::HasBufferedOutput() return (sendq.length() > 0); } +bool ircd_connector::CheckPing() +{ + if (TIME > this->nextping) + { + if (this->replied) + { + this->AddWriteBuf("?\n"); + this->nextping = TIME+30; + this->replied = false; + return true; + } + else + { + this->SetWriteError("Ping timeout"); + this->CloseConnection(); + this->SetState(STATE_DISCONNECTED); + WriteOpers("*** Ping timeout on link to %s (more routes may remain)",this->GetServerName().c_str()); + return false; + } + } +} + +void ircd_connector::ResetPing() +{ + log(DEBUG,"Reset ping counter"); + this->replied = true; + this->nextping = TIME+30; +} + // send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it) bool ircd_connector::FlushWriteBuf() { diff --git a/src/servers.cpp b/src/servers.cpp index 15929345f..38f9cfb5f 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -250,6 +250,15 @@ void serverrec::FlushWriteBuffers() { for (int i = 0; i < this->connectors.size(); i++) { + if (this->connectors[i].GetState() != STATE_DISCONNECTED) + { + if (!this->connectors[i].CheckPing()) + { + WriteOpers("*** Lost single connection to %s: Ping timeout",this->connectors[i].GetServerName().c_str()); + this->connectors[i].CloseConnection(); + this->connectors[i].SetState(STATE_DISCONNECTED); + } + } if (this->connectors[i].HasBufferedOutput()) { if (!this->connectors[i].FlushWriteBuf()) @@ -400,6 +409,7 @@ bool serverrec::RecvPacket(std::deque<std::string> &messages, char* recvhost,std } if (this->connectors[i].BufferIsComplete()) { + this->connectors[i].ResetPing(); while (this->connectors[i].BufferIsComplete()) { std::string text = this->connectors[i].GetBuffer(); |