]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
In the grand tradition of huge fucking commits:
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / utils.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 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<string, less<string> > > server_hash;
30 #else
31 typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<string>, irc::StrHashComp> server_hash;
32 #endif
33
34 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
35
36 /** A group of modules that implement InspSocketHook
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
45 {
46  private:
47         /** Creator server
48          */
49         InspIRCd* ServerInstance;
50  public:
51         /** Creator module
52          */
53         ModuleSpanningTree* Creator;
54         /** Remote servers that are currently bursting
55          */
56         server_hash RemoteServersBursting;
57         /** Flatten links and /MAP for non-opers
58          */
59         bool FlatLinks;
60         /** Hide U-Lined servers in /MAP and /LINKS
61          */
62         bool HideULines;
63         /** Announce TS changes to channels on merge
64          */
65         bool AnnounceTSChange;
66         /** Synchronize timestamps between servers
67          */
68         bool EnableTimeSync;
69         /** Make snomasks +CQ quiet during bursts and splits
70          */
71         bool quiet_bursts;
72         /** Socket bindings for listening sockets
73          */
74         std::vector<TreeSocket*> Bindings;
75         /* Number of seconds that a server can go without ping
76          * before opers are warned of high latency.
77          */
78         int PingWarnTime;
79         /** This variable represents the root of the server tree
80          */
81         TreeServer *TreeRoot;
82         /** IPs allowed to link to us
83          */
84         std::vector<std::string> ValidIPs;
85         /** Hash of currently connected servers by name
86          */
87         server_hash serverlist;
88         /** Hash of currently known server ids
89          */
90         server_hash sidlist;
91         /** Hash of servers currently bursting but not initialized as connected
92          */
93         std::map<irc::string,TreeSocket*> burstingserverlist;
94         /** Holds the data from the <link> tags in the conf
95          */
96         std::vector<Link> LinkBlocks;
97         /** Holds a bitmask of queued xline types waiting to be applied.
98          * Will be a mask containing values APPLY_GLINES, APPLY_KLINES,
99          * APPLY_QLINES and APPLY_ZLINES.
100          */
101         int lines_to_apply;
102
103         /** If this is true, this server is the master sync server for time
104          * synching - e.g. it is the server with its clock correct. It will
105          * send out the correct time at intervals.
106          */
107         bool MasterTime;
108
109         /** List of module pointers which can provide I/O abstraction
110          */
111         hookmodules hooks;
112
113         /** List of module names which can provide I/O abstraction
114          */
115         std::vector<std::string> hooknames;
116
117         /** True (default) if we are to use challenge-response HMAC
118          * to authenticate passwords.
119          *
120          * NOTE: This defaults to on, but should be turned off if
121          * you are linking to an older version of inspircd.
122          */
123         bool ChallengeResponse;
124
125         /** Ping frequency of server to server links
126          */
127         int PingFreq;
128
129         /** Initialise utility class
130          */
131         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
132         /** Destroy class and free listeners etc
133          */
134         ~SpanningTreeUtilities();
135         /** Send a message from this server to one other local or remote
136          */
137         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
138         /** Send a message from this server to all but one other, local or remote
139          */
140         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
141         /** Send a message from this server to all but one other, local or remote
142          */
143         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
144         /** Send a message from this server to all others
145          */
146         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
147         /** Send a message from this server to all others
148          */
149         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
150         /** 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)
151          */
152         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
153         /** Read the spanningtree module's tags from the config file
154          */
155         void ReadConfiguration(bool rebind);
156         /** Add a server to the server list for GetListOfServersForChannel
157          */
158         void AddThisServer(TreeServer* server, TreeServerList &list);
159         /** Compile a list of servers which contain members of channel c
160          */
161         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
162         /** Find a server by name
163          */
164         TreeServer* FindServer(const std::string &ServerName);
165         /** Find server by SID
166          */
167         TreeServer* FindServerID(const std::string &id);
168         /** Find a remote bursting server by name
169          */
170         TreeServer* FindRemoteBurstServer(TreeServer* Server);
171         /** Set a remote server to bursting or not bursting
172          */
173         void SetRemoteBursting(TreeServer* Server, bool bursting);
174         /** Find a route to a server by name
175          */
176         TreeServer* BestRouteTo(const std::string &ServerName);
177         /** Find a server by glob mask
178          */
179         TreeServer* FindServerMask(const std::string &ServerName);
180         /** Returns true if this is a server name we recognise
181          */
182         bool IsServer(const std::string &ServerName);
183         /** Attempt to connect to the failover link of link x
184          */
185         void DoFailOver(Link* x);
186         /** Find a link tag from a server name
187          */
188         Link* FindLink(const std::string& name);
189         /** Refresh the IP cache used for allowing inbound connections
190          */
191         void RefreshIPCache();
192
193         TreeSocket* FindBurstingServer(const std::string &ServerName);
194
195         void AddBurstingServer(const std::string &ServerName, TreeSocket* s);
196
197         void DelBurstingServer(TreeSocket* s);
198
199         /** Return true if str looks like a server ID
200          * @param string to check against
201          */
202         bool IsSID(const std::string &str);
203 };
204
205 #endif