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