Remove dangerous Timestamp::store.
This commit is contained in:
parent
9c04dc47ad
commit
b6db8a66ec
@ -55,6 +55,7 @@ void AuthManager::DbState::store(StorerT &storer) const {
|
|||||||
bool is_wait_registration_supported = true;
|
bool is_wait_registration_supported = true;
|
||||||
bool is_wait_registration_stores_phone_number = true;
|
bool is_wait_registration_stores_phone_number = true;
|
||||||
bool is_wait_qr_code_confirmation_supported = true;
|
bool is_wait_qr_code_confirmation_supported = true;
|
||||||
|
bool is_time_store_supported = true;
|
||||||
BEGIN_STORE_FLAGS();
|
BEGIN_STORE_FLAGS();
|
||||||
STORE_FLAG(has_terms_of_service);
|
STORE_FLAG(has_terms_of_service);
|
||||||
STORE_FLAG(is_pbkdf2_supported);
|
STORE_FLAG(is_pbkdf2_supported);
|
||||||
@ -64,11 +65,12 @@ void AuthManager::DbState::store(StorerT &storer) const {
|
|||||||
STORE_FLAG(is_wait_qr_code_confirmation_supported);
|
STORE_FLAG(is_wait_qr_code_confirmation_supported);
|
||||||
STORE_FLAG(allow_apple_id_);
|
STORE_FLAG(allow_apple_id_);
|
||||||
STORE_FLAG(allow_google_id_);
|
STORE_FLAG(allow_google_id_);
|
||||||
|
STORE_FLAG(is_time_store_supported);
|
||||||
END_STORE_FLAGS();
|
END_STORE_FLAGS();
|
||||||
store(state_, storer);
|
store(state_, storer);
|
||||||
store(api_id_, storer);
|
store(api_id_, storer);
|
||||||
store(api_hash_, storer);
|
store(api_hash_, storer);
|
||||||
store(state_timestamp_, storer);
|
store_time(state_timestamp_.at(), storer);
|
||||||
|
|
||||||
if (has_terms_of_service) {
|
if (has_terms_of_service) {
|
||||||
store(terms_of_service_, storer);
|
store(terms_of_service_, storer);
|
||||||
@ -105,6 +107,7 @@ void AuthManager::DbState::parse(ParserT &parser) {
|
|||||||
bool is_wait_registration_supported = false;
|
bool is_wait_registration_supported = false;
|
||||||
bool is_wait_registration_stores_phone_number = false;
|
bool is_wait_registration_stores_phone_number = false;
|
||||||
bool is_wait_qr_code_confirmation_supported = false;
|
bool is_wait_qr_code_confirmation_supported = false;
|
||||||
|
bool is_time_store_supported = false;
|
||||||
if (parser.version() >= static_cast<int32>(Version::AddTermsOfService)) {
|
if (parser.version() >= static_cast<int32>(Version::AddTermsOfService)) {
|
||||||
BEGIN_PARSE_FLAGS();
|
BEGIN_PARSE_FLAGS();
|
||||||
PARSE_FLAG(has_terms_of_service);
|
PARSE_FLAG(has_terms_of_service);
|
||||||
@ -115,20 +118,24 @@ void AuthManager::DbState::parse(ParserT &parser) {
|
|||||||
PARSE_FLAG(is_wait_qr_code_confirmation_supported);
|
PARSE_FLAG(is_wait_qr_code_confirmation_supported);
|
||||||
PARSE_FLAG(allow_apple_id_);
|
PARSE_FLAG(allow_apple_id_);
|
||||||
PARSE_FLAG(allow_google_id_);
|
PARSE_FLAG(allow_google_id_);
|
||||||
|
PARSE_FLAG(is_time_store_supported);
|
||||||
END_PARSE_FLAGS();
|
END_PARSE_FLAGS();
|
||||||
}
|
}
|
||||||
if (!is_wait_qr_code_confirmation_supported) {
|
if (!is_time_store_supported) {
|
||||||
return parser.set_error("Have no QR code confirmation support");
|
return parser.set_error("Have no time store support");
|
||||||
}
|
}
|
||||||
CHECK(is_pbkdf2_supported);
|
CHECK(is_pbkdf2_supported);
|
||||||
CHECK(is_srp_supported);
|
CHECK(is_srp_supported);
|
||||||
CHECK(is_wait_registration_supported);
|
CHECK(is_wait_registration_supported);
|
||||||
CHECK(is_wait_registration_stores_phone_number);
|
CHECK(is_wait_registration_stores_phone_number);
|
||||||
|
CHECK(is_wait_qr_code_confirmation_supported);
|
||||||
|
|
||||||
parse(state_, parser);
|
parse(state_, parser);
|
||||||
parse(api_id_, parser);
|
parse(api_id_, parser);
|
||||||
parse(api_hash_, parser);
|
parse(api_hash_, parser);
|
||||||
parse(state_timestamp_, parser);
|
double state_timestamp = 0.0;
|
||||||
|
parse_time(state_timestamp, parser);
|
||||||
|
state_timestamp_ = Timestamp::at(state_timestamp);
|
||||||
|
|
||||||
if (has_terms_of_service) {
|
if (has_terms_of_service) {
|
||||||
parse(terms_of_service_, parser);
|
parse(terms_of_service_, parser);
|
||||||
|
@ -15,7 +15,8 @@ void SendCodeHelper::on_sent_code(telegram_api::object_ptr<telegram_api::auth_se
|
|||||||
phone_code_hash_ = std::move(sent_code->phone_code_hash_);
|
phone_code_hash_ = std::move(sent_code->phone_code_hash_);
|
||||||
sent_code_info_ = get_sent_authentication_code_info(std::move(sent_code->type_));
|
sent_code_info_ = get_sent_authentication_code_info(std::move(sent_code->type_));
|
||||||
next_code_info_ = get_authentication_code_info(std::move(sent_code->next_type_));
|
next_code_info_ = get_authentication_code_info(std::move(sent_code->next_type_));
|
||||||
next_code_timestamp_ = Timestamp::in((sent_code->flags_ & SENT_CODE_FLAG_HAS_TIMEOUT) != 0 ? sent_code->timeout_ : 0);
|
next_code_timestamp_ =
|
||||||
|
Time::now() + ((sent_code->flags_ & SENT_CODE_FLAG_HAS_TIMEOUT) != 0 ? sent_code->timeout_ : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendCodeHelper::on_phone_code_hash(string &&phone_code_hash) {
|
void SendCodeHelper::on_phone_code_hash(string &&phone_code_hash) {
|
||||||
@ -30,7 +31,7 @@ td_api::object_ptr<td_api::authenticationCodeInfo> SendCodeHelper::get_authentic
|
|||||||
return make_tl_object<td_api::authenticationCodeInfo>(
|
return make_tl_object<td_api::authenticationCodeInfo>(
|
||||||
phone_number_, get_authentication_code_type_object(sent_code_info_),
|
phone_number_, get_authentication_code_type_object(sent_code_info_),
|
||||||
get_authentication_code_type_object(next_code_info_),
|
get_authentication_code_type_object(next_code_info_),
|
||||||
max(static_cast<int32>(next_code_timestamp_.in() + 1 - 1e-9), 0));
|
max(static_cast<int32>(next_code_timestamp_ - Time::now() + 1 - 1e-9), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<telegram_api::auth_resendCode> SendCodeHelper::resend_code() const {
|
Result<telegram_api::auth_resendCode> SendCodeHelper::resend_code() const {
|
||||||
|
@ -83,7 +83,7 @@ class SendCodeHelper {
|
|||||||
|
|
||||||
SendCodeHelper::AuthenticationCodeInfo sent_code_info_;
|
SendCodeHelper::AuthenticationCodeInfo sent_code_info_;
|
||||||
SendCodeHelper::AuthenticationCodeInfo next_code_info_;
|
SendCodeHelper::AuthenticationCodeInfo next_code_info_;
|
||||||
Timestamp next_code_timestamp_;
|
double next_code_timestamp_ = 0.0;
|
||||||
|
|
||||||
static AuthenticationCodeInfo get_authentication_code_info(
|
static AuthenticationCodeInfo get_authentication_code_info(
|
||||||
tl_object_ptr<telegram_api::auth_CodeType> &&code_type_ptr);
|
tl_object_ptr<telegram_api::auth_CodeType> &&code_type_ptr);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "td/telegram/logevent/LogEventHelper.h"
|
||||||
#include "td/telegram/SendCodeHelper.h"
|
#include "td/telegram/SendCodeHelper.h"
|
||||||
|
|
||||||
#include "td/utils/tl_helpers.h"
|
#include "td/utils/tl_helpers.h"
|
||||||
@ -36,7 +37,7 @@ void SendCodeHelper::store(StorerT &storer) const {
|
|||||||
store(phone_code_hash_, storer);
|
store(phone_code_hash_, storer);
|
||||||
store(sent_code_info_, storer);
|
store(sent_code_info_, storer);
|
||||||
store(next_code_info_, storer);
|
store(next_code_info_, storer);
|
||||||
store(next_code_timestamp_, storer);
|
store_time(next_code_timestamp_, storer);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ParserT>
|
template <class ParserT>
|
||||||
@ -48,7 +49,7 @@ void SendCodeHelper::parse(ParserT &parser) {
|
|||||||
parse(phone_code_hash_, parser);
|
parse(phone_code_hash_, parser);
|
||||||
parse(sent_code_info_, parser);
|
parse(sent_code_info_, parser);
|
||||||
parse(next_code_info_, parser);
|
parse(next_code_info_, parser);
|
||||||
parse(next_code_timestamp_, parser);
|
parse_time(next_code_timestamp_, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
//
|
//
|
||||||
#include "td/utils/Time.h"
|
#include "td/utils/Time.h"
|
||||||
|
|
||||||
|
#include "td/utils/port/Clocks.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/port/Clocks.h"
|
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
@ -58,9 +57,6 @@ class Timestamp {
|
|||||||
static Timestamp at(double timeout) {
|
static Timestamp at(double timeout) {
|
||||||
return Timestamp{timeout};
|
return Timestamp{timeout};
|
||||||
}
|
}
|
||||||
static Timestamp at_unix(double timeout) {
|
|
||||||
return Timestamp{timeout - Clocks::system() + Time::now()};
|
|
||||||
}
|
|
||||||
|
|
||||||
static Timestamp in(double timeout, Timestamp now = now_cached()) {
|
static Timestamp in(double timeout, Timestamp now = now_cached()) {
|
||||||
return Timestamp{now.at() + timeout};
|
return Timestamp{now.at() + timeout};
|
||||||
@ -80,9 +76,6 @@ class Timestamp {
|
|||||||
double at() const {
|
double at() const {
|
||||||
return at_;
|
return at_;
|
||||||
}
|
}
|
||||||
double at_unix() const {
|
|
||||||
return at_ + Clocks::system() - Time::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
double in() const {
|
double in() const {
|
||||||
return at_ - Time::now_cached();
|
return at_ - Time::now_cached();
|
||||||
@ -110,14 +103,4 @@ inline bool operator<(const Timestamp &a, const Timestamp &b) {
|
|||||||
return a.at() < b.at();
|
return a.at() < b.at();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class StorerT>
|
|
||||||
void store(const Timestamp ×tamp, StorerT &storer) {
|
|
||||||
storer.store_binary(timestamp.at() - Time::now() + Clocks::system());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class ParserT>
|
|
||||||
void parse(Timestamp ×tamp, ParserT &parser) {
|
|
||||||
timestamp = Timestamp::in(parser.fetch_double() - Clocks::system());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
x
Reference in New Issue
Block a user