diff --git a/benchmark/wget.cpp b/benchmark/wget.cpp index dba997e61..338e38572 100644 --- a/benchmark/wget.cpp +++ b/benchmark/wget.cpp @@ -10,6 +10,7 @@ #include "td/net/HttpQuery.h" #include "td/net/Wget.h" +#include "td/utils/common.h" #include "td/utils/logging.h" #include "td/utils/Status.h" @@ -21,6 +22,9 @@ int main(int argc, char *argv[]) { td::VERBOSITY_NAME(fd) = VERBOSITY_NAME(INFO); std::string url = (argc > 1 ? argv[1] : "https://telegram.org"); + auto timeout = 10; + auto ttl = 3; + auto prefer_ipv6 = (argc > 2 && std::string(argv[2]) == "-6"); auto scheduler = std::make_unique(); scheduler->init(0); scheduler @@ -28,7 +32,7 @@ int main(int argc, char *argv[]) { LOG(ERROR) << *res.ok(); td::Scheduler::instance()->finish(); }), - url) + url, td::Auto(), timeout, ttl, prefer_ipv6) .release(); scheduler->start(); while (scheduler->run_main(10)) { diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 699cc9a22..09701be56 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -109,11 +109,14 @@ Result decode_config(Slice input) { return std::move(config); } -static ActorOwn<> get_simple_config_impl(Promise promise, int32 scheduler_id, string url, string host) { +static ActorOwn<> get_simple_config_impl(Promise promise, int32 scheduler_id, string url, string host, + bool prefer_ipv6) { VLOG(config_recoverer) << "Request simple config from " << url; #if TD_EMSCRIPTEN // FIXME return ActorOwn<>(); #else + const int timeout = 10; + const int ttl = 3; return ActorOwn<>(create_actor_on_scheduler( "Wget", scheduler_id, PromiseCreator::lambda([promise = std::move(promise)](Result r_query) mutable { @@ -122,7 +125,7 @@ static ActorOwn<> get_simple_config_impl(Promise promise, int32 sc return decode_config(http_query->content_); }()); }), - std::move(url), std::vector>({{"Host", std::move(host)}}), 10 /*timeout*/, 3 /*ttl*/, + std::move(url), std::vector>({{"Host", std::move(host)}}), timeout, ttl, prefer_ipv6, SslFd::VerifyPeer::Off)); #endif } @@ -131,7 +134,8 @@ ActorOwn<> get_simple_config_azure(Promise promise, const ConfigSh int32 scheduler_id) { string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod") << "v2/config.txt"; - return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "tcdnb.azureedge.net"); + const bool prefer_ipv6 = shared_config->get_option_boolean("prefer_ipv6"); + return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "tcdnb.azureedge.net", prefer_ipv6); } ActorOwn<> get_simple_config_google_dns(Promise promise, const ConfigShared *shared_config, bool is_test, @@ -141,6 +145,9 @@ ActorOwn<> get_simple_config_google_dns(Promise promise, const Con return ActorOwn<>(); #else string name = shared_config == nullptr ? string() : shared_config->get_option_string("dc_txt_domain_name"); + const int timeout = 10; + const int ttl = 3; + const bool prefer_ipv6 = shared_config->get_option_boolean("prefer_ipv6"); if (name.empty()) { name = is_test ? "tapv2.stel.com" : "apv2.stel.com"; } @@ -178,7 +185,7 @@ ActorOwn<> get_simple_config_google_dns(Promise promise, const Con }()); }), PSTRING() << "https://www.google.com/resolve?name=" << url_encode(name) << "&type=16", - std::vector>({{"Host", "dns.google.com"}}), 10 /*timeout*/, 3 /*ttl*/, + std::vector>({{"Host", "dns.google.com"}}), timeout, ttl, prefer_ipv6, SslFd::VerifyPeer::Off)); #endif } diff --git a/tdnet/td/net/Wget.cpp b/tdnet/td/net/Wget.cpp index fb7f43c4e..d4ea27de8 100644 --- a/tdnet/td/net/Wget.cpp +++ b/tdnet/td/net/Wget.cpp @@ -23,12 +23,13 @@ namespace td { Wget::Wget(Promise promise, string url, std::vector> headers, int32 timeout_in, - int32 ttl, SslFd::VerifyPeer verify_peer) + int32 ttl, bool prefer_ipv6, SslFd::VerifyPeer verify_peer) : promise_(std::move(promise)) , input_url_(std::move(url)) , headers_(std::move(headers)) , timeout_in_(timeout_in) , ttl_(ttl) + , prefer_ipv6_(prefer_ipv6) , verify_peer_(verify_peer) { } @@ -61,7 +62,7 @@ Status Wget::try_init() { TRY_RESULT(header, hc.finish()); IPAddress addr; - TRY_STATUS(addr.init_host_port(url.host_, url.port_)); + TRY_STATUS(addr.init_host_port(url.host_, url.port_, prefer_ipv6_)); TRY_RESULT(fd, SocketFd::open(addr)); if (url.protocol_ == HttpUrl::Protocol::HTTP) { diff --git a/tdnet/td/net/Wget.h b/tdnet/td/net/Wget.h index cecb113c9..6c539ab28 100644 --- a/tdnet/td/net/Wget.h +++ b/tdnet/td/net/Wget.h @@ -22,7 +22,8 @@ namespace td { class Wget : public HttpOutboundConnection::Callback { public: explicit Wget(Promise promise, string url, std::vector> headers = {}, - int32 timeout_in = 10, int32 ttl = 3, SslFd::VerifyPeer verify_peer = SslFd::VerifyPeer::On); + int32 timeout_in = 10, int32 ttl = 3, bool prefer_ipv6 = false, + SslFd::VerifyPeer verify_peer = SslFd::VerifyPeer::On); private: Status try_init(); @@ -42,6 +43,7 @@ class Wget : public HttpOutboundConnection::Callback { std::vector> headers_; int32 timeout_in_; int32 ttl_; + bool prefer_ipv6_ = false; SslFd::VerifyPeer verify_peer_; };