From 879f8da67aeec6ef40c3d83b99dd31fd42a59f06 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 12 Apr 2022 16:21:42 +0300 Subject: [PATCH] Respect flood waits in reregister_device. --- td/telegram/DeviceTokenManager.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/td/telegram/DeviceTokenManager.cpp b/td/telegram/DeviceTokenManager.cpp index 5239ef667..fc9b3e7b6 100644 --- a/td/telegram/DeviceTokenManager.cpp +++ b/td/telegram/DeviceTokenManager.cpp @@ -22,6 +22,7 @@ #include "td/utils/format.h" #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" +#include "td/utils/misc.h" #include "td/utils/Random.h" #include "td/utils/SliceBuilder.h" #include "td/utils/Status.h" @@ -431,9 +432,13 @@ void DeviceTokenManager::on_result(NetQueryPtr net_query) { } info.state = TokenInfo::State::Sync; } else { + int32 retry_after = 0; if (r_flag.is_error()) { - if (!G()->is_expected_error(r_flag.error())) { - LOG(ERROR) << "Failed to " << info.state << " device: " << r_flag.error(); + auto &error = r_flag.error(); + if (!G()->is_expected_error(error)) { + LOG(ERROR) << "Failed to " << info.state << " device: " << error; + } else { + retry_after = Global::get_retry_after(error.code(), error.message()); } info.promise.set_error(r_flag.move_as_error()); } else { @@ -441,7 +446,7 @@ void DeviceTokenManager::on_result(NetQueryPtr net_query) { } if (info.state == TokenInfo::State::Reregister) { // keep trying to reregister the token - return loop(); + return set_timeout_in(clamp(retry_after, 1, 3600)); } else if (info.state == TokenInfo::State::Register) { info.state = TokenInfo::State::Unregister; } else {