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/>.
23 #ifndef M_SPANNINGTREE_UTILS_H
24 #define M_SPANNINGTREE_UTILS_H
28 /* Foward declarations */
33 class ModuleSpanningTree;
34 class SpanningTreeUtilities;
36 /* This hash_map holds the hash equivalent of the server
37 * tree, used for rapid linear lookups.
39 #if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
40 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
42 #ifdef HASHCOMP_DEPRECATED
43 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
45 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
49 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
51 /** Contains helper functions and variables for this module,
52 * and keeps them out of the global namespace
54 class SpanningTreeUtilities : public classbase
59 ModuleSpanningTree* Creator;
61 /** Flatten links and /MAP for non-opers
64 /** Hide U-Lined servers in /MAP and /LINKS
67 /** Announce TS changes to channels on merge
69 bool AnnounceTSChange;
71 /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
75 /** Make snomasks +CQ quiet during bursts and splits
79 /* Number of seconds that a server can go without ping
80 * before opers are warned of high latency.
83 /** This variable represents the root of the server tree
86 /** IPs allowed to link to us
88 std::vector<std::string> ValidIPs;
89 /** Hash of currently connected servers by name
91 server_hash serverlist;
92 /** Hash of currently known server ids
95 /** Hash of servers currently bursting but not initialized as connected
97 std::map<irc::string,TreeSocket*> burstingserverlist;
98 /** List of all outgoing sockets and their timeouts
100 std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
101 /** Holds the data from the <link> tags in the conf
103 std::vector<reference<Link> > LinkBlocks;
104 /** Holds the data from the <autoconnect> tags in the conf
106 std::vector<reference<Autoconnect> > AutoconnectBlocks;
108 /** True (default) if we are to use challenge-response HMAC
109 * to authenticate passwords.
111 * NOTE: This defaults to on, but should be turned off if
112 * you are linking to an older version of inspircd.
114 bool ChallengeResponse;
116 /** Ping frequency of server to server links
120 /** Initialise utility class
122 SpanningTreeUtilities(ModuleSpanningTree* Creator);
124 /** Prepare for class destruction
128 /** Destroy class and free listeners etc
130 ~SpanningTreeUtilities();
132 void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
134 /** Send a message from this server to one other local or remote
136 bool DoOneToOne(const std::string &prefix, const std::string &command, const parameterlist ¶ms, std::string target);
138 /** Send a message from this server to all but one other, local or remote
140 bool DoOneToAllButSender(const std::string &prefix, const std::string &command, const parameterlist ¶ms, std::string omit);
142 /** Send a message from this server to all but one other, local or remote
144 bool DoOneToAllButSender(const char* prefix, const char* command, const parameterlist ¶ms, std::string omit);
146 /** Send a message from this server to all others
148 bool DoOneToMany(const std::string &prefix, const std::string &command, const parameterlist ¶ms);
150 /** Send a message from this server to all others
152 bool DoOneToMany(const char* prefix, const char* command, const parameterlist ¶ms);
154 /** Send a message from this server to all others, without doing any processing on the command (e.g. send it as-is with colons and all)
156 bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, const parameterlist ¶ms);
158 /** Read the spanningtree module's tags from the config file
160 void ReadConfiguration();
162 /** Add a server to the server list for GetListOfServersForChannel
164 void AddThisServer(TreeServer* server, TreeServerList &list);
166 /** Compile a list of servers which contain members of channel c
168 void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
170 /** Find a server by name
172 TreeServer* FindServer(const std::string &ServerName);
174 /** Find server by SID
176 TreeServer* FindServerID(const std::string &id);
178 /** Find a route to a server by name
180 TreeServer* BestRouteTo(const std::string &ServerName);
182 /** Find a server by glob mask
184 TreeServer* FindServerMask(const std::string &ServerName);
186 /** Returns true if this is a server name we recognise
188 bool IsServer(const std::string &ServerName);
190 /** Find a link tag from a server name
192 Link* FindLink(const std::string& name);
194 /** Refresh the IP cache used for allowing inbound connections
196 void RefreshIPCache();