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, const std::string& addr, const std::string& hook)
49 : ListenSocketBase(port, addr), Utils(u), Hook(hook)
55 virtual void OnAcceptReady(int nfd);
58 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
60 /** Contains helper functions and variables for this module,
61 * and keeps them out of the global namespace
63 class SpanningTreeUtilities : public classbase
68 ModuleSpanningTree* Creator;
70 /** Flatten links and /MAP for non-opers
73 /** Hide U-Lined servers in /MAP and /LINKS
76 /** Announce TS changes to channels on merge
78 bool AnnounceTSChange;
80 /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
84 /** Make snomasks +CQ quiet during bursts and splits
88 /** Socket bindings for listening sockets
90 std::vector<ServerSocketListener *> Bindings;
91 /* Number of seconds that a server can go without ping
92 * before opers are warned of high latency.
95 /** This variable represents the root of the server tree
98 /** Represents the server whose command we are processing
100 FakeUser *ServerUser;
101 /** IPs allowed to link to us
103 std::vector<std::string> ValidIPs;
104 /** Hash of currently connected servers by name
106 server_hash serverlist;
107 /** Hash of currently known server ids
110 /** Hash of servers currently bursting but not initialized as connected
112 std::map<irc::string,TreeSocket*> burstingserverlist;
113 /** List of all outgoing sockets and their timeouts
115 std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
116 /** Holds the data from the <link> tags in the conf
118 std::vector<reference<Link> > LinkBlocks;
119 /** Holds the data from the <autoconnect> tags in the conf
121 std::vector<reference<Autoconnect> > AutoconnectBlocks;
123 /** True (default) if we are to use challenge-response HMAC
124 * to authenticate passwords.
126 * NOTE: This defaults to on, but should be turned off if
127 * you are linking to an older version of inspircd.
129 bool ChallengeResponse;
131 /** Ping frequency of server to server links
135 /** Initialise utility class
137 SpanningTreeUtilities(ModuleSpanningTree* Creator);
139 /** Prepare for class destruction
143 /** Destroy class and free listeners etc
145 ~SpanningTreeUtilities();
147 void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
149 /** Send a message from this server to one other local or remote
151 bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string target);
153 /** Send a message from this server to all but one other, local or remote
155 bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist ¶ms, std::string omit);
157 /** Send a message from this server to all but one other, local or remote
159 bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist ¶ms, std::string omit);
161 /** Send a message from this server to all others
163 bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist ¶ms);
165 /** Send a message from this server to all others
167 bool DoOneToMany(const char* prefix, const char* command, parameterlist ¶ms);
169 /** 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)
171 bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist ¶ms);
173 /** Read the spanningtree module's tags from the config file
175 void ReadConfiguration(bool rebind);
177 /** Add a server to the server list for GetListOfServersForChannel
179 void AddThisServer(TreeServer* server, TreeServerList &list);
181 /** Compile a list of servers which contain members of channel c
183 void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
185 /** Find a server by name
187 TreeServer* FindServer(const std::string &ServerName);
189 /** Find server by SID
191 TreeServer* FindServerID(const std::string &id);
193 /** Find a route to a server by name
195 TreeServer* BestRouteTo(const std::string &ServerName);
197 /** Find a server by glob mask
199 TreeServer* FindServerMask(const std::string &ServerName);
201 /** Returns true if this is a server name we recognise
203 bool IsServer(const std::string &ServerName);
205 /** Find a link tag from a server name
207 Link* FindLink(const std::string& name);
209 /** Refresh the IP cache used for allowing inbound connections
211 void RefreshIPCache();