From 58ae98026be6b6e3faec748bdb35d04c09abed0d Mon Sep 17 00:00:00 2001 From: Vladimir Golovnev Date: Wed, 10 May 2023 15:02:15 +0300 Subject: [PATCH] Try to detect system wake-up event PR #18934. Closes #17898. --- src/base/bittorrent/sessionimpl.cpp | 15 +++++++++++++++ src/base/bittorrent/sessionimpl.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 80ee809ea..f23e43649 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -1470,6 +1470,21 @@ void SessionImpl::endStartup(ResumeSessionContext *context) m_resumeDataTimer->start(); } + m_wakeupCheckTimer = new QTimer(this); + connect(m_wakeupCheckTimer, &QTimer::timeout, this, [this] + { + const auto now = QDateTime::currentDateTime(); + if (m_wakeupCheckTimestamp.secsTo(now) > 100) + { + LogMsg(tr("System wake-up event detected. Re-announcing to all the trackers...")); + reannounceToAllTrackers(); + } + + m_wakeupCheckTimestamp = QDateTime::currentDateTime(); + }); + m_wakeupCheckTimestamp = QDateTime::currentDateTime(); + m_wakeupCheckTimer->start(30s); + m_isRestored = true; emit startupProgressUpdated(100); emit restored(); diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index 257437aa0..4b921c19c 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -773,6 +774,9 @@ namespace BitTorrent bool m_isPortMappingEnabled = false; QHash> m_mappedPorts; + QTimer *m_wakeupCheckTimer = nullptr; + QDateTime m_wakeupCheckTimestamp; + friend void Session::initInstance(); friend void Session::freeInstance(); friend Session *Session::instance();