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