1 #ifndef __TREESERVER_H__
2 #define __TREESERVER_H__
4 /** Each server in the tree is represented by one class of
5 * type TreeServer. A locally connected TreeServer can
6 * have a class of type TreeSocket associated with it, for
7 * remote servers, the TreeSocket entry will be NULL.
8 * Each server also maintains a pointer to its parent
9 * (NULL if this server is ours, at the top of the tree)
10 * and a pointer to its "Route" (see the comments in the
11 * constructors below), and also a dynamic list of pointers
12 * to its children which can be iterated recursively
13 * if required. Creating or deleting objects of type
14 i* TreeServer automatically maintains the hash_map of
15 * TreeServer items, deleting and inserting them as they
16 * are created and destroyed.
18 class TreeServer : public classbase
20 InspIRCd* ServerInstance; /* Creator */
21 TreeServer* Parent; /* Parent entry */
22 TreeServer* Route; /* Route entry */
23 std::vector<TreeServer*> Children; /* List of child objects */
24 irc::string ServerName; /* Server's name */
25 std::string ServerDesc; /* Server's description */
26 std::string VersionString; /* Version string or empty string */
27 int UserCount; /* Not used in this version */
28 int OperCount; /* Not used in this version */
29 TreeSocket* Socket; /* For directly connected servers this points at the socket object */
30 time_t NextPing; /* After this time, the server should be PINGed*/
31 bool LastPingWasGood; /* True if the server responded to the last PING with a PONG */
32 SpanningTreeUtilities* Utils; /* Utility class */
36 /** We don't use this constructor. Its a dummy, and won't cause any insertion
37 * of the TreeServer into the hash_map. See below for the two we DO use.
39 TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance);
41 /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
42 * represents our own server. Therefore, it has no route, no parent, and
43 * no socket associated with it. Its version string is our own local version.
45 TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc);
47 /** When we create a new server, we call this constructor to initialize it.
48 * This constructor initializes the server's Route and Parent, and sets up
49 * its ping counters so that it will be pinged one minute from now.
51 TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock);
53 int QuitUsers(const std::string &reason);
55 /** This method is used to add the structure to the
56 * hash_map for linear searches. It is only called
57 * by the constructors.
61 /** This method removes the reference to this object
62 * from the hash_map which is used for linear searches.
63 * It is only called by the default destructor.
68 * The 'route' is defined as the locally-
69 * connected server which can be used to reach this server.
71 TreeServer* GetRoute();
75 std::string GetName();
77 /** Get server description (GECOS)
79 std::string GetDesc();
81 /** Get server version string
83 std::string GetVersion();
85 /** Set time we are next due to ping this server
87 void SetNextPingTime(time_t t);
89 /** Get the time we are next due to ping this server
91 time_t NextPingTime();
93 /** True if the server answered their last ping
95 bool AnsweredLastPing();
97 /** Set the server as responding to its last ping
101 /** Get the number of users on this server for MAP
105 /** Increment the user counter
109 /** Decrement the user counter
113 /** Get the oper count for this server
117 /** Get the TreeSocket pointer for local servers.
118 * For remote servers, this returns NULL.
120 TreeSocket* GetSocket();
122 /** Get the parent server.
123 * For the root node, this returns NULL.
125 TreeServer* GetParent();
127 /** Set the server version string
129 void SetVersion(const std::string &Version);
131 /** Return number of child servers
133 unsigned int ChildCount();
135 /** Return a child server indexed 0..n
137 TreeServer* GetChild(unsigned int n);
139 /** Add a child server
141 void AddChild(TreeServer* Child);
143 /** Delete a child server, return false if it didn't exist.
145 bool DelChild(TreeServer* Child);
147 /** Removes child nodes of this node, and of that node, etc etc.
148 * This is used during netsplits to automatically tidy up the
149 * server tree. It is slow, we don't use it for much else.