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