]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Move lots of spanningtree items to commands
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 __TREESERVER_H__
15 #define __TREESERVER_H__
16
17 #include "treesocket.h"
18
19 /** Each server in the tree is represented by one class of
20  * type TreeServer. A locally connected TreeServer can
21  * have a class of type TreeSocket associated with it, for
22  * remote servers, the TreeSocket entry will be NULL.
23  * Each server also maintains a pointer to its parent
24  * (NULL if this server is ours, at the top of the tree)
25  * and a pointer to its "Route" (see the comments in the
26  * constructors below), and also a dynamic list of pointers
27  * to its children which can be iterated recursively
28  * if required. Creating or deleting objects of type
29  i* TreeServer automatically maintains the hash_map of
30  * TreeServer items, deleting and inserting them as they
31  * are created and destroyed.
32  */
33 class TreeServer : public classbase
34 {
35         TreeServer* Parent;                     /* Parent entry */
36         TreeServer* Route;                      /* Route entry */
37         std::vector<TreeServer*> Children;      /* List of child objects */
38         irc::string ServerName;                 /* Server's name */
39         std::string ServerDesc;                 /* Server's description */
40         std::string VersionString;              /* Version string or empty string */
41         unsigned int ServerUserCount;           /* How many users are on this server? [note: doesn't care about +i] */
42         unsigned int ServerOperCount;           /* How many opers are on this server? */
43         TreeSocket* Socket;                     /* For directly connected servers this points at the socket object */
44         time_t NextPing;                        /* After this time, the server should be PINGed*/
45         bool LastPingWasGood;                   /* True if the server responded to the last PING with a PONG */
46         SpanningTreeUtilities* Utils;           /* Utility class */
47         std::string sid;                        /* Server ID */
48
49         /** Set server ID
50          * @param id Server ID
51          * @throws CoreException on duplicate ID
52          */
53         void SetID(const std::string &id);
54
55  public:
56         FakeUser* const ServerUser;             /* User representing this server */
57         time_t age;
58
59         bool Warned;                            /* True if we've warned opers about high latency on this server */
60         bool bursting;                          /* whether or not this server is bursting */
61
62         /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
63          * represents our own server. Therefore, it has no route, no parent, and
64          * no socket associated with it. Its version string is our own local version.
65          */
66         TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id);
67
68         /** When we create a new server, we call this constructor to initialize it.
69          * This constructor initializes the server's Route and Parent, and sets up
70          * its ping counters so that it will be pinged one minute from now.
71          */
72         TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
73
74         int QuitUsers(const std::string &reason);
75
76         /** This method is used to add the structure to the
77          * hash_map for linear searches. It is only called
78          * by the constructors.
79          */
80         void AddHashEntry();
81
82         /** This method removes the reference to this object
83          * from the hash_map which is used for linear searches.
84          * It is only called by the default destructor.
85          */
86         void DelHashEntry();
87
88         /** Get route.
89          * The 'route' is defined as the locally-
90          * connected server which can be used to reach this server.
91          */
92         TreeServer* GetRoute();
93
94         /** Get server name
95          */
96         std::string GetName();
97
98         /** Get server description (GECOS)
99          */
100         std::string GetDesc();
101
102         /** Get server version string
103          */
104         std::string GetVersion();
105
106         /** Set time we are next due to ping this server
107          */
108         void SetNextPingTime(time_t t);
109
110         /** Get the time we are next due to ping this server
111          */
112         time_t NextPingTime();
113
114         /** Last ping time in milliseconds, used to calculate round trip time
115          */
116         unsigned long LastPingMsec;
117
118         /** Round trip time of last ping
119          */
120         unsigned long rtt;
121
122         /** When we recieved BURST from this server, used to calculate total burst time at ENDBURST.
123          */
124         unsigned long StartBurst;
125
126         /** True if this server is hidden
127          */
128         bool Hidden;
129
130         /** True if the server answered their last ping
131          */
132         bool AnsweredLastPing();
133
134         /** Set the server as responding to its last ping
135          */
136         void SetPingFlag();
137
138         /** Get the number of users on this server.
139          */
140         unsigned int GetUserCount();
141
142         /** Increment or decrement the user count by diff.
143          */
144         void SetUserCount(int diff);
145
146         /** Gets the numbers of opers on this server.
147          */
148         unsigned int GetOperCount();
149
150         /** Increment or decrement the oper count by diff.
151          */
152         void SetOperCount(int diff);
153
154         /** Get the TreeSocket pointer for local servers.
155          * For remote servers, this returns NULL.
156          */
157         TreeSocket* GetSocket();
158
159         /** Get the parent server.
160          * For the root node, this returns NULL.
161          */
162         TreeServer* GetParent();
163
164         /** Set the server version string
165          */
166         void SetVersion(const std::string &Version);
167
168         /** Return number of child servers
169          */
170         unsigned int ChildCount();
171
172         /** Return a child server indexed 0..n
173          */
174         TreeServer* GetChild(unsigned int n);
175
176         /** Add a child server
177          */
178         void AddChild(TreeServer* Child);
179
180         /** Delete a child server, return false if it didn't exist.
181          */
182         bool DelChild(TreeServer* Child);
183
184         /** Removes child nodes of this node, and of that node, etc etc.
185          * This is used during netsplits to automatically tidy up the
186          * server tree. It is slow, we don't use it for much else.
187          */
188         bool Tidy();
189
190         /** Get server ID
191          */
192         std::string& GetID();
193
194         /** Marks a server as having finished bursting and performs appropriate actions.
195          */
196         void FinishBurst();
197         /** Recursive call for child servers */
198         void FinishBurstInternal();
199
200         CullResult cull();
201         /** Destructor
202          */
203         ~TreeServer();
204 };
205
206 #endif