Skip to content

Commit 7a0e70b

Browse files
committed
Pass proxy to addProxy, editProxy and testProxy.
1 parent 6e15f5b commit 7a0e70b

9 files changed

Lines changed: 34 additions & 39 deletions

File tree

benchmark/check_proxy.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ int main(int argc, char **argv) {
9494
usage();
9595
}
9696

97-
requests.emplace_back(arg,
98-
td::td_api::make_object<td::td_api::testProxy>(
99-
server, port, td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret), -1, -1));
97+
auto proxy_type = td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret);
98+
auto proxy = td::td_api::make_object<td::td_api::proxy>(server, port, std::move(proxy_type));
99+
requests.emplace_back(arg, td::td_api::make_object<td::td_api::testProxy>(std::move(proxy), -1, -1));
100100
};
101101

102102
td::int32 dc_id = 2;

td/generate/scheme/td_api.tl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14771,19 +14771,15 @@ getApplicationDownloadLink = HttpUrl;
1477114771

1477214772

1477314773
//@description Adds a proxy server for network requests. Can be called before authorization
14774-
//@server Proxy server domain or IP address
14775-
//@port Proxy server port
14774+
//@proxy The proxy to add
1477614775
//@enable Pass true to immediately enable the proxy
14777-
//@type Proxy type
14778-
addProxy server:string port:int32 enable:Bool type:ProxyType = AddedProxy;
14776+
addProxy proxy:proxy enable:Bool = AddedProxy;
1477914777

1478014778
//@description Edits an existing proxy server for network requests. Can be called before authorization
1478114779
//@proxy_id Proxy identifier
14782-
//@server Proxy server domain or IP address
14783-
//@port Proxy server port
14780+
//@proxy The new information about the proxy
1478414781
//@enable Pass true to immediately enable the proxy
14785-
//@type Proxy type
14786-
editProxy proxy_id:int32 server:string port:int32 enable:Bool type:ProxyType = AddedProxy;
14782+
editProxy proxy_id:int32 proxy:proxy enable:Bool = AddedProxy;
1478714783

1478814784
//@description Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization @proxy_id Proxy identifier
1478914785
enableProxy proxy_id:int32 = Ok;
@@ -14873,12 +14869,10 @@ testSquareInt x:int32 = TestInt;
1487314869
testNetwork = Ok;
1487414870

1487514871
//@description Sends a simple network request to the Telegram servers via proxy; for testing only. Can be called before authorization
14876-
//@server Proxy server domain or IP address
14877-
//@port Proxy server port
14878-
//@type Proxy type
14872+
//@proxy The proxy to test
1487914873
//@dc_id Identifier of a datacenter with which to test connection
1488014874
//@timeout The maximum overall timeout for the request
14881-
testProxy server:string port:int32 type:ProxyType dc_id:int32 timeout:double = Ok;
14875+
testProxy proxy:proxy dc_id:int32 timeout:double = Ok;
1488214876

1488314877
//@description Forces an updates.getDifference call to the Telegram servers; for testing only
1488414878
testGetDifference = Ok;

td/telegram/Requests.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8778,20 +8778,18 @@ void Requests::on_request(uint64 id, td_api::saveApplicationLogEvent &request) {
87788778
}
87798779

87808780
void Requests::on_request(uint64 id, td_api::addProxy &request) {
8781-
CLEAN_INPUT_STRING(request.server_);
87828781
CREATE_REQUEST_PROMISE();
8783-
send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, -1, std::move(request.server_), request.port_,
8784-
request.enable_, std::move(request.type_), std::move(promise));
8782+
send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, -1, std::move(request.proxy_), request.enable_,
8783+
std::move(promise));
87858784
}
87868785

87878786
void Requests::on_request(uint64 id, td_api::editProxy &request) {
87888787
if (request.proxy_id_ < 0) {
87898788
return send_error_raw(id, 400, "Proxy identifier invalid");
87908789
}
8791-
CLEAN_INPUT_STRING(request.server_);
87928790
CREATE_REQUEST_PROMISE();
8793-
send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, request.proxy_id_, std::move(request.server_),
8794-
request.port_, request.enable_, std::move(request.type_), std::move(promise));
8791+
send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, request.proxy_id_, std::move(request.proxy_),
8792+
request.enable_, std::move(promise));
87958793
}
87968794

