From ff593d2ce855b0bd47b91916822a0ec976f744ca Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 6 Aug 2018 18:28:56 +0300 Subject: [PATCH] Properly fix resolving proxy IP. GitOrigin-RevId: cb385b8d0753da6f76dcdb237b2001143a23c94f --- td/telegram/net/ConnectionCreator.cpp | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 28782681..eb2acab2 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -718,12 +718,11 @@ void ConnectionCreator::on_network(bool network_flag, uint32 network_generation) auto old_generation = network_generation_; network_generation_ = network_generation; if (network_flag_) { - if (old_generation != network_generation_) { - VLOG(connections) << "Set proxy query token to 0: " << old_generation << " " << network_generation_; - resolve_proxy_query_token_ = 0; - resolve_proxy_timestamp_ = Timestamp(); - get_proxy_info_timestamp_ = Timestamp(); - } + VLOG(connections) << "Set proxy query token to 0: " << old_generation << " " << network_generation_; + resolve_proxy_query_token_ = 0; + resolve_proxy_timestamp_ = Timestamp(); + get_proxy_info_timestamp_ = Timestamp(); + for (auto &client : clients_) { client.second.backoff.clear(); client.second.flood_control.clear_events(); @@ -1300,6 +1299,9 @@ void ConnectionCreator::loop() { if (!is_inited_) { return; } + if (G()->close_flag()) { + return; + } if (!network_flag_) { return; } @@ -1344,14 +1346,14 @@ void ConnectionCreator::loop() { } void ConnectionCreator::on_result(NetQueryPtr query) { - if (get_link_token() != get_proxy_info_query_token_) { - return; - } - SCOPE_EXIT { loop(); }; + if (get_link_token() != get_proxy_info_query_token_) { + return; + } + get_proxy_info_query_token_ = 0; auto res = fetch_result(std::move(query)); if (res.is_error()) { @@ -1407,16 +1409,16 @@ void ConnectionCreator::schedule_get_proxy_info(int32 expires) { } void ConnectionCreator::on_proxy_resolved(Result r_ip_address, bool dummy) { + SCOPE_EXIT { + loop(); + }; + if (get_link_token() != resolve_proxy_query_token_) { VLOG(connections) << "Ignore unneeded proxy IP address " << get_link_token() << ", expected " << resolve_proxy_query_token_; return; } - SCOPE_EXIT { - loop(); - }; - resolve_proxy_query_token_ = 0; if (r_ip_address.is_error()) { VLOG(connections) << "Receive error for resolving proxy IP address: " << r_ip_address.error();