From 061ca24be9bac47b367ba0c6ec7c914c8661525a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 19 Jul 2021 05:09:20 +0300 Subject: [PATCH] Simplify AuthKeyHandshake constructor. --- td/mtproto/Handshake.cpp | 5 ++++- td/mtproto/Handshake.h | 17 ++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index 042037789..1ec70aef2 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -46,6 +46,10 @@ static Result fetch_result(Slice message, bool check_end return std::move(result); } +AuthKeyHandshake::AuthKeyHandshake(int32 dc_id, int32 expires_in) + : mode_(expires_in == 0 ? Mode::Main : Mode::Temp), dc_id_(dc_id), expires_in_(expires_in) { +} + void AuthKeyHandshake::clear() { last_query_ = BufferSlice(); state_ = Start; @@ -100,7 +104,6 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs dc_id_, expires_in_)); expires_at_ = Time::now() + expires_in_; break; - case Mode::Unknown: default: UNREACHABLE(); } diff --git a/td/mtproto/Handshake.h b/td/mtproto/Handshake.h index 72245bae9..14077b546 100644 --- a/td/mtproto/Handshake.h +++ b/td/mtproto/Handshake.h @@ -33,8 +33,6 @@ class AuthKeyHandshakeContext { }; class AuthKeyHandshake { - enum class Mode { Unknown, Main, Temp }; - public: class Callback { public: @@ -45,15 +43,7 @@ class AuthKeyHandshake { virtual void send_no_crypto(const Storer &storer) = 0; }; - AuthKeyHandshake(int32 dc_id, int32 expires_in) { - dc_id_ = dc_id; - if (expires_in == 0) { - mode_ = Mode::Main; - } else { - mode_ = Mode::Temp; - expires_in_ = expires_in; - } - } + AuthKeyHandshake(int32 dc_id, int32 expires_in); bool is_ready_for_finish() const; @@ -82,9 +72,10 @@ class AuthKeyHandshake { } private: - using State = enum { Start, ResPQ, ServerDHParams, DHGenResponse, Finish }; + enum State : int32 { Start, ResPQ, ServerDHParams, DHGenResponse, Finish }; State state_ = Start; - Mode mode_ = Mode::Unknown; + enum class Mode : int32 { Main, Temp }; + Mode mode_ = Mode::Main; int32 dc_id_ = 0; int32 expires_in_ = 0; double expires_at_ = 0;