]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_spanningtree/treeserver.h
Remove space indents
[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);
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         /** These accessors etc should be pretty self-
68          * explanitory.
69          */
70         TreeServer* GetRoute();
71         std::string GetName();
72         std::string GetDesc();
73         std::string GetVersion();
74         void SetNextPingTime(time_t t);
75         time_t NextPingTime();
76         bool AnsweredLastPing();
77         void SetPingFlag();
78         int GetUserCount();
79         void AddUserCount();
80         void DelUserCount();
81         int GetOperCount();
82         TreeSocket* GetSocket();
83         TreeServer* GetParent();
84         void SetVersion(const std::string &Version);
85         unsigned int ChildCount();
86         TreeServer* GetChild(unsigned int n);
87         void AddChild(TreeServer* Child);
88         bool DelChild(TreeServer* Child);
89
90         /** Removes child nodes of this node, and of that node, etc etc.
91          * This is used during netsplits to automatically tidy up the
92          * server tree. It is slow, we don't use it for much else.
93          */
94         bool Tidy();
95
96         ~TreeServer();
97
98 };
99
100 #endif