]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
First phase of conversion to dynamic limits on all the lengths, configured via the...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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
25 /* This hash_map holds the hash equivalent of the server
26  * tree, used for rapid linear lookups.
27  */
28 #ifdef WINDOWS
29 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash_compare<std::string, std::less<std::string> > > server_hash;
30 #else
31 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<std::string>, irc::StrHashComp> server_hash;
32 #endif
33
34 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
35
36 /** A group of modules that implement BufferedSocketHook
37  * that we can use to hook our server to server connections.
38  */
39 typedef std::map<irc::string, Module*> hookmodules;
40
41 /** Contains helper functions and variables for this module,
42  * and keeps them out of the global namespace
43  */
44 class SpanningTreeUtilities : public classbase
45 {
46  private:
47         /** Creator server
48          */
49         InspIRCd* ServerInstance;
50  public:
51         /** Creator module
52          */
53         ModuleSpanningTree* Creator;
54
55         /** Flatten links and /MAP for non-opers
56          */
57         bool FlatLinks;
58         /** Hide U-Lined servers in /MAP and /LINKS
59          */
60         bool HideULines;
61         /** Announce TS changes to channels on merge
62          */
63         bool AnnounceTSChange;
64
65         /** Make snomasks +CQ quiet during bursts and splits
66          */
67         bool quiet_bursts;
68         /** Socket bindings for listening sockets
69          */
70         std::vector<TreeSocket*> Bindings;
71         /* Number of seconds that a server can go without ping
72          * before opers are warned of high latency.
73          */
74         int PingWarnTime;
75         /** This variable represents the root of the server tree
76          */
77         TreeServer *TreeRoot;
78         /** IPs allowed to link to us
79          */
80         std::vector<std::string> ValidIPs;
81         /** Hash of currently connected servers by name
82          */
83         server_hash serverlist;
84         /** Hash of currently known server ids
85          */
86         server_hash sidlist;
87         /** Hash of servers currently bursting but not initialized as connected
88          */
89         std::map<irc::string,TreeSocket*> burstingserverlist;
90         /** Holds the data from the <link> tags in the conf
91          */
92         std::vector<Link> LinkBlocks;
93
94         /** List of module pointers which can provide I/O abstraction
95          */
96         hookmodules hooks;
97
98         /** List of module names which can provide I/O abstraction
99          */
100         std::vector<std::string> hooknames;
101
102         /** True (default) if we are to use challenge-response HMAC
103          * to authenticate passwords.
104          *
105          * NOTE: This defaults to on, but should be turned off if
106          * you are linking to an older version of inspircd.
107          */
108         bool ChallengeResponse;
109
110         /** Ping frequency of server to server links
111          */
112         int PingFreq;
113
114         /** Initialise utility class
115          */
116         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
117
118         /** Destroy class and free listeners etc
119          */
120         ~SpanningTreeUtilities();
121
122         /** Send a message from this server to one other local or remote
123          */
124         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
125
126         /** Send a message from this server to all but one other, local or remote
127          */
128         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
129
130         /** Send a message from this server to all but one other, local or remote
131          */
132         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
133
134         /** Send a message from this server to all others
135          */
136         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
137
138         /** Send a message from this server to all others
139          */
140         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
141
142         /** 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)
143          */
144         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
145
146         /** Read the spanningtree module's tags from the config file
147          */
148         void ReadConfiguration(bool rebind);
149
150         /** Add a server to the server list for GetListOfServersForChannel
151          */
152         void AddThisServer(TreeServer* server, TreeServerList &list);
153
154         /** Compile a list of servers which contain members of channel c
155          */
156         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
157
158         /** Find a server by name
159          */
160         TreeServer* FindServer(const std::string &ServerName);
161
162         /** Find server by SID
163          */
164         TreeServer* FindServerID(const std::string &id);
165
166         /** Find a route to a server by name
167          */
168         TreeServer* BestRouteTo(const std::string &ServerName);
169
170         /** Find a server by glob mask
171          */
172         TreeServer* FindServerMask(const std::string &ServerName);
173
174         /** Returns true if this is a server name we recognise
175          */
176         bool IsServer(const std::string &ServerName);
177
178         /** Attempt to connect to the failover link of link x
179          */
180         void DoFailOver(Link* x);
181
182         /** Find a link tag from a server name
183          */
184         Link* FindLink(const std::string& name);
185
186         /** Refresh the IP cache used for allowing inbound connections
187          */
188         void RefreshIPCache();
189 };
190
191 #endif