diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-04-13 17:41:22 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-04-13 17:41:22 +0200 |
commit | 2f17664ea13fe8f0983080d69886a46b58e5e266 (patch) | |
tree | 5b563e7d6b2b796aefbb028ed6af7c2df1f28391 | |
parent | 4facf97111ce2c028d0c0c2292562a0d6a703395 (diff) |
m_spanningtree Remove redundant first parameter of PING/PONG
-rw-r--r-- | src/modules/m_spanningtree/compat.cpp | 41 | ||||
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_spanningtree/ping.cpp | 30 | ||||
-rw-r--r-- | src/modules/m_spanningtree/pong.cpp | 38 |
4 files changed, 61 insertions, 51 deletions
diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 30b7ba8bb..433da9847 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -20,6 +20,7 @@ #include "inspircd.h" #include "main.h" #include "treesocket.h" +#include "treeserver.h" static std::string newline("\n"); @@ -130,6 +131,15 @@ void TreeSocket::WriteLine(std::string line) line.erase(c, d-c); } + else if ((command == "PING") || (command == "PONG")) + { + // :22D PING 20D + if (line.length() < 13) + return; + + // Insert the source SID (and a space) between the command and the first parameter + line.insert(10, line.substr(1, 4)); + } } } } @@ -165,6 +175,37 @@ bool TreeSocket::PreProcessOldProtocolMessage(User*& who, std::string& cmd, std: // :20D FTOPIC #channel 100 Attila :topic text return InsertCurrentChannelTS(params); } + else if ((cmd == "PING") || (cmd == "PONG")) + { + if (params.size() == 1) + { + // If it's a PING with 1 parameter, reply with a PONG now, if it's a PONG with 1 parameter (weird), do nothing + if (cmd[1] == 'I') + this->WriteData(":" + ServerInstance->Config->GetSID() + " PONG " + params[0] + newline); + + // Don't process this message further + return false; + } + + // :20D PING 20D 22D + // :20D PONG 20D 22D + // Drop the first parameter + params.erase(params.begin()); + + // If the target is a server name, translate it to a SID + if (!InspIRCd::IsSID(params[0])) + { + TreeServer* server = Utils->FindServer(params[0]); + if (!server) + { + // We've no idea what this is, log and stop processing + ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Received a " + cmd + " with an unknown target: \"" + params[0] + "\", command dropped"); + return false; + } + + params[0] = server->GetID(); + } + } return true; // Passthru } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index a5785f20c..bd49a3075 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -196,8 +196,7 @@ restart: // ... if we can find a proper route to them if (tsock) { - tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " + - ServerInstance->Config->GetSID() + " " + s->GetID()); + tsock->WriteLine(":" + ServerInstance->Config->GetSID() + " PING " + s->GetID()); s->LastPingMsec = ts; } } diff --git a/src/modules/m_spanningtree/ping.cpp b/src/modules/m_spanningtree/ping.cpp index 951673964..badcc3401 100644 --- a/src/modules/m_spanningtree/ping.cpp +++ b/src/modules/m_spanningtree/ping.cpp @@ -28,28 +28,24 @@ bool TreeSocket::LocalPing(const std::string &prefix, parameterlist ¶ms) { if (params.size() < 1) return true; - if (params.size() == 1) + + const std::string& forwardto = params[0]; + if (forwardto == ServerInstance->Config->GetSID()) { - this->WriteLine(":"+ServerInstance->Config->GetSID()+" PONG "+params[0]); - return true; + // PING for us, reply with a PONG + std::string reply = ":" + forwardto + " PONG " + prefix; + if (params.size() >= 2) + // If there is a second parameter, append it + reply.append(" :").append(params[1]); + + this->WriteLine(reply); } else { - const std::string& forwardto = params[1]; - if (forwardto == ServerInstance->Config->ServerName || forwardto == ServerInstance->Config->GetSID()) - { - // this is a ping for us, send back PONG to the requesting server - params[1] = params[0]; - params[0] = forwardto; - Utils->DoOneToOne(ServerInstance->Config->GetSID(),"PONG",params,params[1]); - } - else - { - // not for us, pass it on :) - Utils->DoOneToOne(prefix,"PING",params,forwardto); - } - return true; + // not for us, pass it on :) + Utils->DoOneToOne(prefix,"PING",params,forwardto); } + return true; } diff --git a/src/modules/m_spanningtree/pong.cpp b/src/modules/m_spanningtree/pong.cpp index 9c3a1b8d7..daf53096d 100644 --- a/src/modules/m_spanningtree/pong.cpp +++ b/src/modules/m_spanningtree/pong.cpp @@ -30,49 +30,23 @@ bool TreeSocket::LocalPong(const std::string &prefix, parameterlist ¶ms) if (params.size() < 1) return true; - if (params.size() == 1) + const std::string& forwardto = params[0]; + if (forwardto == ServerInstance->Config->GetSID()) { + // PONG for us TreeServer* ServerSource = Utils->FindServer(prefix); if (ServerSource) { - ServerSource->SetPingFlag(); long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000); ServerSource->rtt = ts - ServerSource->LastPingMsec; + ServerSource->SetPingFlag(); } } else { - const std::string& forwardto = params[1]; - if (forwardto == ServerInstance->Config->GetSID() || forwardto == ServerInstance->Config->ServerName) - { - /* - * this is a PONG for us - * if the prefix is a user, check theyre local, and if they are, - * dump the PONG reply back to their fd. If its a server, do nowt. - * Services might want to send these s->s, but we dont need to yet. - */ - User* u = ServerInstance->FindNick(prefix); - if (u) - { - u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str()); - } - - TreeServer *ServerSource = Utils->FindServer(params[0]); - - if (ServerSource) - { - long ts = ServerInstance->Time() * 1000 + (ServerInstance->Time_ns() / 1000000); - ServerSource->rtt = ts - ServerSource->LastPingMsec; - ServerSource->SetPingFlag(); - } - } - else - { - // not for us, pass it on :) - Utils->DoOneToOne(prefix,"PONG",params,forwardto); - } + // not for us, pass it on :) + Utils->DoOneToOne(prefix,"PONG",params,forwardto); } - return true; } |