]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Remove an obsolete value
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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
59         /** We don't use this constructor. Its a dummy, and won't cause any insertion
60          * of the TreeServer into the hash_map. See below for the two we DO use.
61          */
62         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &id);
63
64         /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
65          * represents our own server. Therefore, it has no route, no parent, and
66          * no socket associated with it. Its version string is our own local version.
67          */
68         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, const std::string &id);
69         
70         /** When we create a new server, we call this constructor to initialize it.
71          * This constructor initializes the server's Route and Parent, and sets up
72          * its ping counters so that it will be pinged one minute from now.
73          */
74         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide);
75
76         int QuitUsers(const std::string &reason);
77
78         /** This method is used to add the structure to the
79          * hash_map for linear searches. It is only called
80          * by the constructors.
81          */
82         void AddHashEntry();
83
84         /** This method removes the reference to this object
85          * from the hash_map which is used for linear searches.
86          * It is only called by the default destructor.
87          */
88         void DelHashEntry();
89
90         /** Get route.
91          * The 'route' is defined as the locally-
92          * connected server which can be used to reach this server.
93          */
94         TreeServer* GetRoute();
95
96         /** Get server name
97          */
98         std::string GetName();
99
100         /** Get server description (GECOS)
101          */
102         std::string GetDesc();
103
104         /** Get server version string
105          */
106         std::string GetVersion();
107
108         /** Set time we are next due to ping this server
109          */
110         void SetNextPingTime(time_t t);
111
112         /** Get the time we are next due to ping this server
113          */
114         time_t NextPingTime();
115
116         /** Last ping time in microseconds, used to calculate round trip time
117          */
118         unsigned long LastPingMsec;
119
120         /** Round trip time of last ping
121          */
122         unsigned long rtt;
123
124         /** True if this server is hidden
125          */
126         bool Hidden;
127
128         /** True if the server answered their last ping
129          */
130         bool AnsweredLastPing();
131
132         /** Set the server as responding to its last ping
133          */
134         void SetPingFlag();
135
136         /** Get the number of users on this server.
137          */
138         unsigned int GetUserCount();
139
140         /** Increment or decrement the user count by diff.
141          */
142         void SetUserCount(int diff);
143
144         /** Gets the numbers of opers on this server.
145          */
146         unsigned int GetOperCount();
147
148         /** Increment or decrement the oper count by diff.
149          */
150         void SetOperCount(int diff);
151
152         /** Get the TreeSocket pointer for local servers.
153          * For remote servers, this returns NULL.
154          */
155         TreeSocket* GetSocket();
156
157         /** Get the parent server.
158          * For the root node, this returns NULL.
159          */
160         TreeServer* GetParent();
161
162         /** Set the server version string
163          */
164         void SetVersion(const std::string &Version);
165
166         /** Return number of child servers
167          */
168         unsigned int ChildCount();
169
170         /** Return a child server indexed 0..n
171          */
172         TreeServer* GetChild(unsigned int n);
173
174         /** Add a child server
175          */
176         void AddChild(TreeServer* Child);
177
178         /** Delete a child server, return false if it didn't exist.
179          */
180         bool DelChild(TreeServer* Child);
181
182         /** Removes child nodes of this node, and of that node, etc etc.
183          * This is used during netsplits to automatically tidy up the
184          * server tree. It is slow, we don't use it for much else.
185          */
186         bool Tidy();
187
188         /** Get server ID
189          */
190         std::string& GetID();
191
192         /** True on duplicate server ID (server not usable)
193          */
194         bool DuplicateID();
195
196         /** Destructor
197          */
198         ~TreeServer();
199
200 };
201
202 #endif