Add dc_id and timeout parameters to testProxy.
GitOrigin-RevId: 399efb78e2c82d8ef6f6b854f572e0a6b6a90336
This commit is contained in:
parent
5cca461115
commit
82892f577d
@ -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<N>] [-h] server:port:secret\n";
|
||||
td::TsCerr() << " -v<N>\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<int>(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<td::int32>(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<td::td_api::testProxy>(
|
||||
server, port, td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret))});
|
||||
server, port, td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret), dc_id, timeout)});
|
||||
while (true) {
|
||||
auto response = client.receive(100.0);
|
||||
if (response.id == 1) {
|
||||
|
@ -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
|
||||
|
Binary file not shown.
@ -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<Unit> &&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> td, uint64 request_id, Proxy proxy)
|
||||
: RequestOnceActor(std::move(td), request_id), proxy_(std::move(proxy)) {
|
||||
TestProxyRequest(ActorShared<Td> 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<int16>(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) {
|
||||
|
@ -3646,7 +3646,7 @@ class CliClient final : public Actor {
|
||||
send_request(
|
||||
td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), server, port_int, enable, std::move(type)));
|
||||
} else if (op == "tproxy") {
|
||||
send_request(td_api::make_object<td_api::testProxy>(server, port_int, std::move(type)));
|
||||
send_request(td_api::make_object<td_api::testProxy>(server, port_int, std::move(type), 2, 10.0));
|
||||
} else {
|
||||
send_request(td_api::make_object<td_api::addProxy>(server, port_int, enable, std::move(type)));
|
||||
}
|
||||
|
Reference in New Issue
Block a user