aboutsummaryrefslogtreecommitdiffhomepage
path: root/td/telegram/net/ConnectionCreator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'td/telegram/net/ConnectionCreator.cpp')
-rw-r--r--td/telegram/net/ConnectionCreator.cpp132
1 files changed, 0 insertions, 132 deletions
diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp
index 66010b278..f029b7b32 100644
--- a/td/telegram/net/ConnectionCreator.cpp
+++ b/td/telegram/net/ConnectionCreator.cpp
@@ -371,138 +371,6 @@ void ConnectionCreator::ping_proxy_buffered_socket_fd(IPAddress ip_address, Buff
create_reference(token))};
}
-void ConnectionCreator::test_proxy(Proxy &&proxy, int32 dc_id, double timeout, Promise<Unit> &&promise) {
- auto start_time = Time::now();
-
- IPAddress ip_address;
- auto status = ip_address.init_host_port(proxy.server(), proxy.port());
- if (status.is_error()) {
- return promise.set_error(400, status.public_message());
- }
- auto r_socket_fd = SocketFd::open(ip_address);
- if (r_socket_fd.is_error()) {
- return promise.set_error(400, r_socket_fd.error().public_message());
- }
-
- auto dc_options = get_default_dc_options(false);
- IPAddress mtproto_ip_address;
- for (auto &dc_option : dc_options.dc_options) {
- if (dc_option.get_dc_id().get_raw_id() == dc_id) {
- mtproto_ip_address = dc_option.get_ip_address();
- break;
- }
- }
- if (!mtproto_ip_address.is_valid()) {
- return promise.set_error(400, "Invalid datacenter identifier specified");
- }
-
- auto request_id = ++test_proxy_request_id_;
- auto request = make_unique<TestProxyRequest>();
- request->proxy_ = std::move(proxy);
- request->dc_id_ = static_cast<int16>(dc_id);
- request->promise_ = std::move(promise);
-
- auto connection_promise =
- PromiseCreator::lambda([actor_id = actor_id(this), request_id](Result<ConnectionData> r_data) {
- send_closure(actor_id, &ConnectionCreator::on_test_proxy_connection_data, request_id, std::move(r_data));
- });
- request->child_ = prepare_connection(ip_address, r_socket_fd.move_as_ok(), request->proxy_, mtproto_ip_address,
- request->get_transport(), "Test", "TestPingDC2", nullptr, {}, false,
- std::move(connection_promise));
-
- test_proxy_requests_.emplace(request_id, std::move(request));
-
- create_actor<SleepActor>("TestProxyTimeoutActor", timeout + start_time - Time::now(),
- PromiseCreator::lambda([actor_id = actor_id(this), request_id](Unit) {
- send_closure(actor_id, &ConnectionCreator::on_test_proxy_timeout, request_id);
- }))
- .release();
-}
-
-void ConnectionCreator::on_test_proxy_connection_data(uint64 request_id, Result<ConnectionData> r_data) {
- auto it = test_proxy_requests_.find(request_id);
- if (it == test_proxy_requests_.end()) {
- return;
- }
- auto *request = it->second.get();
- if (r_data.is_error()) {
- auto promise = std::move(request->promise_);
- test_proxy_requests_.erase(it);
- return promise.set_error(r_data.move_as_error());
- }
-
- class HandshakeContext final : public mtproto::AuthKeyHandshakeContext {
- public:
- mtproto::DhCallback *get_dh_callback() final {
- return nullptr;
- }
- mtproto::PublicRsaKeyInterface *get_public_rsa_key_interface() final {
- return public_rsa_key_.get();
- }
-
- private:
- std::shared_ptr<mtproto::PublicRsaKeyInterface> public_rsa_key_ = PublicRsaKeySharedMain::create(false);
- };
- auto handshake = make_unique<mtproto::AuthKeyHandshake>(request->dc_id_, 3600);
- auto data = r_data.move_as_ok();
- auto raw_connection = mtproto::RawConnection::create(data.ip_address, std::move(data.buffered_socket_fd),
- request->get_transport(), nullptr);
- request->child_ = create_actor<mtproto::HandshakeActor>(
- "HandshakeActor", std::move(handshake), std::move(raw_connection), make_unique<HandshakeContext>(), 10.0,
- PromiseCreator::lambda(
- [actor_id = actor_id(this), request_id](Result<unique_ptr<mtproto::RawConnection>> raw_connection) {
- send_closure(actor_id, &ConnectionCreator::on_test_proxy_handshake_connection, request_id,
- std::move(raw_connection));
- }),
- PromiseCreator::lambda(
- [actor_id = actor_id(this), request_id](Result<unique_ptr<mtproto::AuthKeyHandshake>> handshake) {
- send_closure(actor_id, &ConnectionCreator::on_test_proxy_handshake, request_id, std::move(handshake));
- }));
-}
-
-void ConnectionCreator::on_test_proxy_handshake_connection(
- uint64 request_id, Result<unique_ptr<mtproto::RawConnection>> r_raw_connection) {
- if (r_raw_connection.is_error()) {
- auto it = test_proxy_requests_.find(request_id);
- if (it == test_proxy_requests_.end()) {
- return;
- }
- auto promise = std::move(it->second->promise_);
- test_proxy_requests_.erase(it);
- return promise.set_error(400, r_raw_connection.move_as_error().public_message());
- }
-}
-
-void ConnectionCreator::on_test_proxy_handshake(uint64 request_id,
- Result<unique_ptr<mtproto::AuthKeyHandshake>> r_handshake) {
- auto it = test_proxy_requests_.find(request_id);
- if (it == test_proxy_requests_.end()) {
- return;
- }
- auto promise = std::move(it->second->promise_);
- test_proxy_requests_.erase(it);
-
- if (r_handshake.is_error()) {
- return promise.set_error(400, r_handshake.move_as_error().public_message());
- }
- auto handshake = r_handshake.move_as_ok();
- if (!handshake->is_ready_for_finish()) {
- return promise.set_error(400, "Handshake is not ready");
- }
- promise.set_value(Unit());
-}
-
-void ConnectionCreator::on_test_proxy_timeout(uint64 request_id) {
- auto it = test_proxy_requests_.find(request_id);
- if (it == test_proxy_requests_.end()) {
- return;
- }
- auto promise = std::move(it->second->promise_);
- test_proxy_requests_.erase(it);
-
- promise.set_error(400, "Timeout expired");
-}
-
void ConnectionCreator::set_active_proxy_id(int32 proxy_id, bool from_binlog) {
active_proxy_id_ = proxy_id;
if (proxy_id == 0) {