diff --git a/td/telegram/net/PublicRsaKeyWatchdog.cpp b/td/telegram/net/PublicRsaKeyWatchdog.cpp index 131997206..cb881c4ee 100644 --- a/td/telegram/net/PublicRsaKeyWatchdog.cpp +++ b/td/telegram/net/PublicRsaKeyWatchdog.cpp @@ -9,8 +9,8 @@ #include "td/telegram/Global.h" #include "td/telegram/net/NetQueryCreator.h" #include "td/telegram/TdDb.h" - #include "td/telegram/telegram_api.h" +#include "td/telegram/Version.h" #include "td/mtproto/RSA.h" @@ -47,7 +47,14 @@ void PublicRsaKeyWatchdog::start_up() { flood_control_.add_limit(2, 60); flood_control_.add_limit(3, 2 * 60); - sync(BufferSlice(G()->td_db()->get_binlog_pmc()->get("cdn_config"))); + string version = G()->td_db()->get_binlog_pmc()->get("cdn_config_version"); + current_version_ = to_string(MTPROTO_LAYER); + if (version != current_version_) { + G()->td_db()->get_binlog_pmc()->erase("cdn_config" + version); + } else { + sync(BufferSlice(G()->td_db()->get_binlog_pmc()->get("cdn_config" + version))); + } + CHECK(keys_.empty()); } void PublicRsaKeyWatchdog::loop() { @@ -84,7 +91,8 @@ void PublicRsaKeyWatchdog::on_result(NetQueryPtr net_query) { } auto buf = net_query->move_as_ok(); - G()->td_db()->get_binlog_pmc()->set("cdn_config", buf.as_slice().str()); + G()->td_db()->get_binlog_pmc()->set("cdn_config_version", current_version_); + G()->td_db()->get_binlog_pmc()->set("cdn_config" + current_version_, buf.as_slice().str()); sync(std::move(buf)); } @@ -100,9 +108,13 @@ void PublicRsaKeyWatchdog::sync(BufferSlice cdn_config_serialized) { return; } cdn_config_ = r_keys.move_as_ok(); - LOG(INFO) << "Receive " << to_string(cdn_config_); - for (auto &key : keys_) { - sync_key(key); + if (keys_.empty()) { + LOG(INFO) << "Load " << to_string(cdn_config_); + } else { + LOG(INFO) << "Receive " << to_string(cdn_config_); + for (auto &key : keys_) { + sync_key(key); + } } } diff --git a/td/telegram/net/PublicRsaKeyWatchdog.h b/td/telegram/net/PublicRsaKeyWatchdog.h index 632df9d2b..73e4e9f14 100644 --- a/td/telegram/net/PublicRsaKeyWatchdog.h +++ b/td/telegram/net/PublicRsaKeyWatchdog.h @@ -36,6 +36,7 @@ class PublicRsaKeyWatchdog final : public NetActor { tl_object_ptr cdn_config_; FloodControlStrict flood_control_; bool has_query_{false}; + string current_version_; void start_up() final; void loop() final;