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