1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 /* Foward declarations */
23 class ModuleSpanningTree;
24 class SpanningTreeUtilities;
26 /* This hash_map holds the hash equivalent of the server
27 * tree, used for rapid linear lookups.
29 #if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
30 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
32 #ifdef HASHCOMP_DEPRECATED
33 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
35 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
40 * Initialises server connections
42 class ServerSocketListener : public ListenSocketBase
44 SpanningTreeUtilities *Utils;
47 ServerSocketListener(SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(port, addr)
55 virtual void OnAcceptReady(int nfd);
58 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
60 /** A group of modules that implement BufferedSocketHook
61 * that we can use to hook our server to server connections.
63 typedef std::map<irc::string, Module*> hookmodules;
65 /** The Autoconnect class might as well be a struct,
66 * but this is C++ and we don't believe in structs (!).
67 * It holds the entire information of one <autoconnect>
68 * tag from the main config file. We maintain a list
69 * of them, and populate the list on rehash/load.
71 class Autoconnect : public classbase
76 time_t NextConnectTime;
80 /** Contains helper functions and variables for this module,
81 * and keeps them out of the global namespace
83 class SpanningTreeUtilities : public classbase
88 ModuleSpanningTree* Creator;
90 /** Flatten links and /MAP for non-opers
93 /** Hide U-Lined servers in /MAP and /LINKS
96 /** Announce TS changes to channels on merge
98 bool AnnounceTSChange;
100 /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
104 /** Make snomasks +CQ quiet during bursts and splits
108 /** Socket bindings for listening sockets
110 std::vector<ServerSocketListener *> Bindings;
111 /* Number of seconds that a server can go without ping
112 * before opers are warned of high latency.
115 /** This variable represents the root of the server tree
117 TreeServer *TreeRoot;
118 /** Represents the server whose command we are processing
120 FakeUser *ServerUser;
121 /** IPs allowed to link to us
123 std::vector<std::string> ValidIPs;
124 /** Hash of currently connected servers by name
126 server_hash serverlist;
127 /** Hash of currently known server ids
130 /** Hash of servers currently bursting but not initialized as connected
132 std::map<irc::string,TreeSocket*> burstingserverlist;
133 /** List of all outgoing sockets and their timeouts
135 std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
136 /** Holds the data from the <link> tags in the conf
138 std::vector<Link> LinkBlocks;
139 /** Holds the data from the <autoconnect> tags in the conf
141 std::vector<Autoconnect> AutoconnectBlocks;
143 /** List of module pointers which can provide I/O abstraction
147 /** List of module names which can provide I/O abstraction
149 std::vector<std::string> hooknames;
151 /** True (default) if we are to use challenge-response HMAC
152 * to authenticate passwords.
154 * NOTE: This defaults to on, but should be turned off if
155 * you are linking to an older version of inspircd.
157 bool ChallengeResponse;
159 /** Ping frequency of server to server links
163 /** Initialise utility class
165 SpanningTreeUtilities(ModuleSpanningTree* Creator);
167 /** Destroy class and free listeners etc
169 ~SpanningTreeUtilities();
171 /** Send a message from this server to one other local or remote
173 bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string target);
175 /** Send a message from this server to all but one other, local or remote
177 bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string omit);
179 /** Send a message from this server to all but one other, local or remote
181 bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist ¶ms, std::string omit);
183 /** Send a message from this server to all others
185 bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist ¶ms);
187 /** Send a message from this server to all others
189 bool DoOneToMany(const char* prefix, const char* command, parameterlist ¶ms);
191 /** 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)
193 bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist ¶ms);
195 /** Read the spanningtree module's tags from the config file
197 void ReadConfiguration(bool rebind);
199 /** Add a server to the server list for GetListOfServersForChannel
201 void AddThisServer(TreeServer* server, TreeServerList &list);
203 /** Compile a list of servers which contain members of channel c
205 void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
207 /** Find a server by name
209 TreeServer* FindServer(const std::string &ServerName);
211 /** Find server by SID
213 TreeServer* FindServerID(const std::string &id);
215 /** Find a route to a server by name
217 TreeServer* BestRouteTo(const std::string &ServerName);
219 /** Find a server by glob mask
221 TreeServer* FindServerMask(const std::string &ServerName);
223 /** Returns true if this is a server name we recognise
225 bool IsServer(const std::string &ServerName);
227 /** Attempt to connect to the failover link of link x
229 void DoFailOver(Autoconnect* x);
231 /** Find a link tag from a server name
233 Link* FindLink(const std::string& name);
235 /** Refresh the IP cache used for allowing inbound connections
237 void RefreshIPCache();