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.
67 /** These accessors etc should be pretty self-
70 TreeServer* GetRoute();
71 std::string GetName();
72 std::string GetDesc();
73 std::string GetVersion();
74 void SetNextPingTime(time_t t);
75 time_t NextPingTime();
76 bool AnsweredLastPing();
82 TreeSocket* GetSocket();
83 TreeServer* GetParent();
84 void SetVersion(const std::string &Version);
85 unsigned int ChildCount();
86 TreeServer* GetChild(unsigned int n);
87 void AddChild(TreeServer* Child);
88 bool DelChild(TreeServer* Child);
90 /** Removes child nodes of this node, and of that node, etc etc.
91 * This is used during netsplits to automatically tidy up the
92 * server tree. It is slow, we don't use it for much else.