aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-01-20 15:43:11 +0300
committerlevlam <levlam@telegram.org>2026-01-20 15:43:11 +0300
commit7a0e70b161bade9fa35a515abd5a76b7210ff0d3 (patch)
treefe3945a116eb01a759d0fe29517e92d479021cae
parent6e15f5bb5070bee28d9cc5e858265557cfc4b162 (diff)
Pass proxy to addProxy, editProxy and testProxy.
-rw-r--r--benchmark/check_proxy.cpp6
-rw-r--r--td/generate/scheme/td_api.tl18
-rw-r--r--td/telegram/Requests.cpp14
-rw-r--r--td/telegram/Requests.h2
-rw-r--r--td/telegram/cli.cpp16
-rw-r--r--td/telegram/net/ConnectionCreator.cpp5
-rw-r--r--td/telegram/net/ConnectionCreator.h3
-rw-r--r--td/telegram/net/Proxy.cpp5
-rw-r--r--td/telegram/net/Proxy.h4
9 files changed, 34 insertions, 39 deletions
diff --git a/benchmark/check_proxy.cpp b/benchmark/check_proxy.cpp
index 50d04a22e..b75d2cfcf 100644
--- a/benchmark/check_proxy.cpp
+++ b/benchmark/check_proxy.cpp
@@ -94,9 +94,9 @@ int main(int argc, char **argv) {
usage();
}
- requests.emplace_back(arg,
- td::td_api::make_object<td::td_api::testProxy>(
- server, port, td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret), -1, -1));
+ auto proxy_type = td::td_api::make_object<td::td_api::proxyTypeMtproto>(secret);
+ auto proxy = td::td_api::make_object<td::td_api::proxy>(server, port, std::move(proxy_type));
+ requests.emplace_back(arg, td::td_api::make_object<td::td_api::testProxy>(std::move(proxy), -1, -1));
};
td::int32 dc_id = 2;
diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl
index 3c191eb23..cf7f7497d 100644
--- a/td/generate/scheme/td_api.tl
+++ b/td/generate/scheme/td_api.tl
@@ -14771,19 +14771,15 @@ getApplicationDownloadLink = HttpUrl;
//@description Adds a proxy server for network requests. Can be called before authorization
-//@server Proxy server domain or IP address
-//@port Proxy server port
+//@proxy The proxy to add
//@enable Pass true to immediately enable the proxy
-//@type Proxy type
-addProxy server:string port:int32 enable:Bool type:ProxyType = AddedProxy;
+addProxy proxy:proxy enable:Bool = AddedProxy;
//@description Edits an existing proxy server for network requests. Can be called before authorization
//@proxy_id Proxy identifier
-//@server Proxy server domain or IP address
-//@port Proxy server port
+//@proxy The new information about the proxy
//@enable Pass true to immediately enable the proxy
-//@type Proxy type
-editProxy proxy_id:int32 server:string port:int32 enable:Bool type:ProxyType = AddedProxy;
+editProxy proxy_id:int32 proxy:proxy enable:Bool = AddedProxy;
//@description Enables a proxy. Only one proxy can be enabled at a time. Can be called before authorization @proxy_id Proxy identifier
enableProxy proxy_id:int32 = Ok;
@@ -14873,12 +14869,10 @@ testSquareInt x:int32 = TestInt;
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 domain or IP address
-//@port Proxy server port
-//@type Proxy type
+//@proxy The proxy to test
//@dc_id Identifier of a datacenter with which to test connection
//@timeout The maximum overall timeout for the request
-testProxy server:string port:int32 type:ProxyType dc_id:int32 timeout:double = Ok;
+testProxy proxy:proxy dc_id:int32 timeout:double = Ok;
//@description Forces an updates.getDifference call to the Telegram servers; for testing only
testGetDifference = Ok;
diff --git a/td/telegram/Requests.cpp b/td/telegram/Requests.cpp
index 84604635a..42bc93548 100644
--- a/td/telegram/Requests.cpp
+++ b/td/telegram/Requests.cpp
@@ -8778,20 +8778,18 @@ void Requests::on_request(uint64 id, td_api::saveApplicationLogEvent &request) {
}
void Requests::on_request(uint64 id, td_api::addProxy &request) {
- CLEAN_INPUT_STRING(request.server_);
CREATE_REQUEST_PROMISE();
- send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, -1, std::move(request.server_), request.port_,
- request.enable_, std::move(request.type_), std::move(promise));
+ send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, -1, std::move(request.proxy_), request.enable_,
+ std::move(promise));
}
void Requests::on_request(uint64 id, td_api::editProxy &request) {
if (request.proxy_id_ < 0) {
return send_error_raw(id, 400, "Proxy identifier invalid");
}
- CLEAN_INPUT_STRING(request.server_);
CREATE_REQUEST_PROMISE();
- send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, request.proxy_id_, std::move(request.server_),
- request.port_, request.enable_, std::move(request.type_), std::move(promise));
+ send_closure(G()->connection_creator(), &ConnectionCreator::add_proxy, request.proxy_id_, std::move(request.proxy_),
+ request.enable_, std::move(promise));
}
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) {
td_->country_info_manager_->get_current_country_code(std::move(query_promise));
}
-void Requests::on_request(uint64 id, td_api::testProxy &request) {
- auto r_proxy = Proxy::create_proxy(std::move(request.server_), request.port_, request.type_.get());
+void Requests::on_request(uint64 id, const td_api::testProxy &request) {
+ auto r_proxy = Proxy::create_proxy(request.proxy_.get());
if (r_proxy.is_error()) {
return send_closure(td_actor_, &Td::send_error, id, r_proxy.move_as_error());
}
diff --git a/td/telegram/Requests.h b/td/telegram/Requests.h
index 538fc2a65..9cf673018 100644
--- a/td/telegram/Requests.h
+++ b/td/telegram/Requests.h
@@ -1998,7 +1998,7 @@ class Requests {
void on_request(uint64 id, const td_api::testNetwork &request);
- void on_request(uint64 id, td_api::testProxy &request);
+ void on_request(uint64 id, const td_api::testProxy &request);
void on_request(uint64 id, const td_api::testGetDifference &request);
diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp
index 18615c93c..01bd130b3 100644
--- a/td/telegram/cli.cpp
+++ b/td/telegram/cli.cpp
@@ -2019,10 +2019,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setNetworkType>(td_api::make_object<td_api::networkTypeWiFi>()));
send_request(td_api::make_object<td_api::getNetworkStatistics>());
send_request(td_api::make_object<td_api::getCountryCode>());
- send_request(
- td_api::make_object<td_api::addProxy>("1.1.1.1", 1111, true, td_api::make_object<td_api::proxyTypeSocks5>()));
- send_request(td_api::make_object<td_api::addProxy>("1.1.1.1", 1112, false,
- td_api::make_object<td_api::proxyTypeSocks5>()));
+ send_request(td_api::make_object<td_api::addProxy>(
+ td_api::make_object<td_api::proxy>("1.1.1.1", 1111, td_api::make_object<td_api::proxyTypeSocks5>()), true));
+ send_request(td_api::make_object<td_api::addProxy>(
+ td_api::make_object<td_api::proxy>("1.1.1.1", 1112, td_api::make_object<td_api::proxyTypeSocks5>()), false));
send_request(td_api::make_object<td_api::pingProxy>(0));
auto bad_request = td_api::make_object<td_api::setTdlibParameters>();
@@ -8328,13 +8328,13 @@ class CliClient final : public Actor {
type = td_api::make_object<td_api::proxyTypeSocks5>(user, password);
}
}
+ auto proxy = td_api::make_object<td_api::proxy>(server, port, std::move(type));
if (op[0] == 'e') {
- send_request(
- td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), server, port, enable, std::move(type)));
+ send_request(td_api::make_object<td_api::editProxy>(as_proxy_id(proxy_id), std::move(proxy), enable));
} else if (op == "tproxy") {
- send_request(td_api::make_object<td_api::testProxy>(server, port, std::move(type), 2, 10.0));
+ send_request(td_api::make_object<td_api::testProxy>(std::move(proxy), 2, 10.0));
} else {
- send_request(td_api::make_object<td_api::addProxy>(server, port, enable, std::move(type)));
+ send_request(td_api::make_object<td_api::addProxy>(std::move(proxy), enable));
}
} else if (op == "gproxy" || op == "gproxies") {
send_request(td_api::make_object<td_api::getProxies>());
diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp
index 30c922e9b..6a48563e5 100644
--- a/td/telegram/net/ConnectionCreator.cpp
+++ b/td/telegram/net/ConnectionCreator.cpp
@@ -149,10 +149,9 @@ void ConnectionCreator::set_net_stats_callback(std::shared_ptr<NetStatsCallback>
media_net_stats_callback_ = std::move(media_callback);
}
-void ConnectionCreator::add_proxy(int32 old_proxy_id, string server, int32 port, bool enable,
- td_api::object_ptr<td_api::ProxyType> proxy_type,
+void ConnectionCreator::add_proxy(int32 old_proxy_id, td_api::object_ptr<td_api::proxy> proxy, bool enable,
Promise<td_api::object_ptr<td_api::addedProxy>> promise) {
- TRY_RESULT_PROMISE(promise, new_proxy, Proxy::create_proxy(std::move(server), port, proxy_type.get()));
+ TRY_RESULT_PROMISE(promise, new_proxy, Proxy::create_proxy(proxy.get()));
if (old_proxy_id >= 0) {
if (proxies_.count(old_proxy_id) == 0) {
return promise.set_error(400, "Proxy not found");
diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h
index ed45aef6d..ace5f0672 100644
--- a/td/telegram/net/ConnectionCreator.h
+++ b/td/telegram/net/ConnectionCreator.h
@@ -71,8 +71,7 @@ class ConnectionCreator final : public NetQueryCallback {
void set_net_stats_callback(std::shared_ptr<NetStatsCallback> common_callback,
std::shared_ptr<NetStatsCallback> media_callback);
- void add_proxy(int32 old_proxy_id, string server, int32 port, bool enable,
- td_api::object_ptr<td_api::ProxyType> proxy_type,
+ void add_proxy(int32 old_proxy_id, td_api::object_ptr<td_api::proxy> proxy, bool enable,
Promise<td_api::object_ptr<td_api::addedProxy>> promise);
void enable_proxy(int32 proxy_id, Promise<Unit> promise);
void disable_proxy(Promise<Unit> promise);
diff --git a/td/telegram/net/Proxy.cpp b/td/telegram/net/Proxy.cpp
index a22e87795..bb03fb48a 100644
--- a/td/telegram/net/Proxy.cpp
+++ b/td/telegram/net/Proxy.cpp
@@ -8,6 +8,8 @@
#include "td/telegram/td_api.h"
+#include "td/utils/utf8.h"
+
namespace td {
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
if (server.size() > 255) {
return Status::Error(400, "Server name is too long");
}
+ if (!check_utf8(server)) {
+ return Status::Error(400, "Server name must be encoded in UTF-8");
+ }
if (port <= 0 || port > 65535) {
return Status::Error(400, "Wrong port number");
}
diff --git a/td/telegram/net/Proxy.h b/td/telegram/net/Proxy.h
index dfcc0d8a3..293f4a740 100644
--- a/td/telegram/net/Proxy.h
+++ b/td/telegram/net/Proxy.h
@@ -31,8 +31,6 @@ class ProxyType;
class Proxy {
public:
- static Result<Proxy> create_proxy(string server, int port, const td_api::ProxyType *proxy_type);
-
static Result<Proxy> create_proxy(const td_api::proxy *proxy);
static Proxy socks5(string server, int32 port, string user, string password) {
@@ -160,6 +158,8 @@ class Proxy {
string user_;
string password_;
mtproto::ProxySecret secret_;
+
+ static Result<Proxy> create_proxy(string server, int port, const td_api::ProxyType *proxy_type);
};
inline bool operator==(const Proxy &lhs, const Proxy &rhs) {