2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
24 #include "treesocket.h"
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.
40 class TreeServer : public classbase
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 TreeSocket* Socket; /* For directly connected servers this points at the socket object */
49 time_t NextPing; /* After this time, the server should be PINGed*/
50 bool LastPingWasGood; /* True if the server responded to the last PING with a PONG */
51 SpanningTreeUtilities* Utils; /* Utility class */
52 std::string sid; /* Server ID */
56 * @throws CoreException on duplicate ID
58 void SetID(const std::string &id);
61 FakeUser* const ServerUser; /* User representing this server */
64 bool Warned; /* True if we've warned opers about high latency on this server */
65 bool bursting; /* whether or not this server is bursting */
67 unsigned int UserCount; /* How many users are on this server? [note: doesn't care about +i] */
68 unsigned int OperCount; /* How many opers are on this server? */
70 /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
71 * represents our own server. Therefore, it has no route, no parent, and
72 * no socket associated with it. Its version string is our own local version.
74 TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id);
76 /** When we create a new server, we call this constructor to initialize it.
77 * This constructor initializes the server's Route and Parent, and sets up
78 * its ping counters so that it will be pinged one minute from now.
80 TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
82 int QuitUsers(const std::string &reason);
84 /** This method is used to add the structure to the
85 * hash_map for linear searches. It is only called
86 * by the constructors.
90 /** This method removes the reference to this object
91 * from the hash_map which is used for linear searches.
92 * It is only called by the default destructor.
97 * The 'route' is defined as the locally-
98 * connected server which can be used to reach this server.
100 TreeServer* GetRoute();
104 std::string GetName();
106 /** Get server description (GECOS)
108 const std::string& GetDesc();
110 /** Get server version string
112 const std::string& GetVersion();
114 /** Set time we are next due to ping this server
116 void SetNextPingTime(time_t t);
118 /** Get the time we are next due to ping this server
120 time_t NextPingTime();
122 /** Last ping time in milliseconds, used to calculate round trip time
124 unsigned long LastPingMsec;
126 /** Round trip time of last ping
130 /** When we recieved BURST from this server, used to calculate total burst time at ENDBURST.
132 unsigned long StartBurst;
134 /** True if this server is hidden
138 /** True if the server answered their last ping
140 bool AnsweredLastPing();
142 /** Set the server as responding to its last ping
146 /** Get the TreeSocket pointer for local servers.
147 * For remote servers, this returns NULL.
149 TreeSocket* GetSocket();
151 /** Get the parent server.
152 * For the root node, this returns NULL.
154 TreeServer* GetParent();
156 /** Set the server version string
158 void SetVersion(const std::string &Version);
160 /** Return number of child servers
162 unsigned int ChildCount();
164 /** Return a child server indexed 0..n
166 TreeServer* GetChild(unsigned int n);
168 /** Add a child server
170 void AddChild(TreeServer* Child);
172 /** Delete a child server, return false if it didn't exist.
174 bool DelChild(TreeServer* Child);
176 /** Removes child nodes of this node, and of that node, etc etc.
177 * This is used during netsplits to automatically tidy up the
178 * server tree. It is slow, we don't use it for much else.
184 const std::string& GetID();
186 /** Marks a server as having finished bursting and performs appropriate actions.
189 /** Recursive call for child servers */
190 void FinishBurstInternal();