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