diff options
author | Adam <Adam@anope.org> | 2017-06-22 17:59:58 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2017-06-22 17:59:58 -0400 |
commit | 2b6c5833bb6cd6b1e21bb66a0ebbc6a6e3e86767 (patch) | |
tree | 4f3b8b2dd11e2d80c62db732d0e803978ed440c8 /src/uplink.cpp | |
parent | 46acfd0490bee851ef82897fa6a7686f64b2544e (diff) |
Ping uplink occasionally and disconnect if no pong is received
Diffstat (limited to 'src/uplink.cpp')
-rw-r--r-- | src/uplink.cpp | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/uplink.cpp b/src/uplink.cpp index fb5f3ec23..bd069843c 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -42,11 +42,47 @@ class ReconnectTimer : public Timer } catch (const SocketException &ex) { - Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason()); + Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), + Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, + Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason()); } } }; +Uplink::PingTimer::PingTimer(time_t timeout) : Timer(timeout, Anope::CurTime, true) +{ +} + +void Uplink::PingTimer::Tick(time_t) +{ + Server *uplink; + time_t ping_time = Config->GetBlock("options")->Get<time_t>("ping_time", "60"); + + if (!UplinkSock || Anope::CurTime - UplinkSock->last_read <= ping_time) + return; + + if (Me->GetLinks().empty()) + return; + + if (UplinkSock->pinged) + { + Anope::Logger.Log(_("No response from uplink in {0} seconds, disconnecting"), ping_time); + + UplinkSock->error = true; + Anope::QuitReason = "Ping timeout"; + delete UplinkSock; + Anope::QuitReason.clear(); + return; + } + + Anope::Logger.Debug("Pinging uplink"); + + uplink = Me->GetLinks().front(); + UplinkSock->pinged = true; + + IRCD->Send<messages::Ping>(Me->GetName(), uplink->GetName()); +} + void Uplink::Connect() { if (Config->Uplinks.empty()) @@ -71,7 +107,6 @@ void Uplink::Connect() UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].ipv6), ConnectionSocket(), BufferedSocket() { - error = false; UplinkSock = this; } @@ -142,6 +177,9 @@ UplinkSocket::~UplinkSocket() bool UplinkSocket::ProcessRead() { + last_read = Anope::CurTime; + pinged = false; + bool b = BufferedSocket::ProcessRead(); for (Anope::string buf; (buf = this->GetLine()).empty() == false;) { |