From 821bc642cf58ca1baa73efc91efea4dca283ce2c Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 3 May 2018 13:18:07 +0300 Subject: [PATCH] Update layer 78. GitOrigin-RevId: 8aac14c20fc90c6a0b118fbbe80d4b83034416a2 --- td/generate/scheme/telegram_api.tl | 2 +- td/generate/scheme/telegram_api.tlo | Bin 157004 -> 157108 bytes td/telegram/ConfigManager.cpp | 29 ++++++++++++++++++++++------ td/telegram/ConfigShared.cpp | 6 +++--- td/telegram/ConfigShared.h | 2 +- td/telegram/Td.cpp | 2 +- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/td/generate/scheme/telegram_api.tl b/td/generate/scheme/telegram_api.tl index 681325eb..178a59ca 100644 --- a/td/generate/scheme/telegram_api.tl +++ b/td/generate/scheme/telegram_api.tl @@ -342,7 +342,7 @@ upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; -config#86b5778e flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; +config#eb7bb160 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc; diff --git a/td/generate/scheme/telegram_api.tlo b/td/generate/scheme/telegram_api.tlo index ea62d1c72b5da9e443d74ae7f1d4636a0e21733d..9ee1d70484df0365ad86795e0bdeeff032a91d9a 100644 GIT binary patch delta 158 zcmX?eigU|p&J7tXED0N{UvJJ~xezT1VzDLX=cQ$)Gl1APj|ur`ZVpVaX5{Bd%E?d8 zPECo=%}+^XV3;iLsI<8^F`ZRWG_kZKzqBAFu_QIVv?wROpeQvhvx0$vi2(xGCmU*s qPyUjY1Gc9*C4GBJI%C2t37GjHRYlHhIvlob2SH-n?=UhIBm)5cV><)@ delta 100 zcmdmTn)A#l&J7tXEPdr$+cxL0T!39}?%su+Nv$eB%t!?x`pNNl?c6H`Gl0FRL=V*mgE diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 599fcbb0..9a89bb36 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -359,7 +359,7 @@ class ConfigRecoverer : public Actor { if (r_dc_options.is_ok()) { simple_config_ = r_dc_options.move_as_ok(); VLOG(config_recoverer) << "Got SimpleConfig " << simple_config_; - simple_config_expire_at_ = Time::now_cached() + Random::fast(20 * 60, 30 * 60); + simple_config_expire_at_ = get_config_expire_time(); simple_config_at_ = Time::now_cached(); for (size_t i = 1; i < simple_config_.dc_options.size(); i++) { std::swap(simple_config_.dc_options[i], simple_config_.dc_options[Random::fast(0, static_cast(i))]); @@ -367,7 +367,7 @@ class ConfigRecoverer : public Actor { } else { VLOG(config_recoverer) << "Get SimpleConfig error " << r_dc_options.error(); simple_config_ = DcOptions(); - simple_config_expire_at_ = Time::now_cached() + Random::fast(15, 30); + simple_config_expire_at_ = get_failed_config_expire_time(); } update_dc_options(); loop(); @@ -378,16 +378,28 @@ class ConfigRecoverer : public Actor { if (r_full_config.is_ok()) { full_config_ = r_full_config.move_as_ok(); VLOG(config_recoverer) << "Got FullConfig " << to_string(full_config_); - full_config_expire_at_ = Time::now() + Random::fast(20 * 60, 30 * 60); + full_config_expire_at_ = get_config_expire_time(); send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(full_config_->dc_options_)); } else { VLOG(config_recoverer) << "Get FullConfig error " << r_full_config.error(); full_config_ = FullConfig(); - full_config_expire_at_ = Time::now() + Random::fast(15, 30); + full_config_expire_at_ = get_failed_config_expire_time(); } loop(); } + bool expect_blocking() const { + return G()->shared_config().get_option_boolean("expect_blocking", true); + } + + double get_config_expire_time() const { + return Time::now() + (expect_blocking() ? Random::fast(2 * 60, 3 * 60) : Random::fast(20 * 60, 30 * 60)); + } + + double get_failed_config_expire_time() const { + return Time::now() + (expect_blocking() ? Random::fast(5, 7) : Random::fast(15, 30)); + } + bool is_connecting_{false}; double connecting_since_{0}; @@ -437,7 +449,7 @@ class ConfigRecoverer : public Actor { } double max_connecting_delay() const { - return 20; + return expect_blocking() ? 5 : 20; } void loop() override { if (close_flag_) { @@ -470,7 +482,8 @@ class ConfigRecoverer : public Actor { bool has_dc_options = !dc_options_.dc_options.empty(); bool is_valid_full_config = !check_timeout(Timestamp::at(full_config_expire_at_)); bool need_full_config = has_connecting_problem && has_dc_options && !is_valid_full_config && - full_config_query_.empty() && check_timeout(Timestamp::at(dc_options_at_ + 10)); + full_config_query_.empty() && + check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10))); if (need_simple_config) { ref_cnt_++; VLOG(config_recoverer) << "ASK SIMPLE CONFIG"; @@ -687,6 +700,10 @@ void ConfigManager::process_config(tl_object_ptr config) { shared_config.set_option_integer("basic_group_size_max", config->chat_size_max_); shared_config.set_option_integer("supergroup_size_max", config->megagroup_size_max_); shared_config.set_option_integer("pinned_chat_count_max", config->pinned_dialogs_count_max_); + if (is_from_main_dc || !shared_config.have_option("expect_blocking")) { + shared_config.set_option_integer("expect_blocking", + (config->flags_ & telegram_api::config::BLOCKED_MODE_MASK) != 0); + } if (is_from_main_dc || !shared_config.have_option("t_me_url")) { shared_config.set_option_string("t_me_url", config->me_url_prefix_); } diff --git a/td/telegram/ConfigShared.cpp b/td/telegram/ConfigShared.cpp index 637d9fcd..cd79eeb3 100644 --- a/td/telegram/ConfigShared.cpp +++ b/td/telegram/ConfigShared.cpp @@ -58,10 +58,10 @@ std::unordered_map ConfigShared::get_options() const { return config_pmc_->get_all(); } -bool ConfigShared::get_option_boolean(Slice name) const { +bool ConfigShared::get_option_boolean(Slice name, bool default_value) const { auto value = get_option(name); if (value.empty()) { - return false; + return default_value; } if (value == "Btrue") { return true; @@ -70,7 +70,7 @@ bool ConfigShared::get_option_boolean(Slice name) const { return false; } LOG(ERROR) << "Found \"" << value << "\" instead of boolean option"; - return false; + return default_value; } int32 ConfigShared::get_option_integer(Slice name, int32 default_value) const { diff --git a/td/telegram/ConfigShared.h b/td/telegram/ConfigShared.h index 03f3ca28..cd85d28b 100644 --- a/td/telegram/ConfigShared.h +++ b/td/telegram/ConfigShared.h @@ -39,7 +39,7 @@ class ConfigShared { std::unordered_map get_options(Slice prefix) const; std::unordered_map get_options() const; - bool get_option_boolean(Slice name) const; + bool get_option_boolean(Slice name, bool default_value = false) const; int32 get_option_integer(Slice name, int32 default_value = 0) const; tl_object_ptr get_option_value(Slice value) const; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 7628fbe6..7a4e8941 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4102,7 +4102,7 @@ bool Td::is_internal_config_option(Slice name) { return name == "call_ring_timeout_ms" || name == "call_receive_timeout_ms" || name == "channels_read_media_period" || name == "edit_time_limit" || name == "revoke_pm_inbox" || name == "revoke_time_limit" || name == "revoke_pm_time_limit" || name == "rating_e_decay" || name == "saved_animations_limit" || - name == "recent_stickers_limit" || name == "auth"; + name == "recent_stickers_limit" || name == "expect_blocking" || name == "auth"; } void Td::on_config_option_updated(const string &name) {