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 */
24 class ModuleSpanningTree;
25 class SpanningTreeUtilities;
27 /* This hash_map holds the hash equivalent of the server
28 * tree, used for rapid linear lookups.
30 #if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
31 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
33 #ifdef HASHCOMP_DEPRECATED
34 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
36 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
41 * Initialises server connections
43 class ServerSocketListener : public ListenSocketBase
45 SpanningTreeUtilities *Utils;
48 ServerSocketListener(SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(port, addr)
56 virtual void OnAcceptReady(int nfd);
59 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
61 /** A group of modules that implement BufferedSocketHook
62 * that we can use to hook our server to server connections.
64 typedef std::map<irc::string, Module*> hookmodules;
66 /** Contains helper functions and variables for this module,
67 * and keeps them out of the global namespace
69 class SpanningTreeUtilities : public classbase
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 /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
90 /** Make snomasks +CQ quiet during bursts and splits
94 /** Socket bindings for listening sockets
96 std::vector<ServerSocketListener *> Bindings;
97 /* Number of seconds that a server can go without ping
98 * before opers are warned of high latency.
101 /** This variable represents the root of the server tree
103 TreeServer *TreeRoot;
104 /** Represents the server whose command we are processing
106 FakeUser *ServerUser;
107 /** IPs allowed to link to us
109 std::vector<std::string> ValidIPs;
110 /** Hash of currently connected servers by name
112 server_hash serverlist;
113 /** Hash of currently known server ids
116 /** Hash of servers currently bursting but not initialized as connected
118 std::map<irc::string,TreeSocket*> burstingserverlist;
119 /** List of all outgoing sockets and their timeouts
121 std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
122 /** Holds the data from the <link> tags in the conf
124 std::vector<reference<Link> > LinkBlocks;
125 /** Holds the data from the <autoconnect> tags in the conf
127 std::vector<reference<Autoconnect> > AutoconnectBlocks;
129 /** List of module pointers which can provide I/O abstraction
133 /** List of module names which can provide I/O abstraction
135 std::vector<std::string> hooknames;
137 /** True (default) if we are to use challenge-response HMAC
138 * to authenticate passwords.
140 * NOTE: This defaults to on, but should be turned off if
141 * you are linking to an older version of inspircd.
143 bool ChallengeResponse;
145 /** Ping frequency of server to server links
149 /** Initialise utility class
151 SpanningTreeUtilities(ModuleSpanningTree* Creator);
153 /** Prepare for class destruction
157 /** Destroy class and free listeners etc
159 ~SpanningTreeUtilities();
161 void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
163 /** Send a message from this server to one other local or remote
165 bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string target);
167 /** Send a message from this server to all but one other, local or remote
169 bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string omit);
171 /** Send a message from this server to all but one other, local or remote
173 bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist ¶ms, std::string omit);
175 /** Send a message from this server to all others
177 bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist ¶ms);
179 /** Send a message from this server to all others
181 bool DoOneToMany(const char* prefix, const char* command, parameterlist ¶ms);
183 /** 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)
185 bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist ¶ms);
187 /** Read the spanningtree module's tags from the config file
189 void ReadConfiguration(bool rebind);
191 /** Add a server to the server list for GetListOfServersForChannel
193 void AddThisServer(TreeServer* server, TreeServerList &list);
195 /** Compile a list of servers which contain members of channel c
197 void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
199 /** Find a server by name
201 TreeServer* FindServer(const std::string &ServerName);
203 /** Find server by SID
205 TreeServer* FindServerID(const std::string &id);
207 /** Find a route to a server by name
209 TreeServer* BestRouteTo(const std::string &ServerName);
211 /** Find a server by glob mask
213 TreeServer* FindServerMask(const std::string &ServerName);
215 /** Returns true if this is a server name we recognise
217 bool IsServer(const std::string &ServerName);
219 /** Find a link tag from a server name
221 Link* FindLink(const std::string& name);
223 /** Refresh the IP cache used for allowing inbound connections
225 void RefreshIPCache();