1
0
mirror of https://github.com/anope/anope.git synced 2026-07-01 12:26:39 +02:00

Fixed some issues with reconnecting if we disconnect from the uplink

This commit is contained in:
Adam
2010-08-01 20:05:52 -04:00
parent e8d6524411
commit 90976b6672
9 changed files with 53 additions and 34 deletions
+6 -2
View File
@@ -86,7 +86,7 @@ class CoreExport Server : public Flags<ServerFlag>
/* Server ID */
Anope::string SID;
/* Links for this server */
std::list<Server *> Links;
std::vector<Server *> Links;
/* Uplink for this server */
Server *UplinkServer;
@@ -140,7 +140,7 @@ class CoreExport Server : public Flags<ServerFlag>
/** Get the list of links this server has, or NULL if it has none
* @return A list of servers
*/
const std::list<Server *> &GetLinks() const;
const std::vector<Server *> &GetLinks() const;
/** Get the uplink server for this server, if this is our uplink will be Me
* @return The servers uplink
@@ -157,6 +157,10 @@ class CoreExport Server : public Flags<ServerFlag>
*/
void DelLink(Server *s);
/** Remove all links from this server
*/
void ClearLinks();
/** Finish syncing this server and optionally all links to it
* @param SyncLinks True to sync the links for this server too (if any)
*/
+1 -1
View File
@@ -28,7 +28,7 @@ class CommandOSJupe : public Command
if (!isValidHost(jserver, 3))
notice_lang(Config.s_OperServ, u, OPER_JUPE_HOST_ERROR);
else if (server && (server == Me || server == Me->GetUplink()))
else if (server && (server == Me || server == Me->GetLinks().front()))
notice_lang(Config.s_OperServ, u, OPER_JUPE_INVALID_SERVER);
else
{
+4 -4
View File
@@ -28,8 +28,8 @@ static int stats_count_servers(Server *s)
int count = 1;
if (!s->GetLinks().empty())
for (std::list<Server *>::const_iterator it = s->GetLinks().begin(), it_end = s->GetLinks().end(); it != it_end; ++it)
count += stats_count_servers(*it);
for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
count += stats_count_servers(s->GetLinks()[i]);
return count;
}
@@ -209,9 +209,9 @@ class CommandOSStats : public Command
if (!buf.empty())
buf.erase(buf.begin());
notice_lang(Config.s_OperServ, u, OPER_STATS_UPLINK_SERVER, Me->GetUplink()->GetName().c_str());
notice_lang(Config.s_OperServ, u, OPER_STATS_UPLINK_SERVER, Me->GetLinks().front()->GetName().c_str());
notice_lang(Config.s_OperServ, u, OPER_STATS_UPLINK_CAPAB, buf.c_str());
notice_lang(Config.s_OperServ, u, OPER_STATS_UPLINK_SERVER_COUNT, stats_count_servers(Me->GetUplink()));
notice_lang(Config.s_OperServ, u, OPER_STATS_UPLINK_SERVER_COUNT, stats_count_servers(Me->GetLinks().front()));
return MOD_CONT;
}
+1 -1
View File
@@ -700,7 +700,7 @@ int anope_event_burst(const Anope::string &source, int ac, const char **av)
* server finished bursting. -GD
*/
if (!s)
s = Me->GetUplink();
s = Me->GetLinks().front();
if (s)
s->Sync(true);
}
+1 -1
View File
@@ -1036,7 +1036,7 @@ int anope_event_capab(const Anope::string &source, int ac, const char **av)
int anope_event_endburst(const Anope::string &source, int ac, const char **av)
{
Me->GetUplink()->Sync(true);
Me->GetLinks().front()->Sync(true);
return MOD_CONT;
}
+1 -1
View File
@@ -49,7 +49,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
BotListByUID[this->uid] = this;
// If we're synchronised with the uplink already, call introduce_user() for this bot.
if (Me && Me->GetUplink() && Me->GetUplink()->IsSynced())
if (Me && !Me->GetLinks().empty() && Me->GetLinks().front()->IsSynced())
{
ircdproto->SendClientIntroduction(this->nick, this->GetIdent(), this->host, this->realname, ircd->pseudoclient_mode, this->uid);
XLine x(this->nick, "Reserved for services");
+14 -2
View File
@@ -116,8 +116,6 @@ class UplinkSocket : public ClientSocket
~UplinkSocket()
{
/* Process the last bits of data before disconnecting */
SocketEngine->Process();
UplinkSock = NULL;
}
@@ -188,6 +186,7 @@ void do_restart_services()
UserListByUID.erase(it->second->GetUID());
}
ircdproto->SendSquit(Config.ServerName, quitmsg);
SocketEngine->Process();
delete UplinkSock;
close_log();
/* First don't unload protocol module, then do so */
@@ -236,6 +235,7 @@ static void services_shutdown()
while (!UserListByNick.empty())
delete UserListByNick.begin()->second;
}
SocketEngine->Process();
delete UplinkSock;
FOREACH_MOD(I_OnShutdown, OnShutdown());
/* First don't unload protocol module, then do so */
@@ -553,6 +553,18 @@ int main(int ac, char **av, char **envp)
delete u;
}
/* Nuke all channels */
for (channel_map::const_iterator it = ChannelList.begin(); it != ChannelList.end();)
{
Channel *c = it->second;
++it;
delete c;
}
Me->SetFlag(SERVER_SYNCING);
Me->ClearLinks();
unsigned j = 0;
for (; j < (Config.MaxRetries ? Config.MaxRetries : j + 1); ++j)
{
+4 -4
View File
@@ -130,8 +130,8 @@ void server_global(const Server *s, const Anope::string &message)
if (!s->GetLinks().empty())
{
for (std::list<Server *>::const_iterator it = s->GetLinks().begin(), it_end = s->GetLinks().end(); it != it_end; ++it)
server_global(*it, message);
for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
server_global(s->GetLinks()[i], message);
}
}
@@ -147,10 +147,10 @@ void oper_global(const Anope::string &nick, const char *fmt, ...)
if (!nick.empty() && !Config.AnonymousGlobal)
{
Anope::string rmsg = "[" + nick + "] " + msg;
server_global(Me->GetUplink(), rmsg);
server_global(Me->GetLinks().front(), rmsg);
}
else
server_global(Me->GetUplink(), msg);
server_global(Me->GetLinks().front(), msg);
}
/**************************************************************************/
+21 -18
View File
@@ -114,7 +114,7 @@ Server::~Server()
if (this->UplinkServer)
this->UplinkServer->DelLink(this);
for (std::list<Server *>::iterator it = this->Links.begin(), it_end = this->Links.end(); it != it_end; ++it)
for (std::vector<Server *>::iterator it = this->Links.begin(), it_end = this->Links.end(); it != it_end; ++it)
delete *it;
}
@@ -170,7 +170,7 @@ const Anope::string &Server::GetSID() const
/** Get the list of links this server has, or NULL if it has none
* @return A list of servers
*/
const std::list<Server*> &Server::GetLinks() const
const std::vector<Server *> &Server::GetLinks() const
{
return this->Links;
}
@@ -188,12 +188,6 @@ Server *Server::GetUplink()
*/
void Server::AddLink(Server *s)
{
/* This is only used for Me, initially we start services with an uplink of NULL, then
* connect to the server which introduces itself and has us as the uplink, which calls this
*/
if (this == Me && !this->UplinkServer)
this->UplinkServer = s;
this->Links.push_back(s);
Alog() << "Server " << s->GetName() << " introduced from " << this->GetName();
@@ -207,11 +201,11 @@ void Server::DelLink(Server *s)
if (this->Links.empty())
throw CoreException("Server::DelLink called on " + this->GetName() + " for " + s->GetName() + " but we have no links?");
for (std::list<Server *>::iterator it = this->Links.begin(), it_end = this->Links.end(); it != it_end; ++it)
for (unsigned i = 0, j = this->Links.size(); i < j; ++i)
{
if (*it == s)
if (this->Links[i] == s)
{
this->Links.erase(it);
this->Links.erase(this->Links.begin() + i);
break;
}
}
@@ -219,6 +213,15 @@ void Server::DelLink(Server *s)
Alog() << "Server " << s->GetName() << " quit from " << this->GetName();
}
/** Remov all links from this server
*/
void Server::ClearLinks()
{
for (unsigned i = 0, j = this->Links.size(); i < j; ++i)
delete this->Links[i];
this->Links.clear();
}
/** Finish syncing this server and optionally all links to it
* @param SyncLinks True to sync the links for this server too (if any)
*/
@@ -231,11 +234,11 @@ void Server::Sync(bool SyncLinks)
if (SyncLinks && !this->Links.empty())
{
for (std::list<Server *>::iterator it = this->Links.begin(), it_end = this->Links.end(); it != it_end; ++it)
(*it)->Sync(true);
for (unsigned i = 0, j = this->Links.size(); i < j; ++i)
this->Links[i]->Sync(true);
}
if (this == Me->GetUplink())
if (this == Me->GetLinks().front())
{
FOREACH_MOD(I_OnPreUplinkSync, OnPreUplinkSync(this));
ircdproto->SendEOB();
@@ -246,7 +249,7 @@ void Server::Sync(bool SyncLinks)
FOREACH_MOD(I_OnServerSync, OnServerSync(this));
if (this == Me->GetUplink())
if (this == Me->GetLinks().front())
{
FOREACH_MOD(I_OnUplinkSync, OnUplinkSync(this));
restore_unsynced_topics();
@@ -288,9 +291,9 @@ Server *Server::Find(const Anope::string &name, Server *s)
if (!s->GetLinks().empty())
{
for (std::list<Server *>::const_iterator it = s->GetLinks().begin(), it_end = s->GetLinks().end(); it != it_end; ++it)
for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
{
Server *serv = *it;
Server *serv = s->GetLinks()[i];
if (serv->GetName().equals_cs(name) || serv->GetSID().equals_cs(name))
return serv;
@@ -378,7 +381,7 @@ void do_squit(const Anope::string &source, int ac, const char **av)
buf = s->GetName() + " " + s->GetUplink()->GetName();
if (s->GetUplink() == Me->GetUplink() && Capab.HasFlag(CAPAB_UNCONNECT))
if (s->GetUplink() == Me && Capab.HasFlag(CAPAB_UNCONNECT))
{
Alog(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName();
/* need to fix */