]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Add extra /map info (connection uptime, and lag time) to /MAP for opers. Adds feature...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.h
1 #ifndef __TREESERVER_H__
2 #define __TREESERVER_H__
3
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.
17  */
18 class TreeServer : public classbase
19 {
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 */
33
34  public:
35
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.
38          */
39         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance);
40
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.
44          */
45         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc);
46         
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.
50          */
51         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock);
52
53         int QuitUsers(const std::string &reason);
54
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.
58          */
59         void AddHashEntry();
60
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.
64          */
65         void DelHashEntry();
66
67         /** Get route.
68          * The 'route' is defined as the locally-
69          * connected server which can be used to reach this server.
70          */
71         TreeServer* GetRoute();
72
73         /** Get server name
74          */
75         std::string GetName();
76
77         /** Get server description (GECOS)
78          */
79         std::string GetDesc();
80
81         /** Get server version string
82          */
83         std::string GetVersion();
84
85         /** Set time we are next due to ping this server
86          */
87         void SetNextPingTime(time_t t);
88
89         /** Get the time we are next due to ping this server
90          */
91         time_t NextPingTime();
92
93         /** Time of last ping used to calculate this->rtt below
94          */
95         time_t LastPing;
96
97         /** Round trip time of last ping
98          */
99         time_t rtt;
100
101         /** True if the server answered their last ping
102          */
103         bool AnsweredLastPing();
104
105         /** Set the server as responding to its last ping
106          */
107         void SetPingFlag();
108
109         /** Get the number of users on this server for MAP
110          */
111         int GetUserCount();
112
113         /** Increment the user counter
114          */
115         void AddUserCount();
116
117         /** Decrement the user counter
118          */
119         void DelUserCount();
120
121         /** Get the oper count for this server
122          */
123         int GetOperCount();
124
125         /** Get the TreeSocket pointer for local servers.
126          * For remote servers, this returns NULL.
127          */
128         TreeSocket* GetSocket();
129
130         /** Get the parent server.
131          * For the root node, this returns NULL.
132          */
133         TreeServer* GetParent();
134
135         /** Set the server version string
136          */
137         void SetVersion(const std::string &Version);
138
139         /** Return number of child servers
140          */
141         unsigned int ChildCount();
142
143         /** Return a child server indexed 0..n
144          */
145         TreeServer* GetChild(unsigned int n);
146
147         /** Add a child server
148          */
149         void AddChild(TreeServer* Child);
150
151         /** Delete a child server, return false if it didn't exist.
152          */
153         bool DelChild(TreeServer* Child);
154
155         /** Removes child nodes of this node, and of that node, etc etc.
156          * This is used during netsplits to automatically tidy up the
157          * server tree. It is slow, we don't use it for much else.
158          */
159         bool Tidy();
160
161         /** Destructor
162          */
163         ~TreeServer();
164
165 };
166
167 #endif