]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/utils.h
Make classbase and refcountbase uncopyable; expand comments on their indended uses
[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, const std::string& addr, const std::string& Hook)
49                 : ListenSocketBase(port, addr, "servers", Hook), Utils(u)
50         {
51         }
52
53         virtual void OnAcceptReady(int nfd);
54 };
55
56 typedef std::map<TreeServer*,TreeServer*> TreeServerList;
57
58 /** Contains helper functions and variables for this module,
59  * and keeps them out of the global namespace
60  */
61 class SpanningTreeUtilities : public classbase
62 {
63  public:
64         /** Creator module
65          */
66         ModuleSpanningTree* Creator;
67
68         /** Flatten links and /MAP for non-opers
69          */
70         bool FlatLinks;
71         /** Hide U-Lined servers in /MAP and /LINKS
72          */
73         bool HideULines;
74         /** Announce TS changes to channels on merge
75          */
76         bool AnnounceTSChange;
77
78         /** Allow modules marked as VF_OPTCOMMON to be mismatched when linking
79          */
80         bool AllowOptCommon;
81
82         /** Make snomasks +CQ quiet during bursts and splits
83          */
84         bool quiet_bursts;
85
86         /* Number of seconds that a server can go without ping
87          * before opers are warned of high latency.
88          */
89         int PingWarnTime;
90         /** This variable represents the root of the server tree
91          */
92         TreeServer *TreeRoot;
93         /** Represents the server whose command we are processing
94          */
95         FakeUser *ServerUser;
96         /** IPs allowed to link to us
97          */
98         std::vector<std::string> ValidIPs;
99         /** Hash of currently connected servers by name
100          */
101         server_hash serverlist;
102         /** Hash of currently known server ids
103          */
104         server_hash sidlist;
105         /** Hash of servers currently bursting but not initialized as connected
106          */
107         std::map<irc::string,TreeSocket*> burstingserverlist;
108         /** List of all outgoing sockets and their timeouts
109          */
110         std::map<TreeSocket*, std::pair<std::string, int> > timeoutlist;
111         /** Holds the data from the <link> tags in the conf
112          */
113         std::vector<reference<Link> > LinkBlocks;
114         /** Holds the data from the <autoconnect> tags in the conf
115          */
116         std::vector<reference<Autoconnect> > AutoconnectBlocks;
117
118         /** True (default) if we are to use challenge-response HMAC
119          * to authenticate passwords.
120          *
121          * NOTE: This defaults to on, but should be turned off if
122          * you are linking to an older version of inspircd.
123          */
124         bool ChallengeResponse;
125
126         /** Ping frequency of server to server links
127          */
128         int PingFreq;
129
130         /** Initialise utility class
131          */
132         SpanningTreeUtilities(ModuleSpanningTree* Creator);
133
134         /** Prepare for class destruction
135          */
136         CullResult cull();
137
138         /** Destroy class and free listeners etc
139          */
140         ~SpanningTreeUtilities();
141
142         void RouteCommand(TreeServer*, const std::string&, const parameterlist&, User*);
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, parameterlist &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, parameterlist &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, parameterlist &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, parameterlist &params);
159
160         /** Send a message from this server to all others
161          */
162         bool DoOneToMany(const char* prefix, const char* command, parameterlist &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, parameterlist &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         /** Find a link tag from a server name
201          */
202         Link* FindLink(const std::string& name);
203
204         /** Refresh the IP cache used for allowing inbound connections
205          */
206         void RefreshIPCache();
207 };
208
209 #endif