Better AuthManager storers and parsers.

GitOrigin-RevId: 20e1e7ed3591d1f99c0661164360822dd6d0b3e6
This commit is contained in:
levlam 2018-03-14 22:47:08 +03:00
parent c9a9e386e5
commit 6855704b52
3 changed files with 10 additions and 14 deletions

View File

@ -844,20 +844,20 @@ bool AuthManager::load_state() {
DbState db_state;
auto status = log_event_parse(db_state, data);
if (status.is_error()) {
LOG(INFO) << "Ignore auth_state :" << status;
LOG(INFO) << "Ignore auth_state: " << status;
return false;
}
CHECK(db_state.state_ == State::WaitCode);
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;
}
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;
}
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;
}
LOG(INFO) << "Load auth_state from db";

View File

@ -51,7 +51,7 @@ class SendCodeHelper {
static constexpr int32 SENT_CODE_FLAG_HAS_TIMEOUT = 1 << 2;
struct AuthenticationCodeInfo {
enum class Type { None, Message, Sms, Call, FlashCall };
enum class Type : int32 { None, Message, Sms, Call, FlashCall };
Type type = Type::None;
int32 length = 0;
string pattern;
@ -141,7 +141,7 @@ class AuthManager : public NetActor {
private:
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 {
None,
SignIn,

View File

@ -12,16 +12,14 @@ namespace td {
template <class T>
void SendCodeHelper::AuthenticationCodeInfo::store(T &storer) const {
using td::store;
store(static_cast<int>(type), storer);
store(type, storer);
store(length, storer);
store(pattern, storer);
}
template <class T>
void SendCodeHelper::AuthenticationCodeInfo::parse(T &parser) {
using td::parse;
int32 type_int;
parse(type_int, parser);
type = narrow_cast<decltype(type)>(type_int);
parse(type, parser);
parse(length, parser);
parse(pattern, parser);
}
@ -52,7 +50,7 @@ template <class T>
void AuthManager::DbState::store(T &storer) const {
using td::store;
CHECK(state_ == State::WaitCode);
store(static_cast<int32>(state_), storer);
store(state_, storer);
store(api_id_, storer);
store(api_hash_, storer);
store(send_code_helper_, storer);
@ -61,9 +59,7 @@ void AuthManager::DbState::store(T &storer) const {
template <class T>
void AuthManager::DbState::parse(T &parser) {
using td::parse;
int32 state;
parse(state, parser);
state_ = narrow_cast<State>(state);
parse(state_, parser);
parse(api_id_, parser);
parse(api_hash_, parser);
parse(send_code_helper_, parser);