2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7 * Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "cachetimer.h"
28 /* Foward declarations */
33 class ModuleSpanningTree;
34 class SpanningTreeUtilities;
37 extern SpanningTreeUtilities* Utils;
39 /* This hash_map holds the hash equivalent of the server
40 * tree, used for rapid linear lookups.
42 typedef TR1NS::unordered_map<std::string, TreeServer*, irc::insensitive, irc::StrHashComp> server_hash;
44 /** Contains helper functions and variables for this module,
45 * and keeps them out of the global namespace
47 class SpanningTreeUtilities : public classbase
49 CacheRefreshTimer RefreshTimer;
52 typedef std::set<TreeSocket*> TreeSocketSet;
53 typedef std::map<TreeSocket*, std::pair<std::string, int> > TimeoutList;
57 ModuleSpanningTree* Creator;
59 /** Flatten links and /MAP for non-opers
62 /** Hide U-Lined servers in /MAP and /LINKS
65 /** Announce TS changes to channels on merge
67 bool AnnounceTSChange;
69 /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
73 /** Make snomasks +CQ quiet during bursts and splits
77 /* Number of seconds that a server can go without ping
78 * before opers are warned of high latency.
81 /** This variable represents the root of the server tree
84 /** IPs allowed to link to us
86 std::vector<std::string> ValidIPs;
87 /** Hash of currently connected servers by name
89 server_hash serverlist;
90 /** Hash of currently known server ids
93 /** List of all outgoing sockets and their timeouts
95 TimeoutList timeoutlist;
96 /** Holds the data from the <link> tags in the conf
98 std::vector<reference<Link> > LinkBlocks;
99 /** Holds the data from the <autoconnect> tags in the conf
101 std::vector<reference<Autoconnect> > AutoconnectBlocks;
103 /** True (default) if we are to use challenge-response HMAC
104 * to authenticate passwords.
106 * NOTE: This defaults to on, but should be turned off if
107 * you are linking to an older version of inspircd.
109 bool ChallengeResponse;
111 /** Ping frequency of server to server links
115 /** Initialise utility class
117 SpanningTreeUtilities(ModuleSpanningTree* Creator);
119 /** Prepare for class destruction
123 /** Destroy class and free listeners etc
125 ~SpanningTreeUtilities();
127 void RouteCommand(TreeServer* origin, CommandBase* cmd, const parameterlist& parameters, User* user);
129 /** Send a message from this server to one other local or remote
131 bool DoOneToOne(const CmdBuilder& params, const std::string& target);
132 void DoOneToOne(const CmdBuilder& params, Server* target);
134 /** Send a message from this server to all but one other, local or remote
136 void DoOneToAllButSender(const CmdBuilder& params, TreeServer* omit);
138 /** Send a message from this server to all others
140 void DoOneToMany(const CmdBuilder& params);
142 /** Read the spanningtree module's tags from the config file
144 void ReadConfiguration();
146 /** Handle nick collision
148 int DoCollision(User* u, TreeServer* server, time_t remotets, const std::string& remoteident, const std::string& remoteip, const std::string& remoteuid);
150 /** Compile a list of servers which contain members of channel c
152 void GetListOfServersForChannel(Channel* c, TreeSocketSet& list, char status, const CUList& exempt_list);
154 /** Find a server by name
156 TreeServer* FindServer(const std::string &ServerName);
158 /** Find server by SID
160 TreeServer* FindServerID(const std::string &id);
162 /** Find a route to a server by name
164 TreeServer* BestRouteTo(const std::string &ServerName);
166 /** Find a server by glob mask
168 TreeServer* FindServerMask(const std::string &ServerName);
170 /** Find a link tag from a server name
172 Link* FindLink(const std::string& name);
174 /** Refresh the IP cache used for allowing inbound connections
176 void RefreshIPCache();
178 /** Sends a PRIVMSG or a NOTICE to a channel obeying an exempt list and an optional prefix
180 void SendChannelMessage(const std::string& prefix, Channel* target, const std::string& text, char status, const CUList& exempt_list, const char* message_type, TreeSocket* omit = NULL);
183 inline void SpanningTreeUtilities::DoOneToMany(const CmdBuilder& params)
185 DoOneToAllButSender(params, NULL);