]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
1bdf127d840d73a42f7ebfb177fc0ca3cc7b05a0
[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                 Hook = NULL;
51         }
52
53         Module* Hook;
54
55         virtual void OnAcceptReady(int nfd);
56 };
57
58 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
59
60 /** A group of modules that implement BufferedSocketHook
61  * that we can use to hook our server to server connections.
62  */
63 typedef std::map<irc::string, Module*> hookmodules;
64
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.
70  */
71 class Autoconnect : public classbase
72 {
73  public:
74         unsigned long Period;
75         std::string Server;
76         time_t NextConnectTime;
77         std::string FailOver;
78 };
79
80 /** Contains helper functions and variables for this module,
81  * and keeps them out of the global namespace
82  */
83 class SpanningTreeUtilities : public classbase
84 {
85  private:
86         /** Creator server
87          */
88         InspIRCd* ServerInstance;
89  public:
90         /** Creator module
91          */
92         ModuleSpanningTree* Creator;
93
94         /** Flatten links and /MAP for non-opers
95          */
96         bool FlatLinks;
97         /** Hide U-Lined servers in /MAP and /LINKS
98          */
99         bool HideULines;
100         /** Announce TS changes to channels on merge
101          */
102         bool AnnounceTSChange;
103
104         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
105          */
106         bool AllowOptCommon;
107
108         /** Make snomasks +CQ quiet during bursts and splits
109          */
110         bool quiet_bursts;
111
112         /** Socket bindings for listening sockets
113          */
114         std::vector<ServerSocketListener *> Bindings;
115         /* Number of seconds that a server can go without ping
116          * before opers are warned of high latency.
117          */
118         int PingWarnTime;
119         /** This variable represents the root of the server tree
120          */
121         TreeServer *TreeRoot;
122         /** Represents the server whose command we are processing
123          */
124         FakeUser *ServerUser;
125         /** IPs allowed to link to us
126          */
127         std::vector<std::string> ValidIPs;
128         /** Hash of currently connected servers by name
129          */
130         server_hash serverlist;
131         /** Hash of currently known server ids
132          */
133         server_hash sidlist;
134         /** Hash of servers currently bursting but not initialized as connected
135          */
136         std::map<irc::string,TreeSocket*> burstingserverlist;
137         /** List of all outgoing sockets and their timeouts
138          */
139         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
140         /** Holds the data from the <link> tags in the conf
141          */
142         std::vector<Link> LinkBlocks;
143         /** Holds the data from the <autoconnect> tags in the conf
144          */
145         std::vector<Autoconnect> AutoconnectBlocks;
146
147         /** List of module pointers which can provide I/O abstraction
148          */
149         hookmodules hooks;
150
151         /** List of module names which can provide I/O abstraction
152          */
153         std::vector<std::string> hooknames;
154
155         /** True (default) if we are to use challenge-response HMAC
156          * to authenticate passwords.
157          *
158          * NOTE: This defaults to on, but should be turned off if
159          * you are linking to an older version of inspircd.
160          */
161         bool ChallengeResponse;
162
163         /** Ping frequency of server to server links
164          */
165         int PingFreq;
166
167         /** Initialise utility class
168          */
169         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
170
171         /** Destroy class and free listeners etc
172          */
173         ~SpanningTreeUtilities();
174
175         /** Send a message from this server to one other local or remote
176          */
177         bool DoOneToOne(const std::string &prefix, const std::string &command, parameterlist &params, std::string target);
178
179         /** Send a message from this server to all but one other, local or remote
180          */
181         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, parameterlist &params, std::string omit);
182
183         /** Send a message from this server to all but one other, local or remote
184          */
185         bool DoOneToAllButSender(const char* prefix, const char* command, parameterlist &params, std::string omit);
186
187         /** Send a message from this server to all others
188          */
189         bool DoOneToMany(const std::string &prefix, const std::string &command, parameterlist &params);
190
191         /** Send a message from this server to all others
192          */
193         bool DoOneToMany(const char* prefix, const char* command, parameterlist &params);
194
195         /** 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)
196          */
197         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, parameterlist &params);
198
199         /** Read the spanningtree module's tags from the config file
200          */
201         void ReadConfiguration(bool rebind);
202
203         /** Add a server to the server list for GetListOfServersForChannel
204          */
205         void AddThisServer(TreeServer* server, TreeServerList &list);
206
207         /** Compile a list of servers which contain members of channel c
208          */
209         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
210
211         /** Find a server by name
212          */
213         TreeServer* FindServer(const std::string &ServerName);
214
215         /** Find server by SID
216          */
217         TreeServer* FindServerID(const std::string &id);
218
219         /** Find a route to a server by name
220          */
221         TreeServer* BestRouteTo(const std::string &ServerName);
222
223         /** Find a server by glob mask
224          */
225         TreeServer* FindServerMask(const std::string &ServerName);
226
227         /** Returns true if this is a server name we recognise
228          */
229         bool IsServer(const std::string &ServerName);
230
231         /** Attempt to connect to the failover link of link x
232          */
233         void DoFailOver(Autoconnect* x);
234
235         /** Find a link tag from a server name
236          */
237         Link* FindLink(const std::string& name);
238
239         /** Refresh the IP cache used for allowing inbound connections
240          */
241         void RefreshIPCache();
242 };
243
244 #endif