]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
381ed928f678ed139a5a94ab20a862e35a445fba
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.h
1 #ifndef __TREESERVER_H__
2 #define __TREESERVER_H__
3
4 /** Each server in the tree is represented by one class of
5  * type TreeServer. A locally connected TreeServer can
6  * have a class of type TreeSocket associated with it, for
7  * remote servers, the TreeSocket entry will be NULL.
8  * Each server also maintains a pointer to its parent
9  * (NULL if this server is ours, at the top of the tree)
10  * and a pointer to its "Route" (see the comments in the
11  * constructors below), and also a dynamic list of pointers
12  * to its children which can be iterated recursively
13  * if required. Creating or deleting objects of type
14  i* TreeServer automatically maintains the hash_map of
15  * TreeServer items, deleting and inserting them as they
16  * are created and destroyed.
17  */
18 class TreeServer : public classbase
19 {
20         InspIRCd* ServerInstance;               /* Creator */
21         TreeServer* Parent;                     /* Parent entry */
22         TreeServer* Route;                      /* Route entry */
23         std::vector<TreeServer*> Children;      /* List of child objects */
24         irc::string ServerName;                 /* Server's name */
25         std::string ServerDesc;                 /* Server's description */
26         std::string VersionString;              /* Version string or empty string */
27         int UserCount;                          /* Not used in this version */
28         int OperCount;                          /* Not used in this version */
29         TreeSocket* Socket;                     /* For directly connected servers this points at the socket object */
30         time_t NextPing;                        /* After this time, the server should be PINGed*/
31         bool LastPingWasGood;                   /* True if the server responded to the last PING with a PONG */
32         SpanningTreeUtilities* Utils;           /* Utility class */
33
34  public:
35
36         /** We don't use this constructor. Its a dummy, and won't cause any insertion
37          * of the TreeServer into the hash_map. See below for the two we DO use.
38          */
39         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance);
40
41         /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
42          * represents our own server. Therefore, it has no route, no parent, and
43          * no socket associated with it. Its version string is our own local version.
44          */
45         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc);
46         
47         /** When we create a new server, we call this constructor to initialize it.
48          * This constructor initializes the server's Route and Parent, and sets up
49          * its ping counters so that it will be pinged one minute from now.
50          */
51         TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock, bool Hide);
52
53         int QuitUsers(const std::string &reason);
54
55         /** This method is used to add the structure to the
56          * hash_map for linear searches. It is only called
57          * by the constructors.
58          */
59         void AddHashEntry();
60
61         /** This method removes the reference to this object
62          * from the hash_map which is used for linear searches.
63          * It is only called by the default destructor.
64          */
65         void DelHashEntry();
66
67         /** Get route.
68          * The 'route' is defined as the locally-
69          * connected server which can be used to reach this server.
70          */
71         TreeServer* GetRoute();
72
73         /** Get server name
74          */
75         std::string GetName();
76
77         /** Get server description (GECOS)
78          */
79         std::string GetDesc();
80
81         /** Get server version string
82          */
83         std::string GetVersion();
84
85         /** Set time we are next due to ping this server
86          */
87         void SetNextPingTime(time_t t);
88
89         /** Get the time we are next due to ping this server
90          */
91         time_t NextPingTime();
92
93         /** Time of last ping used to calculate this->rtt below
94          */
95         time_t LastPing;
96
97         /** Round trip time of last ping
98          */
99         time_t rtt;
100
101         /** True if this server is hidden
102          */
103         bool Hidden;
104
105         /** True if the server answered their last ping
106          */
107         bool AnsweredLastPing();
108
109         /** Set the server as responding to its last ping
110          */
111         void SetPingFlag();
112
113         /** Get the number of users on this server for MAP
114          */
115         int GetUserCount();
116
117         /** Increment the user counter
118          */
119         void AddUserCount();
120
121         /** Decrement the user counter
122          */
123         void DelUserCount();
124
125         /** Get the oper count for this server
126          */
127         int GetOperCount();
128
129         /** Get the TreeSocket pointer for local servers.
130          * For remote servers, this returns NULL.
131          */
132         TreeSocket* GetSocket();
133
134         /** Get the parent server.
135          * For the root node, this returns NULL.
136          */
137         TreeServer* GetParent();
138
139         /** Set the server version string
140          */
141         void SetVersion(const std::string &Version);
142
143         /** Return number of child servers
144          */
145         unsigned int ChildCount();
146
147         /** Return a child server indexed 0..n
148          */
149         TreeServer* GetChild(unsigned int n);
150
151         /** Add a child server
152          */
153         void AddChild(TreeServer* Child);
154
155         /** Delete a child server, return false if it didn't exist.
156          */
157         bool DelChild(TreeServer* Child);
158
159         /** Removes child nodes of this node, and of that node, etc etc.
160          * This is used during netsplits to automatically tidy up the
161          * server tree. It is slow, we don't use it for much else.
162          */
163         bool Tidy();
164
165         /** Destructor
166          */
167         ~TreeServer();
168
169 };
170
171 #endif