]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Add <autoconnect> blocks [jackmcbarn]
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __ST__UTIL__
15 #define __ST__UTIL__
16
17 #include "inspircd.h"
18
19 /* Foward declarations */
20 class TreeServer;
21 class TreeSocket;
22 class Link;
23 class ModuleSpanningTree;
24 class SpanningTreeUtilities;
25
26 /* This hash_map holds the hash equivalent of the server
27  * tree, used for rapid linear lookups.
28  */
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;
31 #else
32         #ifdef HASHCOMP_DEPRECATED
33                 typedef nspace::hash_map<std::string, TreeServer*, nspace::insensitive, irc::StrHashComp> server_hash;
34         #else
35                 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
36         #endif
37 #endif
38
39 /*
40  * Initialises server connections
41  */
42 class ServerSocketListener : public ListenSocketBase
43 {
44         SpanningTreeUtilities *Utils;
45
46  public:
47         ServerSocketListener(InspIRCd* Instance, SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(Instance, port, addr)
48         {
49                 this->Utils = u;
50         }
51
52         virtual void OnAcceptReady(int nfd);
53 };
54
55 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
56
57 /** A group of modules that implement BufferedSocketHook
58  * that we can use to hook our server to server connections.
59  */
60 typedef std::map<irc::string, Module*> hookmodules;
61
62 /** The Autoconnect class might as well be a struct,
63  * but this is C++ and we don't believe in structs (!).
64  * It holds the entire information of one <autoconnect>
65  * tag from the main config file. We maintain a list
66  * of them, and populate the list on rehash/load.
67  */
68 class Autoconnect : public classbase
69 {
70  public:
71         unsigned long Period;
72         std::string Server;
73         time_t NextConnectTime;
74         std::string FailOver;
75 };
76
77 /** Contains helper functions and variables for this module,
78  * and keeps them out of the global namespace
79  */
80 class SpanningTreeUtilities : public classbase
81 {
82  private:
83         /** Creator server
84          */
85         InspIRCd* ServerInstance;
86  public:
87         /** Creator module
88          */
89         ModuleSpanningTree* Creator;
90
91         /** Flatten links and /MAP for non-opers
92          */
93         bool FlatLinks;
94         /** Hide U-Lined servers in /MAP and /LINKS
95          */
96         bool HideULines;
97         /** Announce TS changes to channels on merge
98          */
99         bool AnnounceTSChange;
100
101         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
102          */
103         bool AllowOptCommon;
104
105         /** Make snomasks +CQ quiet during bursts and splits
106          */
107         bool quiet_bursts;
108
109         /** Socket bindings for listening sockets
110          */
111         std::vector<ServerSocketListener *> Bindings;
112         /* Number of seconds that a server can go without ping
113          * before opers are warned of high latency.
114          */
115         int PingWarnTime;
116         /** This variable represents the root of the server tree
117          */
118         TreeServer *TreeRoot;
119         /** Represents the server whose command we are processing
120          */
121         FakeUser *ServerUser;
122         /** IPs allowed to link to us
123          */
124         std::vector<std::string> ValidIPs;
125         /** Hash of currently connected servers by name
126          */
127         server_hash serverlist;
128         /** Hash of currently known server ids
129          */
130         server_hash sidlist;
131         /** Hash of servers currently bursting but not initialized as connected
132          */
133         std::map<irc::string,TreeSocket*> burstingserverlist;
134         /** List of all outgoing sockets and their timeouts
135          */
136         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
137         /** Holds the data from the <link> tags in the conf
138          */
139         std::vector<Link> LinkBlocks;
140         /** Holds the data from the <autoconnect> tags in the conf
141          */
142         std::vector<Autoconnect> AutoconnectBlocks;
143
144         /** List of module pointers which can provide I/O abstraction
145          */
146         hookmodules hooks;
147
148         /** List of module names which can provide I/O abstraction
149          */
150         std::vector<std::string> hooknames;
151
152         /** True (default) if we are to use challenge-response HMAC
153          * to authenticate passwords.
154          *
155          * NOTE: This defaults to on, but should be turned off if
156          * you are linking to an older version of inspircd.
157          */
158         bool ChallengeResponse;
159
160         /** Ping frequency of server to server links
161          */
162         int PingFreq;
163
164         /** Initialise utility class
165          */
166         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
167
168         /** Destroy class and free listeners etc
169          */
170         ~SpanningTreeUtilities();
171
172         /** Send a message from this server to one other local or remote
173          */
174         bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target);
175
176         /** Send a message from this server to all but one other, local or remote
177          */
178         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit);
179
180         /** Send a message from this server to all but one other, local or remote
181          */
182         bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit);
183
184         /** Send a message from this server to all others
185          */
186         bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params);
187
188         /** Send a message from this server to all others
189          */
190         bool DoOneToMany(const char* prefix, const char* command, parameterlist &params);
191
192         /** 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          */
194         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params);
195
196         /** Read the spanningtree module's tags from the config file
197          */
198         void ReadConfiguration(bool rebind);
199
200         /** Add a server to the server list for GetListOfServersForChannel
201          */
202         void AddThisServer(TreeServer* server, TreeServerList &list);
203
204         /** Compile a list of servers which contain members of channel c
205          */
206         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
207
208         /** Find a server by name
209          */
210         TreeServer* FindServer(const std::string &ServerName);
211
212         /** Find server by SID
213          */
214         TreeServer* FindServerID(const std::string &id);
215
216         /** Find a route to a server by name
217          */
218         TreeServer* BestRouteTo(const std::string &ServerName);
219
220         /** Find a server by glob mask
221          */
222         TreeServer* FindServerMask(const std::string &ServerName);
223
224         /** Returns true if this is a server name we recognise
225          */
226         bool IsServer(const std::string &ServerName);
227
228         /** Attempt to connect to the failover link of link x
229          */
230         void DoFailOver(Autoconnect* x);
231
232         /** Find a link tag from a server name
233          */
234         Link* FindLink(const std::string& name);
235
236         /** Refresh the IP cache used for allowing inbound connections
237          */
238         void RefreshIPCache();
239 };
240
241 #endif