From a4305d8f3c3e613be839bdcd61a1d14c87fed5aa Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 23 Sep 2019 11:49:26 +0100 Subject: Add the server id to the Server class. --- src/modules/m_spanningtree/treeserver.cpp | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'src/modules/m_spanningtree/treeserver.cpp') diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 952899962..2b143269c 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -32,16 +32,22 @@ * no socket associated with it. Its version string is our own local version. */ TreeServer::TreeServer() - : Server(ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc) + : Server(ServerInstance->Config->GetSID(), ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc) , Parent(NULL), Route(NULL) , VersionString(ServerInstance->GetVersionString()) , fullversion(ServerInstance->GetVersionString(true)) , rawversion(INSPIRCD_VERSION) - , Socket(NULL), sid(ServerInstance->Config->GetSID()), behind_bursting(0), isdead(false) + , Socket(NULL) + , behind_bursting(0) + , isdead(false) , pingtimer(this) , ServerUser(ServerInstance->FakeClient) - , age(ServerInstance->Time()), UserCount(ServerInstance->Users.LocalUserCount()) - , OperCount(0), rtt(0), StartBurst(0), Hidden(false) + , age(ServerInstance->Time()) + , UserCount(ServerInstance->Users.LocalUserCount()) + , OperCount(0) + , rtt(0) + , StartBurst(0) + , Hidden(false) { AddHashEntry(); } @@ -51,11 +57,19 @@ TreeServer::TreeServer() * the ping timer for the server. */ TreeServer::TreeServer(const std::string& Name, const std::string& Desc, const std::string& id, TreeServer* Above, TreeSocket* Sock, bool Hide) - : Server(Name, Desc) - , Parent(Above), Socket(Sock), sid(id), behind_bursting(Parent->behind_bursting), isdead(false) + : Server(id, Name, Desc) + , Parent(Above) + , Socket(Sock) + , behind_bursting(Parent->behind_bursting) + , isdead(false) , pingtimer(this) , ServerUser(new FakeUser(id, this)) - , age(ServerInstance->Time()), UserCount(0), OperCount(0), rtt(0), StartBurst(0), Hidden(Hide) + , age(ServerInstance->Time()) + , UserCount(0) + , OperCount(0) + , rtt(0) + , StartBurst(0) + , Hidden(Hide) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "New server %s behind_bursting %u", GetName().c_str(), behind_bursting); CheckULine(); @@ -128,7 +142,7 @@ void TreeServer::BeginBurst(uint64_t startms) if ((!startms) || (startms > now)) startms = now; this->StartBurst = startms; - ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Server %s started bursting at time %s behind_bursting %u", sid.c_str(), ConvToStr(startms).c_str(), behind_bursting); + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Server %s started bursting at time %s behind_bursting %u", GetId().c_str(), ConvToStr(startms).c_str(), behind_bursting); } void TreeServer::FinishBurstInternal() @@ -166,7 +180,7 @@ void TreeServer::SQuitChild(TreeServer* server, const std::string& reason) { // Server split from us, generate a SQUIT message and broadcast it ServerInstance->SNO->WriteGlobalSno('l', "Server \002" + server->GetName() + "\002 split: " + reason); - CmdBuilder("SQUIT").push(server->GetID()).push_last(reason).Broadcast(); + CmdBuilder("SQUIT").push(server->GetId()).push_last(reason).Broadcast(); } else { @@ -258,7 +272,7 @@ void TreeServer::CheckULine() void TreeServer::AddHashEntry() { Utils->serverlist[GetName()] = this; - Utils->sidlist[sid] = this; + Utils->sidlist[GetId()] = this; } CullResult TreeServer::cull() @@ -288,6 +302,6 @@ TreeServer::~TreeServer() void TreeServer::RemoveHash() { - Utils->sidlist.erase(sid); + Utils->sidlist.erase(GetId()); Utils->serverlist.erase(GetName()); } -- cgit v1.3.1-10-gc9f91 From cf5d382b822cecd54fdbc77e4c1c4de8a8aa3c35 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 23 Sep 2019 11:51:09 +0100 Subject: Add whether the server split with an error to OnServerSplit. --- include/modules/server.h | 24 ++++++++++++++++++++---- src/modules/m_sasl.cpp | 2 +- src/modules/m_spanningtree/main.cpp | 2 +- src/modules/m_spanningtree/treeserver.cpp | 10 +++++----- src/modules/m_spanningtree/treeserver.h | 10 ++++++---- src/modules/m_spanningtree/treesocket2.cpp | 2 +- 6 files changed, 34 insertions(+), 16 deletions(-) (limited to 'src/modules/m_spanningtree/treeserver.cpp') diff --git a/include/modules/server.h b/include/modules/server.h index 259da868f..c758df364 100644 --- a/include/modules/server.h +++ b/include/modules/server.h @@ -19,6 +19,11 @@ #pragma once +#ifdef __GNUC__ +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + #include "event.h" namespace ServerProtocol @@ -61,10 +66,16 @@ class ServerProtocol::LinkEventListener */ virtual void OnServerLink(const Server* server) { } - /** Fired when a server splits - * @param server Server that split - */ - virtual void OnServerSplit(const Server* server) { } + /** Fired when a server splits + * @param server Server that split + * @param error Whether the server split because of an error. + */ + virtual void OnServerSplit(const Server* server, bool error) { OnServerSplit(server); } + + /** Fired when a server splits + * @param server Server that split + */ + DEPRECATED_METHOD(virtual void OnServerSplit(const Server* server)) { } }; class ServerProtocol::MessageEventListener @@ -134,3 +145,8 @@ class ServerEventListener { } }; + +#ifdef __GNUC__ +# pragma GCC diagnostic pop +#endif + diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 28bce2bf3..9813ba6b5 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -59,7 +59,7 @@ class ServerTracker Update(server, true); } - void OnServerSplit(const Server* server) CXX11_OVERRIDE + void OnServerSplit(const Server* server, bool error) CXX11_OVERRIDE { Update(server, false); } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 2848ce940..3e992f39f 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -689,7 +689,7 @@ void ModuleSpanningTree::OnUnloadModule(Module* mod) { TreeServer* server = i->second; if (!server->IsRoot()) - FOREACH_MOD_CUSTOM(GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (server)); + FOREACH_MOD_CUSTOM(GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (server, false)); } return; } diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 2b143269c..c463ef1c8 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -172,7 +172,7 @@ void TreeServer::FinishBurst() FinishBurstInternal(); } -void TreeServer::SQuitChild(TreeServer* server, const std::string& reason) +void TreeServer::SQuitChild(TreeServer* server, const std::string& reason, bool error) { stdalgo::erase(Children, server); @@ -188,7 +188,7 @@ void TreeServer::SQuitChild(TreeServer* server, const std::string& reason) } unsigned int num_lost_servers = 0; - server->SQuitInternal(num_lost_servers); + server->SQuitInternal(num_lost_servers, error); const std::string quitreason = GetName() + " " + server->GetName(); unsigned int num_lost_users = QuitUsers(quitreason); @@ -204,14 +204,14 @@ void TreeServer::SQuitChild(TreeServer* server, const std::string& reason) ServerInstance->GlobalCulls.AddItem(server); } -void TreeServer::SQuitInternal(unsigned int& num_lost_servers) +void TreeServer::SQuitInternal(unsigned int& num_lost_servers, bool error) { ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Server %s lost in split", GetName().c_str()); for (ChildServers::const_iterator i = Children.begin(); i != Children.end(); ++i) { TreeServer* server = *i; - server->SQuitInternal(num_lost_servers); + server->SQuitInternal(num_lost_servers, error); } // Mark server as dead @@ -220,7 +220,7 @@ void TreeServer::SQuitInternal(unsigned int& num_lost_servers) RemoveHash(); if (!Utils->Creator->dying) - FOREACH_MOD_CUSTOM(Utils->Creator->GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (this)); + FOREACH_MOD_CUSTOM(Utils->Creator->GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerSplit, (this, error)); } unsigned int TreeServer::QuitUsers(const std::string& reason) diff --git a/src/modules/m_spanningtree/treeserver.h b/src/modules/m_spanningtree/treeserver.h index 90841d0b4..14413cd92 100644 --- a/src/modules/m_spanningtree/treeserver.h +++ b/src/modules/m_spanningtree/treeserver.h @@ -74,7 +74,7 @@ class TreeServer : public Server /** Used by SQuit logic to recursively remove servers */ - void SQuitInternal(unsigned int& num_lost_servers); + void SQuitInternal(unsigned int& num_lost_servers, bool error); /** Remove the reference to this server from the hash maps */ @@ -103,15 +103,17 @@ class TreeServer : public Server /** SQuit a server connected to this server, removing the given server and all servers behind it * @param server Server to squit, must be directly below this server * @param reason Reason for quitting the server, sent to opers and other servers + * @param error Whether the server is being squit because of an error. */ - void SQuitChild(TreeServer* server, const std::string& reason); + void SQuitChild(TreeServer* server, const std::string& reason, bool error = false); /** SQuit this server, removing this server and all servers behind it * @param reason Reason for quitting the server, sent to opers and other servers + * @param error Whether the server is being squit because of an error. */ - void SQuit(const std::string& reason) + void SQuit(const std::string& reason, bool error = false) { - GetParent()->SQuitChild(this, reason); + GetParent()->SQuitChild(this, reason, error); } static unsigned int QuitUsers(const std::string& reason); diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 966d624bb..13ede628a 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -415,7 +415,7 @@ void TreeSocket::Close() // If the connection is fully up (state CONNECTED) // then propogate a netsplit to all peers. if (MyRoot) - MyRoot->SQuit(getError()); + MyRoot->SQuit(getError(), true); ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\002%s\002' failed.", linkID.c_str()); -- cgit v1.3.1-10-gc9f91 From 65f74be719bf249f4bc93e09670ee07410ecec96 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 23 Sep 2019 12:44:42 +0100 Subject: Add the OnServerBurst hook and fix the docs for OnServerLink. --- include/modules/server.h | 9 +++++++-- src/modules/m_spanningtree/treeserver.cpp | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/modules/m_spanningtree/treeserver.cpp') diff --git a/include/modules/server.h b/include/modules/server.h index c758df364..4e02efd19 100644 --- a/include/modules/server.h +++ b/include/modules/server.h @@ -61,11 +61,16 @@ class ServerProtocol::LinkEventListener { } - /** Fired when a server finishes burst - * @param server Server that recently linked and finished burst + /** Fired when a server has linked to the network. + * @param server Server that recently linked. */ virtual void OnServerLink(const Server* server) { } + /** Fired when a server has finished bursting. + * @param server Server that recently finished bursting. + */ + virtual void OnServerBurst(const Server* server) { } + /** Fired when a server splits * @param server Server that split * @param error Whether the server split because of an error. diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index c463ef1c8..6fb6705ba 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -167,6 +167,7 @@ void TreeServer::FinishBurst() unsigned long bursttime = ts - this->StartBurst; ServerInstance->SNO->WriteToSnoMask(Parent == Utils->TreeRoot ? 'l' : 'L', "Received end of netburst from \002%s\002 (burst time: %lu %s)", GetName().c_str(), (bursttime > 10000 ? bursttime / 1000 : bursttime), (bursttime > 10000 ? "secs" : "msecs")); + FOREACH_MOD_CUSTOM(Utils->Creator->GetLinkEventProvider(), ServerProtocol::LinkEventListener, OnServerBurst, (this)); StartBurst = 0; FinishBurstInternal(); -- cgit v1.3.1-10-gc9f91 From 32d96016bd21fd5dff54503df4222c10662e57e5 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 30 Sep 2019 10:19:29 +0100 Subject: Fix an shadowing warning in the spanningtree module. --- src/modules/m_spanningtree/treeserver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modules/m_spanningtree/treeserver.cpp') diff --git a/src/modules/m_spanningtree/treeserver.cpp b/src/modules/m_spanningtree/treeserver.cpp index 6fb6705ba..91bac36f9 100644 --- a/src/modules/m_spanningtree/treeserver.cpp +++ b/src/modules/m_spanningtree/treeserver.cpp @@ -56,8 +56,8 @@ TreeServer::TreeServer() * This constructor initializes the server's Route and Parent, and sets up * the ping timer for the server. */ -TreeServer::TreeServer(const std::string& Name, const std::string& Desc, const std::string& id, TreeServer* Above, TreeSocket* Sock, bool Hide) - : Server(id, Name, Desc) +TreeServer::TreeServer(const std::string& Name, const std::string& Desc, const std::string& Sid, TreeServer* Above, TreeSocket* Sock, bool Hide) + : Server(Sid, Name, Desc) , Parent(Above) , Socket(Sock) , behind_bursting(Parent->behind_bursting) -- cgit v1.3.1-10-gc9f91