diff --git a/benchmark/check_proxy.cpp b/benchmark/check_proxy.cpp index 686f43d15..617180d6c 100644 --- a/benchmark/check_proxy.cpp +++ b/benchmark/check_proxy.cpp @@ -17,6 +17,10 @@ static void usage() { td::TsCerr() << "Tests specified MTProto-proxy; exits with code 0 on success.\n"; td::TsCerr() << "Usage:\n"; td::TsCerr() << "check_proxy [-v] [-h] server:port:secret\n"; + td::TsCerr() << " -v\tSet verbosity level to N\n"; + td::TsCerr() << " -h/--help\tDisplay this information\n"; + td::TsCerr() << " -d/--dc-id\tIdentifier of a datacenter, to which try to connect (default is 2)\n"; + td::TsCerr() << " -t/--timeout\tMaximum overall timeout for the request (default is 10 seconds)\n"; std::exit(2); } @@ -26,10 +30,13 @@ int main(int argc, char **argv) { td::int32 port = 0; td::string secret; + td::int32 dc_id = 2; + double timeout = 10.0; + for (int i = 1; i < argc; i++) { td::string arg(argv[i]); if (arg.substr(0, 2) == "-v") { - if (arg.size() == 2 && i + 1 < argc) { + if (arg.size() == 2 && i + 1 < argc && argv[i + 1][0] != '-') { arg = argv[++i]; } else { arg = arg.substr(2); @@ -43,7 +50,19 @@ int main(int argc, char **argv) { new_verbosity += td::to_integer(arg) - (new_verbosity == 1); } new_verbosity_level = VERBOSITY_NAME(FATAL) + new_verbosity; - } else if (arg == "-h" || arg == "--help") { + } else if (arg == "-t" || arg == "--timeout") { + if (i + 1 == argc) { + td::TsCerr() << "Value is required after " << arg; + usage(); + } + timeout = td::to_double(std::string(argv[++i])); + } else if (arg == "-d" || arg == "--dc_id") { + if (i + 1 == argc) { + td::TsCerr() << "Value is required after " << arg; + usage(); + } + dc_id = td::to_integer(std::string(argv[++i])); + } else if (arg[0] == '-') { usage(); } else { auto secret_pos = arg.rfind(':'); @@ -76,7 +95,7 @@ int main(int argc, char **argv) { td::Client client; client.send({1, td::td_api::make_object( - server, port, td::td_api::make_object(secret))}); + server, port, td::td_api::make_object(secret), dc_id, timeout)}); while (true) { auto response = client.receive(100.0); if (response.id == 1) { diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1ef5a6bda..01d300015 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4040,7 +4040,8 @@ testSquareInt x:int32 = TestInt; //@description Sends a simple network request to the Telegram servers; for testing only. Can be called before authorization testNetwork = Ok; //@description Sends a simple network request to the Telegram servers via proxy; for testing only. Can be called before authorization @server Proxy server IP address @port Proxy server port @type Proxy type -testProxy server:string port:int32 type:ProxyType = Ok; +//@dc_id Identifier of a datacenter, with which to test connection @timeout Maximum overall timeout for the request +testProxy server:string port:int32 type:ProxyType dc_id:int32 timeout:double = Ok; //@description Forces an updates.getDifference call to the Telegram servers; for testing only testGetDifference = Ok; //@description Does nothing and ensures that the Update object is used; for testing only. This is an offline method. Can be called before authorization diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 20567404c..eccaab84e 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e4aeebf1e..e9eee19b0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -552,7 +552,8 @@ class TestQuery : public Td::ResultHandler { }; class TestProxyRequest : public RequestOnceActor { - int16 dc_id_ = 2; + int16 dc_id_; + double timeout_; Proxy proxy_; ActorOwn<> child_; Promise<> promise_; @@ -562,6 +563,8 @@ class TestProxyRequest : public RequestOnceActor { } void do_run(Promise &&promise) override { + set_timeout_in(timeout_); + promise_ = std::move(promise); IPAddress ip; auto status = ip.init_host_port(proxy_.server(), proxy_.port()); @@ -641,9 +644,17 @@ class TestProxyRequest : public RequestOnceActor { promise_.set_value(Unit()); } + void timeout_expired() override { + send_error(Status::Error(400, "Timeout expired")); + stop(); + } + public: - TestProxyRequest(ActorShared td, uint64 request_id, Proxy proxy) - : RequestOnceActor(std::move(td), request_id), proxy_(std::move(proxy)) { + TestProxyRequest(ActorShared td, uint64 request_id, Proxy proxy, int32 dc_id, double timeout) + : RequestOnceActor(std::move(td), request_id) + , proxy_(std::move(proxy)) + , dc_id_(static_cast(dc_id)) + , timeout_(timeout) { } }; @@ -7707,7 +7718,7 @@ void Td::on_request(uint64 id, td_api::testProxy &request) { if (r_proxy.is_error()) { return send_closure(actor_id(this), &Td::send_error, id, r_proxy.move_as_error()); } - CREATE_REQUEST(TestProxyRequest, r_proxy.move_as_ok()); + CREATE_REQUEST(TestProxyRequest, r_proxy.move_as_ok(), request.dc_id_, request.timeout_); } void Td::on_request(uint64 id, const td_api::testGetDifference &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 6c253706e..b11af476b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3646,7 +3646,7 @@ class CliClient final : public Actor { send_request( td_api::make_object(as_proxy_id(proxy_id), server, port_int, enable, std::move(type))); } else if (op == "tproxy") { - send_request(td_api::make_object(server, port_int, std::move(type))); + send_request(td_api::make_object(server, port_int, std::move(type), 2, 10.0)); } else { send_request(td_api::make_object(server, port_int, enable, std::move(type))); }