From 1626437cbf963b16ce44ef6cc829957fd3a7e2ff Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Fri, 12 Apr 2013 16:40:16 +0200 Subject: m_spanningtree Introduce IJOIN and RESYNC When a local user joins an existing channel, instead of an FJOIN, send an IJOIN with the channel name being the first parameter. If the joining user received prefix modes, append the channel TS and the prefix mode letters as the second and third parameters. When receiving an IJOIN, first check if the target channel exists. If it does not exist, ignore the join (that is, do not create the channel) and send a RESYNC back to the source. If the channel does exist then join the user, and in case any prefix modes were sent (found in the 3rd parameter), compare the TS of the channel to the TS in the IJOIN (2nd parameter). If the timestamps match, set the modes on the user, otherwise ignore the modes. Outgoing IJOINs to 1202 protocol servers are converted to FJOINs, but the channel mode parameter is left empty ("+"). --- src/modules/m_spanningtree/ijoin.cpp | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/modules/m_spanningtree/ijoin.cpp (limited to 'src/modules/m_spanningtree/ijoin.cpp') diff --git a/src/modules/m_spanningtree/ijoin.cpp b/src/modules/m_spanningtree/ijoin.cpp new file mode 100644 index 000000000..2f71ffe27 --- /dev/null +++ b/src/modules/m_spanningtree/ijoin.cpp @@ -0,0 +1,93 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2012-2013 Attila Molnar + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "inspircd.h" +#include "commands.h" +#include "utils.h" +#include "treeserver.h" +#include "treesocket.h" + +CmdResult CommandIJoin::HandleRemote(const std::vector& params, RemoteUser* user) +{ + Channel* chan = ServerInstance->FindChan(params[0]); + if (!chan) + { + // Desync detected, recover + // Ignore the join and send RESYNC, this will result in the remote server sending all channel data to us + ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Received IJOIN for non-existant channel: " + params[0]); + + parameterlist p; + p.push_back(params[0]); + SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils; + Utils->DoOneToOne(ServerInstance->Config->GetSID(), "RESYNC", p, user->server); + + return CMD_FAILURE; + } + + bool apply_modes; + if (params.size() > 1) + { + time_t RemoteTS = ConvToInt(params[1]); + if (!RemoteTS) + { + ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Invalid TS in IJOIN: " + params[1]); + return CMD_INVALID; + } + + if (RemoteTS < chan->age) + { + ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Attempted to lower TS via IJOIN. Channel=" + params[0] + " RemoteTS=" + params[1] + " LocalTS=" + ConvToStr(chan->age)); + return CMD_INVALID; + } + apply_modes = ((params.size() > 2) && (RemoteTS == chan->age)); + } + else + apply_modes = false; + + chan->ForceJoin(user, apply_modes ? ¶ms[2] : NULL); + return CMD_SUCCESS; +} + +CmdResult CommandResync::HandleServer(const std::vector& params, FakeUser* user) +{ + ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Resyncing " + params[0]); + Channel* chan = ServerInstance->FindChan(params[0]); + if (!chan) + { + // This can happen for a number of reasons, safe to ignore + ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Channel does not exist"); + return CMD_FAILURE; + } + + SpanningTreeUtilities* Utils = ((ModuleSpanningTree*)(Module*)creator)->Utils; + TreeServer* server = Utils->FindServer(user->server); + if (!server) + return CMD_FAILURE; + + TreeSocket* socket = server->GetSocket(); + if (!socket) + { + ServerInstance->Logs->Log("m_spanningtree", LOG_DEFAULT, "Received RESYNC with a source that is not directly connected: " + user->uuid); + return CMD_INVALID; + } + + // Send all known information about the channel + socket->SyncChannel(chan); + return CMD_SUCCESS; +} -- cgit v1.3.1-10-gc9f91