Fix PublicRsaKeyWatchdog.
This commit is contained in:
parent
1464e85a5b
commit
23b0a91e88
@ -90,10 +90,10 @@ class AuthDataSharedImpl final : public AuthDataShared {
|
|||||||
std::shared_ptr<Guard> guard_;
|
std::shared_ptr<Guard> guard_;
|
||||||
RwMutex rw_mutex_;
|
RwMutex rw_mutex_;
|
||||||
|
|
||||||
string auth_key_key() {
|
string auth_key_key() const {
|
||||||
return PSTRING() << "auth" << dc_id_.get_raw_id();
|
return PSTRING() << "auth" << dc_id_.get_raw_id();
|
||||||
}
|
}
|
||||||
string future_salts_key() {
|
string future_salts_key() const {
|
||||||
return PSTRING() << "salt" << dc_id_.get_raw_id();
|
return PSTRING() << "salt" << dc_id_.get_raw_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +76,13 @@ Result<mtproto::PublicRsaKeyInterface::RsaKey> PublicRsaKeyShared::get_rsa_key(c
|
|||||||
|
|
||||||
void PublicRsaKeyShared::drop_keys() {
|
void PublicRsaKeyShared::drop_keys() {
|
||||||
if (dc_id_.is_empty()) {
|
if (dc_id_.is_empty()) {
|
||||||
|
// not CDN
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto lock = rw_mutex_.lock_write();
|
auto lock = rw_mutex_.lock_write();
|
||||||
|
LOG(INFO) << "Drop " << keys_.size() << " keys for " << dc_id_;
|
||||||
keys_.clear();
|
keys_.clear();
|
||||||
|
notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PublicRsaKeyShared::has_keys() {
|
bool PublicRsaKeyShared::has_keys() {
|
||||||
@ -104,7 +107,6 @@ mtproto::PublicRsaKeyInterface::RsaKey *PublicRsaKeyShared::get_rsa_key_unsafe(i
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PublicRsaKeyShared::notify() {
|
void PublicRsaKeyShared::notify() {
|
||||||
auto lock = rw_mutex_.lock_read();
|
|
||||||
td::remove_if(listeners_, [&](auto &listener) { return !listener->notify(); });
|
td::remove_if(listeners_, [&](auto &listener) { return !listener->notify(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ void PublicRsaKeyWatchdog::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Time::now_cached() < flood_control_.get_wakeup_at()) {
|
if (Time::now_cached() < flood_control_.get_wakeup_at()) {
|
||||||
|
set_timeout_in(flood_control_.get_wakeup_at() - Time::now_cached() + 0.01);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -78,6 +79,7 @@ void PublicRsaKeyWatchdog::on_result(NetQueryPtr net_query) {
|
|||||||
yield();
|
yield();
|
||||||
if (net_query->is_error()) {
|
if (net_query->is_error()) {
|
||||||
LOG(ERROR) << "Receive error for GetCdnConfig: " << net_query->move_as_error();
|
LOG(ERROR) << "Receive error for GetCdnConfig: " << net_query->move_as_error();
|
||||||
|
loop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,11 +90,13 @@ void PublicRsaKeyWatchdog::on_result(NetQueryPtr net_query) {
|
|||||||
|
|
||||||
void PublicRsaKeyWatchdog::sync(BufferSlice cdn_config_serialized) {
|
void PublicRsaKeyWatchdog::sync(BufferSlice cdn_config_serialized) {
|
||||||
if (cdn_config_serialized.empty()) {
|
if (cdn_config_serialized.empty()) {
|
||||||
|
loop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto r_keys = fetch_result<telegram_api::help_getCdnConfig>(cdn_config_serialized);
|
auto r_keys = fetch_result<telegram_api::help_getCdnConfig>(cdn_config_serialized);
|
||||||
if (r_keys.is_error()) {
|
if (r_keys.is_error()) {
|
||||||
LOG(WARNING) << "Failed to deserialize help_getCdnConfig (probably not a problem) " << r_keys.error();
|
LOG(WARNING) << "Failed to deserialize help_getCdnConfig (probably not a problem) " << r_keys.error();
|
||||||
|
loop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cdn_config_ = r_keys.move_as_ok();
|
cdn_config_ = r_keys.move_as_ok();
|
||||||
|
Loading…
Reference in New Issue
Block a user