Better AuthManager storers and parsers.
GitOrigin-RevId: 20e1e7ed3591d1f99c0661164360822dd6d0b3e6
This commit is contained in:
parent
c9a9e386e5
commit
6855704b52
@ -844,20 +844,20 @@ bool AuthManager::load_state() {
|
|||||||
DbState db_state;
|
DbState db_state;
|
||||||
auto status = log_event_parse(db_state, data);
|
auto status = log_event_parse(db_state, data);
|
||||||
if (status.is_error()) {
|
if (status.is_error()) {
|
||||||
LOG(INFO) << "Ignore auth_state :" << status;
|
LOG(INFO) << "Ignore auth_state: " << status;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CHECK(db_state.state_ == State::WaitCode);
|
CHECK(db_state.state_ == State::WaitCode);
|
||||||
if (db_state.api_id_ != api_id_ || db_state.api_hash_ != api_hash_) {
|
if (db_state.api_id_ != api_id_ || db_state.api_hash_ != api_hash_) {
|
||||||
LOG(INFO) << "Ignore auth_state : api_id or api_hash changed";
|
LOG(INFO) << "Ignore auth_state: api_id or api_hash changed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!db_state.state_timestamp_.is_in_past()) {
|
if (!db_state.state_timestamp_.is_in_past()) {
|
||||||
LOG(INFO) << "Ignore auth_state : timestamp in future";
|
LOG(INFO) << "Ignore auth_state: timestamp in future";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Timestamp::at(db_state.state_timestamp_.at() + 5 * 60).is_in_past()) {
|
if (Timestamp::at(db_state.state_timestamp_.at() + 5 * 60).is_in_past()) {
|
||||||
LOG(INFO) << "Ignore auth_state : expired " << db_state.state_timestamp_.in();
|
LOG(INFO) << "Ignore auth_state: expired " << db_state.state_timestamp_.in();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Load auth_state from db";
|
LOG(INFO) << "Load auth_state from db";
|
||||||
|
@ -51,7 +51,7 @@ class SendCodeHelper {
|
|||||||
static constexpr int32 SENT_CODE_FLAG_HAS_TIMEOUT = 1 << 2;
|
static constexpr int32 SENT_CODE_FLAG_HAS_TIMEOUT = 1 << 2;
|
||||||
|
|
||||||
struct AuthenticationCodeInfo {
|
struct AuthenticationCodeInfo {
|
||||||
enum class Type { None, Message, Sms, Call, FlashCall };
|
enum class Type : int32 { None, Message, Sms, Call, FlashCall };
|
||||||
Type type = Type::None;
|
Type type = Type::None;
|
||||||
int32 length = 0;
|
int32 length = 0;
|
||||||
string pattern;
|
string pattern;
|
||||||
@ -141,7 +141,7 @@ class AuthManager : public NetActor {
|
|||||||
private:
|
private:
|
||||||
static constexpr size_t MAX_NAME_LENGTH = 255; // server side limit
|
static constexpr size_t MAX_NAME_LENGTH = 255; // server side limit
|
||||||
|
|
||||||
enum class State { None, WaitPhoneNumber, WaitCode, WaitPassword, Ok, LoggingOut, Closing } state_ = State::None;
|
enum class State : int32 { None, WaitPhoneNumber, WaitCode, WaitPassword, Ok, LoggingOut, Closing } state_ = State::None;
|
||||||
enum class NetQueryType {
|
enum class NetQueryType {
|
||||||
None,
|
None,
|
||||||
SignIn,
|
SignIn,
|
||||||
|
@ -12,16 +12,14 @@ namespace td {
|
|||||||
template <class T>
|
template <class T>
|
||||||
void SendCodeHelper::AuthenticationCodeInfo::store(T &storer) const {
|
void SendCodeHelper::AuthenticationCodeInfo::store(T &storer) const {
|
||||||
using td::store;
|
using td::store;
|
||||||
store(static_cast<int>(type), storer);
|
store(type, storer);
|
||||||
store(length, storer);
|
store(length, storer);
|
||||||
store(pattern, storer);
|
store(pattern, storer);
|
||||||
}
|
}
|
||||||
template <class T>
|
template <class T>
|
||||||
void SendCodeHelper::AuthenticationCodeInfo::parse(T &parser) {
|
void SendCodeHelper::AuthenticationCodeInfo::parse(T &parser) {
|
||||||
using td::parse;
|
using td::parse;
|
||||||
int32 type_int;
|
parse(type, parser);
|
||||||
parse(type_int, parser);
|
|
||||||
type = narrow_cast<decltype(type)>(type_int);
|
|
||||||
parse(length, parser);
|
parse(length, parser);
|
||||||
parse(pattern, parser);
|
parse(pattern, parser);
|
||||||
}
|
}
|
||||||
@ -52,7 +50,7 @@ template <class T>
|
|||||||
void AuthManager::DbState::store(T &storer) const {
|
void AuthManager::DbState::store(T &storer) const {
|
||||||
using td::store;
|
using td::store;
|
||||||
CHECK(state_ == State::WaitCode);
|
CHECK(state_ == State::WaitCode);
|
||||||
store(static_cast<int32>(state_), storer);
|
store(state_, storer);
|
||||||
store(api_id_, storer);
|
store(api_id_, storer);
|
||||||
store(api_hash_, storer);
|
store(api_hash_, storer);
|
||||||
store(send_code_helper_, storer);
|
store(send_code_helper_, storer);
|
||||||
@ -61,9 +59,7 @@ void AuthManager::DbState::store(T &storer) const {
|
|||||||
template <class T>
|
template <class T>
|
||||||
void AuthManager::DbState::parse(T &parser) {
|
void AuthManager::DbState::parse(T &parser) {
|
||||||
using td::parse;
|
using td::parse;
|
||||||
int32 state;
|
parse(state_, parser);
|
||||||
parse(state, parser);
|
|
||||||
state_ = narrow_cast<State>(state);
|
|
||||||
parse(api_id_, parser);
|
parse(api_id_, parser);
|
||||||
parse(api_hash_, parser);
|
parse(api_hash_, parser);
|
||||||
parse(send_code_helper_, parser);
|
parse(send_code_helper_, parser);
|
||||||
|
Loading…
Reference in New Issue
Block a user