87978795
void Requests::on_request(uint64 id, const td_api::enableProxy &request) {
@@ -8966,8 +8964,8 @@ void Requests::on_request(uint64 id, const td_api::testNetwork &request) {
89668964
td_->country_info_manager_->get_current_country_code(std::move(query_promise));
89678965
}
89688966

8969-
void Requests::on_request(uint64 id, td_api::testProxy &request) {
8970-
auto r_proxy = Proxy::create_proxy(std::move(request.server_), request.port_, request.type_.get());
8967+
void Requests::on_request(uint64 id, const td_api::testProxy &request) {
8968+
auto r_proxy = Proxy::create_proxy(request.proxy_.get());
89718969
if (r_proxy.is_error()) {
89728970
return send_closure(td_actor_, &Td::send_error, id, r_proxy.move_as_error());
89738971
}

td/telegram/Requests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,7 @@ class Requests {
19981998

19991999
void on_request(uint64 id, const td_api::testNetwork &request);
20002000

2001-
void on_request(uint64 id, td_api::testProxy &request);
2001+
void on_request(uint64 id, const td_api::testProxy &request);
20022002

20032003
void on_request(uint64 id, const td_api::testGetDifference &request);
20042004

td/telegram/cli.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,10 +2019,10 @@ class CliClient final : public Actor {
20192019
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeWiFi>()));
20202020
send_request(td_api::make_object<td_api::getNetworkStatistics>());
20212021
send_request(td_api::make_object<td_api::getCountryCode>());
2022-
send_request(
2023-
td_api::make_object<td_api::addProxy>("1.1.1.1", 1111, true, td_api::make_object<td_api::proxyTypeSocks5>()));
2024-
send_request(td_api::make_object<td_api::addProxy>("1.1.1.1", 1112, false,
2025-
td_api::make_object<td_api::proxyTypeSocks5>()));
2022+
send_request(td_api::make_object<td_api::addProxy>(
2023+
td_api::make_object<td_api::proxy>("1.1.1.1", 1111, td_api::make_object<td_api::proxyTypeSocks5>()), true));
2024+
send_request(td_api::make_object<td_api::addProxy>(
2025+
td_api::make_object<td_api::proxy>("1.1.1.1", 1112, td_api::make_object<td_api::proxyTypeSocks5>()), false));
20262026
send_request(td_api::make_object<td_api::pingProxy>(0));
20272027

20282028
auto bad_request = td_api::make_object<td_api::setTdlibParameters>();
@@ -8328,13 +8328,13 @@ class CliClient final : public Actor {
83288328
type = td_api::make_object<td_api::proxyTypeSocks5>(user, password);
83298329
}
83308330
}
8331+
auto proxy = td_api::make_object<td_api::proxy>(server, port, std::move(type));
83318332
if (op[0] == 'e') {
8332-
send_request(
8333-
td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), server, port, enable, std::move(type)));
8333+
send_request(td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), std::move(proxy), enable));
83348334
} else if (op == "tproxy") {
8335-
send_request(td_api::make_object<td_api::testProxy>(server, port, std::move(type), 2, 10.0));
8335+
send_request(td_api::make_object<td_api::testProxy>(std::move(proxy), 2, 10.0));
83368336
} else {
8337-
send_request(td_api::make_object<td_api::addProxy>(server, port, enable, std::move(type)));
8337+
send_request(td_api::make_object<td_api::addProxy>(std::move(proxy), enable));
83388338
}
83398339
} else if (op == "gproxy" || op == "gproxies") {
83408340
send_request(td_api::make_object<td_api::getProxies>());

td/telegram/net/ConnectionCreator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,9 @@ void ConnectionCreator::set_net_stats_callback(std::shared_ptr<NetStatsCallback>
149149
media_net_stats_callback_ = std::move(media_callback);
150150
}
151151

152-
void ConnectionCreator::add_proxy(int32 old_proxy_id, string server, int32 port, bool enable,
153-
td_api::object_ptr<td_api::ProxyType> proxy_type,
152+
void ConnectionCreator::add_proxy(int32 old_proxy_id, td_api::object_ptr<td_api::proxy> proxy, bool enable,
154153
Promise<td_api::object_ptr<td_api::addedProxy>> promise) {
155-
TRY_RESULT_PROMISE(promise, new_proxy, Proxy::create_proxy(std::move(server), port, proxy_type.get()));
154+
TRY_RESULT_PROMISE(promise, new_proxy, Proxy::create_proxy(proxy.get()));
156155
if (old_proxy_id >= 0) {
157156
if (proxies_.count(old_proxy_id) == 0) {
158157
return promise.set_error(400, "Proxy not found");

td/telegram/net/ConnectionCreator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ class ConnectionCreator final : public NetQueryCallback {
7171
void set_net_stats_callback(std::shared_ptr<NetStatsCallback> common_callback,
7272
std::shared_ptr<NetStatsCallback> media_callback);
7373

74-
void add_proxy(int32 old_proxy_id, string server, int32 port, bool enable,
75-
td_api::object_ptr<td_api::ProxyType> proxy_type,
74+
void add_proxy(int32 old_proxy_id, td_api::object_ptr<td_api::proxy> proxy, bool enable,
7675
Promise<td_api::object_ptr<td_api::addedProxy>> promise);
7776
void enable_proxy(int32 proxy_id, Promise<Unit> promise);
7877
void disable_proxy(Promise<Unit> promise);

td/telegram/net/Proxy.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "td/telegram/td_api.h"
1010

11+
#include "td/utils/utf8.h"
12+
1113
namespace td {
1214

1315
Result<Proxy> Proxy::create_proxy(string server, int port, const td_api::ProxyType *proxy_type) {
@@ -20,6 +22,9 @@ Result<Proxy> Proxy::create_proxy(string server, int port, const td_api::ProxyTy
2022
if (server.size() > 255) {
2123
return Status::Error(400, "Server name is too long");
2224
}
25+
if (!check_utf8(server)) {
26+
return Status::Error(400, "Server name must be encoded in UTF-8");
27+
}
2328
if (port <= 0 || port > 65535) {
2429
return Status::Error(400, "Wrong port number");
2530
}

td/telegram/net/Proxy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class ProxyType;
3131

3232
class Proxy {
3333
public:
34-
static Result<Proxy> create_proxy(string server, int port, const td_api::ProxyType *proxy_type);
35-
3634
static Result<Proxy> create_proxy(const td_api::proxy *proxy);
3735

3836
static Proxy socks5(string server, int32 port, string user, string password) {
@@ -160,6 +158,8 @@ class Proxy {
160158
string user_;
161159
string password_;
162160
mtproto::ProxySecret secret_;
161+
162+
static Result<Proxy> create_proxy(string server, int port, const td_api::ProxyType *proxy_type);
163163
};
164164

165165
inline bool operator==(const Proxy &lhs, const Proxy &rhs) {

0 commit comments

Comments
 (0)