-#include "transport.h"
-
-#include "m_spanningtree/utils.h"
-#include "m_spanningtree/treeserver.h"
-
- TreeServer::TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance) : ServerInstance(Instance), Utils(Util)
- {
- Parent = NULL;
- ServerName = "";
- ServerDesc = "";
- VersionString = "";
- UserCount = OperCount = 0;
- VersionString = ServerInstance->GetVersionString();
- }
-
- /** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
- * represents our own server. Therefore, it has no route, no parent, and
- * no socket associated with it. Its version string is our own local version.
+#include "main.h"
+#include "../spanningtree.h"
+
+#include "utils.h"
+#include "treeserver.h"
+
+/* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h */
+
+/** We use this constructor only to create the 'root' item, Utils->TreeRoot, which
+ * represents our own server. Therefore, it has no route, no parent, and
+ * no socket associated with it. Its version string is our own local version.
+ */
+TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id)
+ : ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util), ServerUser(ServerInstance->FakeClient)
+{
+ age = ServerInstance->Time();
+ bursting = false;
+ Parent = NULL;
+ VersionString.clear();
+ ServerUserCount = ServerOperCount = 0;
+ VersionString = ServerInstance->GetVersionString();
+ Route = NULL;
+ Socket = NULL; /* Fix by brain */
+ StartBurst = rtt = 0;
+ Warned = Hidden = false;
+ AddHashEntry();
+ SetID(id);
+}
+
+/** When we create a new server, we call this constructor to initialize it.
+ * This constructor initializes the server's Route and Parent, and sets up
+ * its ping counters so that it will be pinged one minute from now.
+ */
+TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide)
+ : Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), ServerUser(new FakeUser(id, Name)), Hidden(Hide)
+{
+ age = ServerInstance->Time();
+ bursting = true;
+ VersionString.clear();
+ ServerUserCount = ServerOperCount = 0;
+ SetNextPingTime(ServerInstance->Time() + Utils->PingFreq);
+ SetPingFlag();
+ Warned = false;
+ rtt = 0;
+
+ timeval t;
+ gettimeofday(&t, NULL);
+ long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
+ this->StartBurst = ts;
+ ServerInstance->Logs->Log("m_spanningtree",DEBUG, "Started bursting at time %lu", ts);
+
+ /* find the 'route' for this server (e.g. the one directly connected
+ * to the local server, which we can use to reach it)
+ *
+ * In the following example, consider we have just added a TreeServer
+ * class for server G on our network, of which we are server A.
+ * To route traffic to G (marked with a *) we must send the data to
+ * B (marked with a +) so this algorithm initializes the 'Route'
+ * value to point at whichever server traffic must be routed through
+ * to get here. If we were to try this algorithm with server B,
+ * the Route pointer would point at its own object ('this').
+ *
+ * A
+ * / \
+ * + B C
+ * / \ \
+ * D E F
+ * / \
+ * * G H
+ *
+ * We only run this algorithm when a server is created, as
+ * the routes remain constant while ever the server exists, and
+ * do not need to be re-calculated.