Ask for a config when there is no options for some DC

GitOrigin-RevId: e750c78a4685a20c93c888dee6eaf630b80f7d31
This commit is contained in:
Arseny Smirnov 2020-07-16 21:37:13 +03:00
parent c9889d1a20
commit 2a5c826111
3 changed files with 24 additions and 0 deletions

View File

@ -876,6 +876,7 @@ class ConfigRecoverer : public Actor {
};
ConfigManager::ConfigManager(ActorShared<> parent) : parent_(std::move(parent)) {
lazy_request_flood_countrol_.add_limit(20, 1);
}
void ConfigManager::start_up() {
@ -927,6 +928,19 @@ void ConfigManager::request_config() {
request_config_from_dc_impl(DcId::main());
}
void ConfigManager::lazy_request_config() {
if (G()->close_flag()) {
return;
}
if (config_sent_cnt_ != 0) {
return;
}
expire_time_.relax(Timestamp::at(lazy_request_flood_countrol_.get_wakeup_at()));
set_timeout_at(expire_time_.at());
}
void ConfigManager::get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise) {
if (G()->close_flag()) {
return promise.set_error(Status::Error(500, "Request aborted"));
@ -1033,6 +1047,7 @@ void ConfigManager::on_dc_options_update(DcOptions dc_options) {
void ConfigManager::request_config_from_dc_impl(DcId dc_id) {
config_sent_cnt_++;
lazy_request_flood_countrol_.add_event(static_cast<int32>(Timestamp::now().at()));
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, 0));

View File

@ -18,6 +18,7 @@
#include "td/actor/PromiseFuture.h"
#include "td/utils/common.h"
#include "td/utils/FloodControlStrict.h"
#include "td/utils/logging.h"
#include "td/utils/port/IPAddress.h"
#include "td/utils/Slice.h"
@ -87,6 +88,8 @@ class ConfigManager : public NetQueryCallback {
void request_config();
void lazy_request_config();
void get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise);
void get_content_settings(Promise<Unit> &&promise);
@ -110,6 +113,8 @@ class ConfigManager : public NetQueryCallback {
int ref_cnt_{1};
Timestamp expire_time_;
FloodControlStrict lazy_request_flood_countrol_;
vector<Promise<td_api::object_ptr<td_api::JsonValue>>> get_app_config_queries_;
vector<Promise<Unit>> get_content_settings_queries_;

View File

@ -6,6 +6,9 @@
//
#include "td/telegram/net/DcOptionsSet.h"
#include "td/telegram/Global.h"
#include "td/telegram/ConfigManager.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
@ -130,6 +133,7 @@ Result<DcOptionsSet::ConnectionInfo> DcOptionsSet::find_connection(DcId dc_id, b
auto options = find_all_connections(dc_id, allow_media_only, use_static, prefer_ipv6, only_http);
if (options.empty()) {
send_closure(G()->config_manager(), &ConfigManager::lazy_request_config);
return Status::Error(PSLICE() << "No such connection: " << tag("dc_id", dc_id)
<< tag("allow_media_only", allow_media_only) << tag("use_static", use_static)
<< tag("prefer_ipv6", prefer_ipv6));