1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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.
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(InspIRCd* Instance, SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(Instance, port, addr)
52 virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip);
55 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
57 /** A group of modules that implement BufferedSocketHook
58 * that we can use to hook our server to server connections.
60 typedef std::map<irc::string, Module*> hookmodules;
62 /** Contains helper functions and variables for this module,
63 * and keeps them out of the global namespace
65 class SpanningTreeUtilities : public classbase
70 InspIRCd* ServerInstance;
74 ModuleSpanningTree* Creator;
76 /** Flatten links and /MAP for non-opers
79 /** Hide U-Lined servers in /MAP and /LINKS
82 /** Announce TS changes to channels on merge
84 bool AnnounceTSChange;
86 /** Make snomasks +CQ quiet during bursts and splits
90 /** Socket bindings for listening sockets
92 std::vector<ServerSocketListener *> Bindings;
93 /* Number of seconds that a server can go without ping
94 * before opers are warned of high latency.
97 /** This variable represents the root of the server tree
100 /** IPs allowed to link to us
102 std::vector<std::string> ValidIPs;
103 /** Hash of currently connected servers by name
105 server_hash serverlist;
106 /** Hash of currently known server ids
109 /** Hash of servers currently bursting but not initialized as connected
111 std::map<irc::string,TreeSocket*> burstingserverlist;
112 /** List of all outgoing sockets and their timeouts
114 std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
115 /** Holds the data from the <link> tags in the conf
117 std::vector<Link> LinkBlocks;
119 /** List of module pointers which can provide I/O abstraction
123 /** List of module names which can provide I/O abstraction
125 std::vector<std::string> hooknames;
127 /** True (default) if we are to use challenge-response HMAC
128 * to authenticate passwords.
130 * NOTE: This defaults to on, but should be turned off if
131 * you are linking to an older version of inspircd.
133 bool ChallengeResponse;
135 /** Ping frequency of server to server links
139 /** Initialise utility class
141 SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
143 /** Destroy class and free listeners etc
145 ~SpanningTreeUtilities();
147 /** Send a message from this server to one other local or remote
149 bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> ¶ms, std::string target);
151 /** Send a message from this server to all but one other, local or remote
153 bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> ¶ms, std::string omit);
155 /** Send a message from this server to all but one other, local or remote
157 bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> ¶ms, std::string omit);
159 /** Send a message from this server to all others
161 bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> ¶ms);
163 /** Send a message from this server to all others
165 bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> ¶ms);
167 /** 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)
169 bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> ¶ms);
171 /** Read the spanningtree module's tags from the config file
173 void ReadConfiguration(bool rebind);
175 /** Add a server to the server list for GetListOfServersForChannel
177 void AddThisServer(TreeServer* server, TreeServerList &list);
179 /** Compile a list of servers which contain members of channel c
181 void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
183 /** Find a server by name
185 TreeServer* FindServer(const std::string &ServerName);
187 /** Find server by SID
189 TreeServer* FindServerID(const std::string &id);
191 /** Find a route to a server by name
193 TreeServer* BestRouteTo(const std::string &ServerName);
195 /** Find a server by glob mask
197 TreeServer* FindServerMask(const std::string &ServerName);
199 /** Returns true if this is a server name we recognise
201 bool IsServer(const std::string &ServerName);
203 /** Attempt to connect to the failover link of link x
205 void DoFailOver(Link* x);
207 /** Find a link tag from a server name
209 Link* FindLink(const std::string& name);
211 /** Refresh the IP cache used for allowing inbound connections
213 void RefreshIPCache();