]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Remove InspIRCd* parameters and fields
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #ifndef __TREESERVER_H__
15 #define __TREESERVER_H__
16
17 /** Each server in the tree is represented by one class of
18  * type TreeServer. A locally connected TreeServer can
19  * have a class of type TreeSocket associated with it, for
20  * remote servers, the TreeSocket entry will be NULL.
21  * Each server also maintains a pointer to its parent
22  * (NULL if this server is ours, at the top of the tree)
23  * and a pointer to its "Route" (see the comments in the
24  * constructors below), and also a dynamic list of pointers
25  * to its children which can be iterated recursively
26  * if required. Creating or deleting objects of type
27  i* TreeServer automatically maintains the hash_map of
28  * TreeServer items, deleting and inserting them as they
29  * are created and destroyed.
30  */
31 class TreeServer : public classbase
32 {
33         TreeServer* Parent;                     /* Parent entry */
34         TreeServer* Route;                      /* Route entry */
35         std::vector<TreeServer*> Children;      /* List of child objects */
36         irc::string ServerName;                 /* Server's name */
37         std::string ServerDesc;                 /* Server's description */
38         std::string VersionString;              /* Version string or empty string */
39         unsigned int ServerUserCount;           /* How many users are on this server? [note: doesn't care about +i] */
40         unsigned int ServerOperCount;           /* How many opers are on this server? */
41         TreeSocket* Socket;                     /* For directly connected servers this points at the socket object */
42         time_t NextPing;                        /* After this time, the server should be PINGed*/
43         bool LastPingWasGood;                   /* True if the server responded to the last PING with a PONG */
44         SpanningTreeUtilities* Utils;           /* Utility class */
45         std::string sid;                        /* Server ID */
46
47         /** Set server ID
48          * @param id Server ID
49          * @throws CoreException on duplicate ID
50          */
51         void SetID(const std::string &id);
52
53  public:
54         time_t age;
55
56         bool Warned;                            /* True if we've warned opers about high latency on this server */
57         bool bursting;                          /* whether or not this server is bursting */
58
59         /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
60          * represents our own server. Therefore, it has no route, no parent, and
61          * no socket associated with it. Its version string is our own local version.
62          */
63         TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id);
64
65         /** When we create a new server, we call this constructor to initialize it.
66          * This constructor initializes the server's Route and Parent, and sets up
67          * its ping counters so that it will be pinged one minute from now.
68          */
69         TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
70
71         int QuitUsers(const std::string &reason);
72
73         /** This method is used to add the structure to the
74          * hash_map for linear searches. It is only called
75          * by the constructors.
76          */
77         void AddHashEntry();
78
79         /** This method removes the reference to this object
80          * from the hash_map which is used for linear searches.
81          * It is only called by the default destructor.
82          */
83         void DelHashEntry();
84
85         /** Get route.
86          * The 'route' is defined as the locally-
87          * connected server which can be used to reach this server.
88          */
89         TreeServer* GetRoute();
90
91         /** Get server name
92          */
93         std::string GetName();
94
95         /** Get server description (GECOS)
96          */
97         std::string GetDesc();
98
99         /** Get server version string
100          */
101         std::string GetVersion();
102
103         /** Set time we are next due to ping this server
104          */
105         void SetNextPingTime(time_t t);
106
107         /** Get the time we are next due to ping this server
108          */
109         time_t NextPingTime();
110
111         /** Last ping time in microseconds, used to calculate round trip time
112          */
113         unsigned long LastPingMsec;
114
115         /** Round trip time of last ping
116          */
117         unsigned long rtt;
118
119         /** When we recieved BURST from this server, used to calculate total burst time at ENDBURST.
120          */
121         unsigned long StartBurst;
122
123         /** True if this server is hidden
124          */
125         bool Hidden;
126
127         /** True if the server answered their last ping
128          */
129         bool AnsweredLastPing();
130
131         /** Set the server as responding to its last ping
132          */
133         void SetPingFlag();
134
135         /** Get the number of users on this server.
136          */
137         unsigned int GetUserCount();
138
139         /** Increment or decrement the user count by diff.
140          */
141         void SetUserCount(int diff);
142
143         /** Gets the numbers of opers on this server.
144          */
145         unsigned int GetOperCount();
146
147         /** Increment or decrement the oper count by diff.
148          */
149         void SetOperCount(int diff);
150
151         /** Get the TreeSocket pointer for local servers.
152          * For remote servers, this returns NULL.
153          */
154         TreeSocket* GetSocket();
155
156         /** Get the parent server.
157          * For the root node, this returns NULL.
158          */
159         TreeServer* GetParent();
160
161         /** Set the server version string
162          */
163         void SetVersion(const std::string &Version);
164
165         /** Return number of child servers
166          */
167         unsigned int ChildCount();
168
169         /** Return a child server indexed 0..n
170          */
171         TreeServer* GetChild(unsigned int n);
172
173         /** Add a child server
174          */
175         void AddChild(TreeServer* Child);
176
177         /** Delete a child server, return false if it didn't exist.
178          */
179         bool DelChild(TreeServer* Child);
180
181         /** Removes child nodes of this node, and of that node, etc etc.
182          * This is used during netsplits to automatically tidy up the
183          * server tree. It is slow, we don't use it for much else.
184          */
185         bool Tidy();
186
187         /** Get server ID
188          */
189         std::string& GetID();
190
191         /** Marks a server as having finished bursting and performs appropriate actions.
192          */
193         void FinishBurst();
194         /** Recursive call for child servers */
195         void FinishBurstInternal();
196
197         /** Destructor
198          */
199         ~TreeServer();
200
201 };
202
203 #endif