diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 1 | ||||
-rw-r--r-- | src/uplink.cpp | 42 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index ca67ec56e..34f2a2797 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -145,6 +145,7 @@ int main(int ac, char **av, char **envp) /* Set up timers */ time_t last_check = Anope::CurTime; ExpireTimer expireTimer(Config->GetBlock("options")->Get<time_t>("expiretimeout", "30m")); + Uplink::PingTimer pingTimer(30); /*** Main loop. ***/ while (!Anope::Quitting) 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;) { |