]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Update copyrights for 2009.
[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://www.inspircd.org/wiki/index.php/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         InspIRCd* ServerInstance;               /* Creator */
34         TreeServer* Parent;                     /* Parent entry */
35         TreeServer* Route;                      /* Route entry */
36         std::vector<TreeServer*> Children;      /* List of child objects */
37         irc::string ServerName;                 /* Server's name */
38         std::string ServerDesc;                 /* Server's description */
39         std::string VersionString;              /* Version string or empty string */
40         unsigned int ServerUserCount;           /* How many users are on this server? [note: doesn't care about +i] */
41         unsigned int ServerOperCount;           /* How many opers are on this server? */
42         TreeSocket* Socket;                     /* For directly connected servers this points at the socket object */
43         time_t NextPing;                        /* After this time, the server should be PINGed*/
44         bool LastPingWasGood;                   /* True if the server responded to the last PING with a PONG */
45         SpanningTreeUtilities* Utils;           /* Utility class */
46         std::string sid;                        /* Server ID */
47         bool DupError;                          /* True if the server ID is duplicated (!) */
48
49         /** Set server ID
50          * @param id Server ID
51          * @throws CoreException on duplicate ID
52          */
53         void SetID(const std::string &id);
54
55  public:
56
57         bool Warned;                            /* True if we've warned opers about high latency on this server */
58         bool bursting;                          /* whether or not this server is bursting */
59         
60         /** We don't use this constructor. Its a dummy, and won't cause any insertion
61          * of the TreeServer into the hash_map. See below for the two we DO use.
62          */
63         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &id);
64
65         /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
66          * represents our own server. Therefore, it has no route, no parent, and
67          * no socket associated with it. Its version string is our own local version.
68          */
69         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, const std::string &id);
70         
71         /** When we create a new server, we call this constructor to initialize it.
72          * This constructor initializes the server's Route and Parent, and sets up
73          * its ping counters so that it will be pinged one minute from now.
74          */
75         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
76
77         int QuitUsers(const std::string &reason);
78
79         /** This method is used to add the structure to the
80          * hash_map for linear searches. It is only called
81          * by the constructors.
82          */
83         void AddHashEntry();
84
85         /** This method removes the reference to this object
86          * from the hash_map which is used for linear searches.
87          * It is only called by the default destructor.
88          */
89         void DelHashEntry();
90
91         /** Get route.
92          * The 'route' is defined as the locally-
93          * connected server which can be used to reach this server.
94          */
95         TreeServer* GetRoute();
96
97         /** Get server name
98          */
99         std::string GetName();
100
101         /** Get server description (GECOS)
102          */
103         std::string GetDesc();
104
105         /** Get server version string
106          */
107         std::string GetVersion();
108
109         /** Set time we are next due to ping this server
110          */
111         void SetNextPingTime(time_t t);
112
113         /** Get the time we are next due to ping this server
114          */
115         time_t NextPingTime();
116
117         /** Last ping time in microseconds, used to calculate round trip time
118          */
119         unsigned long LastPingMsec;
120
121         /** Round trip time of last ping
122          */
123         unsigned long rtt;
124         
125         /** When we recieved BURST from this server, used to calculate total burst time at ENDBURST.
126          */
127         unsigned long StartBurst;
128
129         /** True if this server is hidden
130          */
131         bool Hidden;
132
133         /** True if the server answered their last ping
134          */
135         bool AnsweredLastPing();
136
137         /** Set the server as responding to its last ping
138          */
139         void SetPingFlag();
140
141         /** Get the number of users on this server.
142          */
143         unsigned int GetUserCount();
144
145         /** Increment or decrement the user count by diff.
146          */
147         void SetUserCount(int diff);
148
149         /** Gets the numbers of opers on this server.
150          */
151         unsigned int GetOperCount();
152
153         /** Increment or decrement the oper count by diff.
154          */
155         void SetOperCount(int diff);
156
157         /** Get the TreeSocket pointer for local servers.
158          * For remote servers, this returns NULL.
159          */
160         TreeSocket* GetSocket();
161
162         /** Get the parent server.
163          * For the root node, this returns NULL.
164          */
165         TreeServer* GetParent();
166
167         /** Set the server version string
168          */
169         void SetVersion(const std::string &Version);
170
171         /** Return number of child servers
172          */
173         unsigned int ChildCount();
174
175         /** Return a child server indexed 0..n
176          */
177         TreeServer* GetChild(unsigned int n);
178
179         /** Add a child server
180          */
181         void AddChild(TreeServer* Child);
182
183         /** Delete a child server, return false if it didn't exist.
184          */
185         bool DelChild(TreeServer* Child);
186
187         /** Removes child nodes of this node, and of that node, etc etc.
188          * This is used during netsplits to automatically tidy up the
189          * server tree. It is slow, we don't use it for much else.
190          */
191         bool Tidy();
192
193         /** Get server ID
194          */
195         std::string& GetID();
196
197         /** True on duplicate server ID (server not usable)
198          */
199         bool DuplicateID();
200
201         /** Marks a server as having finished bursting and performs appropriate actions.
202          */
203         void FinishBurst();
204
205         /** Destructor
206          */
207         ~TreeServer();
208
209 };
210
211 #endif