refactor: tr_web (#2633)

* refactor: fix tr_web rate limiting and dns caching
This commit is contained in:
Charles Kerr
2022-02-16 12:33:50 -06:00
committed by GitHub
parent 75e111e581
commit f1a53840f9
9 changed files with 736 additions and 600 deletions

View File

@@ -19,7 +19,7 @@
#include <libtransmission/variant.h>
#include <libtransmission/version.h>
#include <libtransmission/web-utils.h>
#include <libtransmission/web.h> /* tr_webRun */
#include <libtransmission/web.h> // tr_sessionFetch()
/***
****
@@ -124,16 +124,10 @@ static char* tr_strlratio(char* buf, double ratio, size_t buflen)
static bool waitingOnWeb;
static void onTorrentFileDownloaded(
tr_session* /*session*/,
bool /*did_connect*/,
bool /*did_timeout*/,
long /*response_code*/,
std::string_view response,
void* vctor)
static void onTorrentFileDownloaded(tr_web::FetchResponse&& response)
{
auto* ctor = static_cast<tr_ctor*>(vctor);
tr_ctorSetMetainfo(ctor, std::data(response), std::size(response), nullptr);
auto* ctor = static_cast<tr_ctor*>(response.user_data);
tr_ctorSetMetainfo(ctor, std::data(response.body), std::size(response.body), nullptr);
waitingOnWeb = false;
}
@@ -286,7 +280,7 @@ int tr_main(int argc, char* argv[])
else if (tr_urlIsValid(torrentPath))
{
// fetch it
tr_webRun(h, { torrentPath, onTorrentFileDownloaded, ctor });
tr_sessionFetch(h, { torrentPath, onTorrentFileDownloaded, ctor });
waitingOnWeb = true;
while (waitingOnWeb)
{