From bfcf52f87cc16b00564543b5aab47dc7b031ed4b Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 6 Jun 2022 20:36:15 +0300 Subject: [PATCH] Support MTPROTO_CLUSTER_INVALID error. --- td/telegram/AuthManager.cpp | 2 +- td/telegram/ConfigManager.cpp | 27 ++++++++++++++++----------- td/telegram/ConfigManager.h | 5 +++-- td/telegram/OptionManager.cpp | 2 +- td/telegram/Payments.cpp | 3 ++- td/telegram/PollManager.cpp | 2 +- td/telegram/UpdatesManager.cpp | 2 +- td/telegram/files/FileManager.cpp | 6 +++++- td/telegram/net/ConnectionCreator.cpp | 2 +- td/telegram/net/SessionProxy.cpp | 1 + 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 24702f2f6..c883ce789 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -803,7 +803,7 @@ void AuthManager::on_get_authorization(tl_object_ptrset_is_bot_online(true); } - send_closure(G()->config_manager(), &ConfigManager::request_config); + send_closure(G()->config_manager(), &ConfigManager::request_config, false); if (query_id_ != 0) { on_query_ok(); } diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 63fa3b73d..d7767937b 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -909,7 +909,7 @@ void ConfigManager::start_up() { auto expire_time = load_config_expire_time(); if (expire_time.is_in_past() || true) { - request_config(); + request_config(false); } else { expire_time_ = expire_time; set_timeout_in(expire_time_.in()); @@ -935,7 +935,7 @@ void ConfigManager::hangup() { void ConfigManager::loop() { if (expire_time_ && expire_time_.is_in_past()) { - request_config(); + request_config(reopen_sessions_after_get_config_); expire_time_ = {}; } } @@ -946,17 +946,17 @@ void ConfigManager::try_stop() { } } -void ConfigManager::request_config() { +void ConfigManager::request_config(bool reopen_sessions) { if (G()->close_flag()) { return; } - if (config_sent_cnt_ != 0) { + if (config_sent_cnt_ != 0 && !reopen_sessions) { return; } lazy_request_flood_control_.add_event(static_cast(Timestamp::now().at())); - request_config_from_dc_impl(DcId::main()); + request_config_from_dc_impl(DcId::main(), reopen_sessions); } void ConfigManager::lazy_request_config() { @@ -1086,11 +1086,13 @@ void ConfigManager::on_dc_options_update(DcOptions dc_options) { send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, std::move(dc_options)); } -void ConfigManager::request_config_from_dc_impl(DcId dc_id) { +void ConfigManager::request_config_from_dc_impl(DcId dc_id, bool reopen_sessions) { config_sent_cnt_++; + reopen_sessions_after_get_config_ |= reopen_sessions; auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), dc_id); query->total_timeout_limit_ = 60 * 60 * 24; - G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 8)); + G()->net_query_dispatcher().dispatch_with_callback(std::move(query), + actor_shared(this, 8 + static_cast(reopen_sessions))); } void ConfigManager::do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions) { @@ -1257,7 +1259,7 @@ void ConfigManager::on_result(NetQueryPtr res) { return; } - CHECK(token == 8); + CHECK(token == 8 || token == 9); CHECK(config_sent_cnt_ > 0); config_sent_cnt_--; auto r_config = fetch_result(std::move(res)); @@ -1270,6 +1272,9 @@ void ConfigManager::on_result(NetQueryPtr res) { } else { on_dc_options_update(DcOptions()); process_config(r_config.move_as_ok()); + if (token == 9) { + G()->net_query_dispatcher().update_mtproto_header(); + } } } @@ -1482,9 +1487,9 @@ void ConfigManager::process_app_config(tl_object_ptr &c for (auto &key_value : static_cast(config.get())->value_) { Slice key = key_value->key_; telegram_api::JSONValue *value = key_value->value_.get(); - if (key == "test" || key == "wallet_enabled" || key == "wallet_blockchain_name" || key == "wallet_config" || - key == "stickers_emoji_cache_time" || key == "upload_max_fileparts_default" || - key == "upload_max_fileparts_premium") { + if (key == "message_animated_emoji_max" || key == "stickers_emoji_cache_time" || key == "test" || + key == "upload_max_fileparts_default" || key == "upload_max_fileparts_premium" || + key == "wallet_blockchain_name" || key == "wallet_config" || key == "wallet_enabled") { continue; } if (key == "ignore_restriction_reasons") { diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 472982cea..b04be2133 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -81,7 +81,7 @@ class ConfigManager final : public NetQueryCallback { public: explicit ConfigManager(ActorShared<> parent); - void request_config(); + void request_config(bool reopen_sessions); void lazy_request_config(); @@ -108,6 +108,7 @@ class ConfigManager final : public NetQueryCallback { private: ActorShared<> parent_; int32 config_sent_cnt_{0}; + bool reopen_sessions_after_get_config_{false}; ActorOwn config_recoverer_; int ref_cnt_{1}; Timestamp expire_time_; @@ -141,7 +142,7 @@ class ConfigManager final : public NetQueryCallback { void on_result(NetQueryPtr res) final; - void request_config_from_dc_impl(DcId dc_id); + void request_config_from_dc_impl(DcId dc_id, bool reopen_sessions); void process_config(tl_object_ptr config); void try_request_app_config(); diff --git a/td/telegram/OptionManager.cpp b/td/telegram/OptionManager.cpp index 154dcc04e..71e903b4b 100644 --- a/td/telegram/OptionManager.cpp +++ b/td/telegram/OptionManager.cpp @@ -284,7 +284,7 @@ void OptionManager::on_option_updated(const string &name) { } } if (name == "is_premium") { - send_closure(td_->config_manager_, &ConfigManager::request_config); + send_closure(td_->config_manager_, &ConfigManager::request_config, true); } break; case 'l': diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 3d5646765..9dc08728b 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -688,7 +688,8 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Invoice &invoice) << (invoice.send_email_address_to_provider ? ", sends email address to provider" : "") << (invoice.recurring_payment_terms_of_service_url.empty() ? string() - : ", recurring payments terms of service at " + invoice.recurring_payment_terms_of_service_url) + : ", recurring payments terms of service at " + + invoice.recurring_payment_terms_of_service_url) << " in " << invoice.currency << " with price parts " << format::as_array(invoice.price_parts) << " and suggested tip amounts " << invoice.suggested_tip_amounts << " up to " << invoice.max_tip_amount << "]"; diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index b7a774d4b..c7a6f9e8e 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1691,7 +1691,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptrexplanation != explanation && (!is_min || poll_server_is_closed)) { if (explanation.text.empty() && !poll->explanation.text.empty()) { - LOG(ERROR) << "Can't change known " << poll_id << " explanation to empty from " << source ; + LOG(ERROR) << "Can't change known " << poll_id << " explanation to empty from " << source; } else { poll->explanation = std::move(explanation); is_changed = true; diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index a5102ec33..4fbe74252 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -3199,7 +3199,7 @@ void UpdatesManager::on_update(tl_object_ptr upda } void UpdatesManager::on_update(tl_object_ptr update, Promise &&promise) { - send_closure(td_->config_manager_, &ConfigManager::request_config); + send_closure(td_->config_manager_, &ConfigManager::request_config, false); promise.set_value(Unit()); } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 9c51a6b50..dc48096d4 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -53,7 +53,7 @@ namespace td { namespace { -constexpr int64 MAX_FILE_SIZE = static_cast(4000) << 20; // 4000MB +constexpr int64 MAX_FILE_SIZE = static_cast(4000) << 20; // 4000MB } // namespace int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(INFO); @@ -3837,6 +3837,10 @@ void FileManager::on_error_impl(FileNodePtr node, Query::Type type, bool was_act return; } } + if (status.message() == "MTPROTO_CLUSTER_INVALID") { + run_download(node, true); + return; + } if (!was_active) { return; diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 504bd5993..eaa9671c6 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -420,7 +420,7 @@ void ConnectionCreator::set_active_proxy_id(int32 proxy_id, bool from_binlog) { if (!from_binlog) { if (proxy_id == 0) { G()->td_db()->get_binlog_pmc()->erase("proxy_active_id"); - send_closure(G()->config_manager(), &ConfigManager::request_config); + send_closure(G()->config_manager(), &ConfigManager::request_config, false); } else { G()->td_db()->get_binlog_pmc()->set("proxy_active_id", to_string(proxy_id)); } diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index ed0d74119..cb2de374c 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -173,6 +173,7 @@ void SessionProxy::close_session() { send_closure(std::move(session_), &Session::close); session_generation_++; } + void SessionProxy::open_session(bool force) { if (!session_.empty()) { return;