1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
14 #ifndef __TREESERVER_H__
15 #define __TREESERVER_H__
17 #include "treesocket.h"
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.
33 class TreeServer : public classbase
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 */
51 * @throws CoreException on duplicate ID
53 void SetID(const std::string &id);
56 FakeUser* const ServerUser; /* User representing this server */
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 */
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.
66 TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id);
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.
72 TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
74 int QuitUsers(const std::string &reason);
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.
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.
89 * The 'route' is defined as the locally-
90 * connected server which can be used to reach this server.
92 TreeServer* GetRoute();
96 std::string GetName();
98 /** Get server description (GECOS)
100 std::string GetDesc();
102 /** Get server version string
104 std::string GetVersion();
106 /** Set time we are next due to ping this server
108 void SetNextPingTime(time_t t);
110 /** Get the time we are next due to ping this server
112 time_t NextPingTime();
114 /** Last ping time in milliseconds, used to calculate round trip time
116 unsigned long LastPingMsec;
118 /** Round trip time of last ping
122 /** When we recieved BURST from this server, used to calculate total burst time at ENDBURST.
124 unsigned long StartBurst;
126 /** True if this server is hidden
130 /** True if the server answered their last ping
132 bool AnsweredLastPing();
134 /** Set the server as responding to its last ping
138 /** Get the number of users on this server.
140 unsigned int GetUserCount();
142 /** Increment or decrement the user count by diff.
144 void SetUserCount(int diff);
146 /** Gets the numbers of opers on this server.
148 unsigned int GetOperCount();
150 /** Increment or decrement the oper count by diff.
152 void SetOperCount(int diff);
154 /** Get the TreeSocket pointer for local servers.
155 * For remote servers, this returns NULL.
157 TreeSocket* GetSocket();
159 /** Get the parent server.
160 * For the root node, this returns NULL.
162 TreeServer* GetParent();
164 /** Set the server version string
166 void SetVersion(const std::string &Version);
168 /** Return number of child servers
170 unsigned int ChildCount();
172 /** Return a child server indexed 0..n
174 TreeServer* GetChild(unsigned int n);
176 /** Add a child server
178 void AddChild(TreeServer* Child);
180 /** Delete a child server, return false if it didn't exist.
182 bool DelChild(TreeServer* Child);
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.
192 std::string& GetID();
194 /** Marks a server as having finished bursting and performs appropriate actions.
197 /** Recursive call for child servers */
198 void FinishBurstInternal();