Support MTPROTO_CLUSTER_INVALID error.

This commit is contained in:
levlam 2022-06-06 20:36:15 +03:00
parent 08e09160d6
commit bfcf52f87c
10 changed files with 32 additions and 20 deletions

View File

@ -803,7 +803,7 @@ void AuthManager::on_get_authorization(tl_object_ptr<telegram_api::auth_Authoriz
} else {
td_->set_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();
}

View File

@ -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<int32>(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<uint64>(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<telegram_api::help_getConfig>(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<telegram_api::JSONValue> &c
for (auto &key_value : static_cast<telegram_api::jsonObject *>(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") {

View File

@ -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<ConfigRecoverer> 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<telegram_api::config> config);
void try_request_app_config();

View File

@ -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':

View File

@ -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 << "]";

View File

@ -1691,7 +1691,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
}
if (poll->explanation != 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;

View File

@ -3199,7 +3199,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateSavedGifs> upda
}
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateConfig> update, Promise<Unit> &&promise) {
send_closure(td_->config_manager_, &ConfigManager::request_config);
send_closure(td_->config_manager_, &ConfigManager::request_config, false);
promise.set_value(Unit());
}

View File

@ -53,7 +53,7 @@
namespace td {
namespace {
constexpr int64 MAX_FILE_SIZE = static_cast<int64>(4000) << 20; // 4000MB
constexpr int64 MAX_FILE_SIZE = static_cast<int64>(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;

View File

@ -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));
}

View File

@ -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;