]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
1022c179663924117991ccd53c7e8cfe90e9e49f
[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 class SpanningTreeUtilities;
25
26 /* This hash_map holds the hash equivalent of the server
27  * tree, used for rapid linear lookups.
28  */
29 #ifdef WINDOWS
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         }
51
52         virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip);
53 };
54
55 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
56
57 /** A group of modules that implement BufferedSocketHook
58  * that we can use to hook our server to server connections.
59  */
60 typedef std::map<irc::string, Module*> hookmodules;
61
62 /** Contains helper functions and variables for this module,
63  * and keeps them out of the global namespace
64  */
65 class SpanningTreeUtilities : public classbase
66 {
67  private:
68         /** Creator server
69          */
70         InspIRCd* ServerInstance;
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         /** Make snomasks +CQ quiet during bursts and splits
87          */
88         bool quiet_bursts;
89
90         /** Socket bindings for listening sockets
91          */
92         std::vector<ServerSocketListener *> Bindings;
93         /* Number of seconds that a server can go without ping
94          * before opers are warned of high latency.
95          */
96         int PingWarnTime;
97         /** This variable represents the root of the server tree
98          */
99         TreeServer *TreeRoot;
100         /** IPs allowed to link to us
101          */
102         std::vector<std::string> ValidIPs;
103         /** Hash of currently connected servers by name
104          */
105         server_hash serverlist;
106         /** Hash of currently known server ids
107          */
108         server_hash sidlist;
109         /** Hash of servers currently bursting but not initialized as connected
110          */
111         std::map<irc::string,TreeSocket*> burstingserverlist;
112         /** Holds the data from the <link> tags in the conf
113          */
114         std::vector<Link> LinkBlocks;
115
116         /** List of module pointers which can provide I/O abstraction
117          */
118         hookmodules hooks;
119
120         /** List of module names which can provide I/O abstraction
121          */
122         std::vector<std::string> hooknames;
123
124         /** True (default) if we are to use challenge-response HMAC
125          * to authenticate passwords.
126          *
127          * NOTE: This defaults to on, but should be turned off if
128          * you are linking to an older version of inspircd.
129          */
130         bool ChallengeResponse;
131
132         /** Ping frequency of server to server links
133          */
134         int PingFreq;
135
136         /** Initialise utility class
137          */
138         SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
139
140         /** Destroy class and free listeners etc
141          */
142         ~SpanningTreeUtilities();
143
144         /** Send a message from this server to one other local or remote
145          */
146         bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
147
148         /** Send a message from this server to all but one other, local or remote
149          */
150         bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
151
152         /** Send a message from this server to all but one other, local or remote
153          */
154         bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
155
156         /** Send a message from this server to all others
157          */
158         bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
159
160         /** Send a message from this server to all others
161          */
162         bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
163
164         /** 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)
165          */
166         bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
167
168         /** Read the spanningtree module's tags from the config file
169          */
170         void ReadConfiguration(bool rebind);
171
172         /** Add a server to the server list for GetListOfServersForChannel
173          */
174         void AddThisServer(TreeServer* server, TreeServerList &list);
175
176         /** Compile a list of servers which contain members of channel c
177          */
178         void GetListOfServersForChannel(Channel* c, TreeServerList &list, char status, const CUList &exempt_list);
179
180         /** Find a server by name
181          */
182         TreeServer* FindServer(const std::string &ServerName);
183
184         /** Find server by SID
185          */
186         TreeServer* FindServerID(const std::string &id);
187
188         /** Find a route to a server by name
189          */
190         TreeServer* BestRouteTo(const std::string &ServerName);
191
192         /** Find a server by glob mask
193          */
194         TreeServer* FindServerMask(const std::string &ServerName);
195
196         /** Returns true if this is a server name we recognise
197          */
198         bool IsServer(const std::string &ServerName);
199
200         /** Attempt to connect to the failover link of link x
201          */
202         void DoFailOver(Link* x);
203
204         /** Find a link tag from a server name
205          */
206         Link* FindLink(const std::string& name);
207
208         /** Refresh the IP cache used for allowing inbound connections
209          */
210         void RefreshIPCache();
211 };
212
213 #endif