Delay subsequent requests to the same host

PR #19801.
Closes #8350.
This commit is contained in:
jNullj
2024-01-19 19:38:16 +02:00
committed by GitHub
parent 8ec3db1807
commit c5d7b62473
13 changed files with 98 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2024 Jonathan Ketchker
* Copyright (C) 2015-2024 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
@@ -49,6 +50,8 @@
#include "downloadhandlerimpl.h"
#include "proxyconfigurationmanager.h"
using namespace std::chrono_literals;
namespace
{
// Disguise as Firefox to avoid web server banning
@@ -188,9 +191,9 @@ Net::DownloadHandler *Net::DownloadManager::download(const DownloadRequest &down
return downloadHandler;
}
void Net::DownloadManager::registerSequentialService(const Net::ServiceID &serviceID)
void Net::DownloadManager::registerSequentialService(const Net::ServiceID &serviceID, const std::chrono::seconds delay)
{
m_sequentialServices.insert(serviceID);
m_sequentialServices.insert(serviceID, delay);
}
QList<QNetworkCookie> Net::DownloadManager::cookiesForUrl(const QUrl &url) const
@@ -309,7 +312,7 @@ void Net::DownloadManager::processRequest(DownloadHandlerImpl *downloadHandler)
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, &QNetworkReply::finished, this, [this, serviceID = ServiceID::fromURL(downloadHandler->url())]
{
QTimer::singleShot(0, this, [this, serviceID] { processWaitingJobs(serviceID); });
QTimer::singleShot(m_sequentialServices.value(serviceID, 0s), this, [this, serviceID] { processWaitingJobs(serviceID); });
});
downloadHandler->assignNetworkReply(reply);
}