diff --git a/td/mtproto/AuthData.h b/td/mtproto/AuthData.h index bf1f50d9c..0452d3d84 100644 --- a/td/mtproto/AuthData.h +++ b/td/mtproto/AuthData.h @@ -89,7 +89,7 @@ class AuthData { if (tmp_auth_key_.empty()) { return true; } - if (now > tmp_auth_key_.expire_at() - 60 * 60 * 2 /*2 hours*/) { + if (now > tmp_auth_key_.expires_at() - 60 * 60 * 2 /*2 hours*/) { return true; } if (!has_tmp_auth_key(now)) { @@ -110,7 +110,7 @@ class AuthData { if (tmp_auth_key_.empty()) { return false; } - if (now > tmp_auth_key_.expire_at() - 60 * 60 /*1 hour*/) { + if (now > tmp_auth_key_.expires_at() - 60 * 60 /*1 hour*/) { return false; } return true; diff --git a/td/mtproto/AuthKey.h b/td/mtproto/AuthKey.h index 4979d4b74..214e25301 100644 --- a/td/mtproto/AuthKey.h +++ b/td/mtproto/AuthKey.h @@ -44,12 +44,12 @@ class AuthKey { void set_need_header(bool need_header) { need_header_ = need_header; } - double expire_at() const { - return expire_at_; + double expires_at() const { + return expires_at_; } - void set_expire_at(double expire_at) { - expire_at_ = expire_at; - // expire_at_ = Time::now() + 60 * 60 + 10 * 60; + void set_expires_at(double expires_at) { + expires_at_ = expires_at; + // expires_at_ = Time::now() + 60 * 60 + 10 * 60; } void clear() { auth_key_.clear(); @@ -80,7 +80,7 @@ class AuthKey { bool auth_flag_ = false; bool was_auth_flag_ = false; bool need_header_ = true; - double expire_at_ = 0; + double expires_at_ = 0; }; } // namespace mtproto diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index 6afa277a5..377f63eb1 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -91,8 +91,8 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs case Mode::Temp: r_data_size = fill_data_with_hash( data_with_hash, - mtproto_api::p_q_inner_data_temp_dc(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, dc_id_, expire_in_)); - expire_at_ = Time::now() + expire_in_; + mtproto_api::p_q_inner_data_temp_dc(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, dc_id_, expires_in_)); + expires_at_ = Time::now() + expires_in_; break; case Mode::Unknown: default: @@ -209,7 +209,7 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection auth_key = AuthKey(auth_key_params.first, std::move(auth_key_params.second)); if (mode_ == Mode::Temp) { - auth_key.set_expire_at(expire_at_); + auth_key.set_expires_at(expires_at_); } server_salt = as(new_nonce.raw) ^ as(server_nonce.raw); @@ -252,9 +252,9 @@ Status AuthKeyHandshake::start_main(Callback *connection) { return on_start(connection); } -Status AuthKeyHandshake::start_tmp(Callback *connection, int32 expire_in) { +Status AuthKeyHandshake::start_tmp(Callback *connection, int32 expires_in) { mode_ = Mode::Temp; - expire_in_ = expire_in; + expires_in_ = expires_in; return on_start(connection); } diff --git a/td/mtproto/Handshake.h b/td/mtproto/Handshake.h index 7c28a514d..42d79c8a0 100644 --- a/td/mtproto/Handshake.h +++ b/td/mtproto/Handshake.h @@ -46,30 +46,30 @@ class AuthKeyHandshake { bool is_ready_for_start(); Status start_main(Callback *connection) TD_WARN_UNUSED_RESULT; - Status start_tmp(Callback *connection, int32 expire_in) TD_WARN_UNUSED_RESULT; + Status start_tmp(Callback *connection, int32 expires_in) TD_WARN_UNUSED_RESULT; bool is_ready_for_message(const UInt128 &message_nonce); bool is_ready_for_finish(); void on_finish(); - AuthKeyHandshake(int32 dc_id, int32 expire_in) { + AuthKeyHandshake(int32 dc_id, int32 expires_in) { dc_id_ = dc_id; - if (expire_in == 0) { + if (expires_in == 0) { mode_ = Mode::Main; } else { mode_ = Mode::Temp; - expire_in_ = expire_in; + expires_in_ = expires_in; } } void init_main() { clear(); mode_ = Mode::Main; } - void init_temp(int32 expire_in) { + void init_temp(int32 expires_in) { clear(); mode_ = Mode::Temp; - expire_in_ = expire_in; + expires_in_ = expires_in; } void resume(Callback *connection); Status on_message(Slice message, Callback *connection, Context *context) TD_WARN_UNUSED_RESULT; @@ -83,8 +83,8 @@ class AuthKeyHandshake { State state_ = Start; Mode mode_ = Mode::Unknown; int32 dc_id_ = 0; - int32 expire_in_ = 0; - double expire_at_ = 0; + int32 expires_in_ = 0; + double expires_at_ = 0; UInt128 nonce; UInt128 server_nonce; diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index b7e8e8ecc..47793f310 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -782,10 +782,10 @@ void SessionConnection::destroy_key() { need_destroy_auth_key_ = true; } -std::pair SessionConnection::encrypted_bind(int64 perm_key, int64 nonce, int32 expire_at) { +std::pair SessionConnection::encrypted_bind(int64 perm_key, int64 nonce, int32 expires_at) { int64 temp_key = auth_data_->get_tmp_auth_key().id(); - mtproto_api::bind_auth_key_inner object(nonce, temp_key, perm_key, auth_data_->get_session_id(), expire_at); + mtproto_api::bind_auth_key_inner object(nonce, temp_key, perm_key, auth_data_->get_session_id(), expires_at); auto object_storer = create_storer(object); auto size = object_storer.size(); auto object_packet = BufferWriter{size, 0, 0}; diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index ad7ad2839..77f7b62e3 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -71,7 +71,7 @@ class SessionConnection // Interface Result TD_WARN_UNUSED_RESULT send_query(BufferSlice buffer, bool gzip_flag, int64 message_id = 0, uint64 invoke_after_id = 0, bool use_quick_ack = false); - std::pair encrypted_bind(int64 perm_key, int64 nonce, int32 expire_at); + std::pair encrypted_bind(int64 perm_key, int64 nonce, int32 expires_at); void get_state_info(int64 message_id); void resend_answer(int64 message_id); diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 9f34a12fa..38d1aa1eb 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -388,10 +388,10 @@ class ConfigRecoverer : public Actor { is_online_ = is_online; if (is_online) { if (simple_config_.dc_options.empty()) { - simple_config_expire_at_ = 0; + simple_config_expires_at_ = 0; } if (full_config_ == nullptr) { - full_config_expire_at_ = 0; + full_config_expires_at_ = 0; } } loop(); @@ -451,7 +451,7 @@ class ConfigRecoverer : public Actor { VLOG(config_recoverer) << "Config has expired at " << config->expires_; } - simple_config_expire_at_ = get_config_expire_time(); + simple_config_expires_at_ = get_config_expire_time(); simple_config_at_ = Time::now_cached(); for (size_t i = 1; i < simple_config_.dc_options.size(); i++) { std::swap(simple_config_.dc_options[i], simple_config_.dc_options[Random::fast(0, static_cast(i))]); @@ -459,7 +459,7 @@ class ConfigRecoverer : public Actor { } else { VLOG(config_recoverer) << "Get SimpleConfig error " << r_simple_config.error(); simple_config_ = DcOptions(); - simple_config_expire_at_ = get_failed_config_expire_time(); + simple_config_expires_at_ = get_failed_config_expire_time(); } update_dc_options(); loop(); @@ -470,12 +470,12 @@ class ConfigRecoverer : public Actor { if (r_full_config.is_ok()) { full_config_ = r_full_config.move_as_ok(); VLOG(config_recoverer) << "Got FullConfig " << to_string(full_config_); - full_config_expire_at_ = get_config_expire_time(); + full_config_expires_at_ = get_config_expire_time(); send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(full_config_->dc_options_)); } else { VLOG(config_recoverer) << "Get FullConfig error " << r_full_config.error(); full_config_ = FullConfig(); - full_config_expire_at_ = get_failed_config_expire_time(); + full_config_expires_at_ = get_failed_config_expire_time(); } loop(); } @@ -506,7 +506,7 @@ class ConfigRecoverer : public Actor { uint32 network_generation_{0}; DcOptions simple_config_; - double simple_config_expire_at_{0}; + double simple_config_expires_at_{0}; double simple_config_at_{0}; ActorOwn<> simple_config_query_; @@ -517,7 +517,7 @@ class ConfigRecoverer : public Actor { size_t dc_options_i_; FullConfig full_config_; - double full_config_expire_at_{0}; + double full_config_expires_at_{0}; ActorOwn<> full_config_query_; uint32 ref_cnt_{1}; @@ -569,14 +569,14 @@ class ConfigRecoverer : public Actor { bool has_connecting_problem = is_connecting_ && check_timeout(Timestamp::at(connecting_since_ + max_connecting_delay())); - bool is_valid_simple_config = !check_timeout(Timestamp::at(simple_config_expire_at_)); + bool is_valid_simple_config = !check_timeout(Timestamp::at(simple_config_expires_at_)); if (!is_valid_simple_config && !simple_config_.dc_options.empty()) { simple_config_ = DcOptions(); update_dc_options(); } bool need_simple_config = has_connecting_problem && !is_valid_simple_config && simple_config_query_.empty(); bool has_dc_options = !dc_options_.dc_options.empty(); - bool is_valid_full_config = !check_timeout(Timestamp::at(full_config_expire_at_)); + bool is_valid_full_config = !check_timeout(Timestamp::at(full_config_expires_at_)); bool need_full_config = has_connecting_problem && has_dc_options && !is_valid_full_config && full_config_query_.empty() && check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10))); @@ -665,12 +665,12 @@ void ConfigManager::start_up() { config_recoverer_ = create_actor("Recoverer", actor_shared()); send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, load_dc_options_update()); // } - auto expire = load_config_expire(); - if (expire.is_in_past()) { + auto expire_time = load_config_expire_time(); + if (expire_time.is_in_past()) { request_config(); } else { - expire_ = expire; - set_timeout_in(expire_.in()); + expire_time_ = expire_time; + set_timeout_in(expire_time_.in()); } } @@ -684,9 +684,9 @@ void ConfigManager::hangup() { try_stop(); } void ConfigManager::loop() { - if (expire_ && expire_.is_in_past()) { + if (expire_time_ && expire_time_.is_in_past()) { request_config(); - expire_ = {}; + expire_time_ = {}; } } void ConfigManager::try_stop() { @@ -707,9 +707,9 @@ void ConfigManager::on_dc_options_update(DcOptions dc_options) { if (dc_options.dc_options.empty()) { return; } - expire_ = Timestamp::now(); - save_config_expire(expire_); - set_timeout_in(expire_.in()); + expire_time_ = Timestamp::now(); + save_config_expire(expire_time_); + set_timeout_in(expire_time_.in()); } void ConfigManager::request_config_from_dc_impl(DcId dc_id) { @@ -727,8 +727,8 @@ void ConfigManager::on_result(NetQueryPtr res) { if (r_config.is_error()) { if (!G()->close_flag()) { LOG(ERROR) << "TODO: getConfig failed: " << r_config.error(); - expire_ = Timestamp::in(60.0); // try again in a minute - set_timeout_in(expire_.in()); + expire_time_ = Timestamp::in(60.0); // try again in a minute + set_timeout_in(expire_time_.in()); } } else { on_dc_options_update(DcOptions()); @@ -753,18 +753,19 @@ DcOptions ConfigManager::load_dc_options_update() { return dc_options; } -Timestamp ConfigManager::load_config_expire() { - auto expire_in = to_integer(G()->td_db()->get_binlog_pmc()->get("config_expire")) - Clocks::system(); +Timestamp ConfigManager::load_config_expire_time() { + auto expires_in = to_integer(G()->td_db()->get_binlog_pmc()->get("config_expire")) - Clocks::system(); - if (expire_in < 0 || expire_in > 60 * 60 /* 1 hour */) { + if (expires_in < 0 || expires_in > 60 * 60 /* 1 hour */) { return Timestamp::now(); } else { - return Timestamp::in(expire_in); + return Timestamp::in(expires_in); } } void ConfigManager::save_config_expire(Timestamp timestamp) { - G()->td_db()->get_binlog_pmc()->set("config_expire", to_string(static_cast(Clocks::system() + expire_.in()))); + G()->td_db()->get_binlog_pmc()->set("config_expire", + to_string(static_cast(Clocks::system() + expire_time_.in()))); } void ConfigManager::process_config(tl_object_ptr config) { @@ -777,8 +778,8 @@ void ConfigManager::process_config(tl_object_ptr config) { if (!is_from_main_dc) { reload_in = 0; } - expire_ = Timestamp::in(reload_in); - set_timeout_at(expire_.at()); + expire_time_ = Timestamp::in(reload_in); + set_timeout_at(expire_time_.at()); LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test"; ConfigShared &shared_config = G()->shared_config(); diff --git a/td/telegram/ConfigManager.h b/td/telegram/ConfigManager.h index 6301dbd55..4aef5ccaa 100644 --- a/td/telegram/ConfigManager.h +++ b/td/telegram/ConfigManager.h @@ -55,7 +55,7 @@ class ConfigManager : public NetQueryCallback { int32 config_sent_cnt_{0}; ActorOwn config_recoverer_; int ref_cnt_{1}; - Timestamp expire_; + Timestamp expire_time_; void start_up() override; void hangup_shared() override; @@ -68,7 +68,7 @@ class ConfigManager : public NetQueryCallback { void request_config_from_dc_impl(DcId dc_id); void process_config(tl_object_ptr config); - Timestamp load_config_expire(); + Timestamp load_config_expire_time(); void save_config_expire(Timestamp timestamp); void save_dc_options_update(DcOptions dc_options); DcOptions load_dc_options_update(); diff --git a/td/telegram/MessagesDb.cpp b/td/telegram/MessagesDb.cpp index 453337fe5..53e4aecfb 100644 --- a/td/telegram/MessagesDb.cpp +++ b/td/telegram/MessagesDb.cpp @@ -491,8 +491,8 @@ class MessagesDbImpl : public MessagesDbSyncInterface { return Status::Error("Not found"); } - Result>, int32>> get_expiring_messages(int32 expire_from, - int32 expire_till, + Result>, int32>> get_expiring_messages(int32 expires_from, + int32 expires_till, int32 limit) override { SCOPE_EXIT { get_expiring_messages_stmt_.reset(); @@ -501,9 +501,9 @@ class MessagesDbImpl : public MessagesDbSyncInterface { std::vector> messages; // load messages - if (expire_from <= expire_till) { - get_expiring_messages_stmt_.bind_int32(1, expire_from).ensure(); - get_expiring_messages_stmt_.bind_int32(2, expire_till).ensure(); + if (expires_from <= expires_till) { + get_expiring_messages_stmt_.bind_int32(1, expires_from).ensure(); + get_expiring_messages_stmt_.bind_int32(2, expires_till).ensure(); get_expiring_messages_stmt_.step().ensure(); while (get_expiring_messages_stmt_.has_row()) { @@ -514,17 +514,17 @@ class MessagesDbImpl : public MessagesDbSyncInterface { } } - // calc next expire_till - get_expiring_messages_helper_stmt_.bind_int32(1, expire_till).ensure(); + // calc next expires_till + get_expiring_messages_helper_stmt_.bind_int32(1, expires_till).ensure(); get_expiring_messages_helper_stmt_.bind_int32(2, limit).ensure(); get_expiring_messages_helper_stmt_.step().ensure(); CHECK(get_expiring_messages_helper_stmt_.has_row()); int32 count = get_expiring_messages_helper_stmt_.view_int32(1); - int32 next_expire_till = -1; + int32 next_expires_till = -1; if (count != 0) { - next_expire_till = get_expiring_messages_helper_stmt_.view_int32(0); + next_expires_till = get_expiring_messages_helper_stmt_.view_int32(0); } - return std::make_pair(std::move(messages), next_expire_till); + return std::make_pair(std::move(messages), next_expires_till); } Result> get_messages(MessagesDbMessagesQuery query) override { @@ -921,9 +921,9 @@ class MessagesDbAsync : public MessagesDbAsyncInterface { send_closure_later(impl_, &Impl::get_messages_fts, std::move(query), std::move(promise)); } void get_expiring_messages( - int32 expire_from, int32 expire_till, int32 limit, + int32 expires_from, int32 expires_till, int32 limit, Promise>, int32>> promise) override { - send_closure_later(impl_, &Impl::get_expiring_messages, expire_from, expire_till, limit, std::move(promise)); + send_closure_later(impl_, &Impl::get_expiring_messages, expires_from, expires_till, limit, std::move(promise)); } void close(Promise<> promise) override { @@ -999,10 +999,10 @@ class MessagesDbAsync : public MessagesDbAsyncInterface { add_read_query(); promise.set_result(sync_db_->get_messages_fts(std::move(query))); } - void get_expiring_messages(int32 expire_from, int32 expire_till, int32 limit, + void get_expiring_messages(int32 expires_from, int32 expires_till, int32 limit, Promise>, int32>> promise) { add_read_query(); - promise.set_result(sync_db_->get_expiring_messages(expire_from, expire_till, limit)); + promise.set_result(sync_db_->get_expiring_messages(expires_from, expires_till, limit)); } void close(Promise<> promise) { diff --git a/td/telegram/MessagesDb.h b/td/telegram/MessagesDb.h index 88c4592a1..d9c657782 100644 --- a/td/telegram/MessagesDb.h +++ b/td/telegram/MessagesDb.h @@ -108,7 +108,7 @@ class MessagesDbSyncInterface { int32 limit) = 0; virtual Result>, int32>> get_expiring_messages( - int32 expire_from, int32 expire_till, int32 limit) = 0; + int32 expires_from, int32 expires_till, int32 limit) = 0; virtual Result get_calls(MessagesDbCallsQuery query) = 0; virtual Result get_messages_fts(MessagesDbFtsQuery query) = 0; @@ -156,7 +156,7 @@ class MessagesDbAsyncInterface { virtual void get_messages_fts(MessagesDbFtsQuery query, Promise promise) = 0; virtual void get_expiring_messages( - int32 expire_from, int32 expire_till, int32 limit, + int32 expires_from, int32 expires_till, int32 limit, Promise>, int32>> promise) = 0; virtual void close(Promise<> promise) = 0; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7d573974a..fcbadeb0c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8926,15 +8926,15 @@ void MessagesManager::init() { } void MessagesManager::ttl_db_loop_start(double server_now) { - ttl_db_expire_from_ = 0; - ttl_db_expire_till_ = static_cast(server_now) + 15 /* 15 seconds */; + ttl_db_expires_from_ = 0; + ttl_db_expires_till_ = static_cast(server_now) + 15 /* 15 seconds */; ttl_db_has_query_ = false; ttl_db_loop(server_now); } void MessagesManager::ttl_db_loop(double server_now) { - LOG(INFO) << "ttl_db: loop " << tag("expire_from", ttl_db_expire_from_) << tag("expire_till", ttl_db_expire_till_) + LOG(INFO) << "ttl_db: loop " << tag("expires_from", ttl_db_expires_from_) << tag("expires_till", ttl_db_expires_till_) << tag("has_query", ttl_db_has_query_); if (ttl_db_has_query_) { return; @@ -8942,14 +8942,14 @@ void MessagesManager::ttl_db_loop(double server_now) { auto now = static_cast(server_now); - if (ttl_db_expire_till_ < 0) { + if (ttl_db_expires_till_ < 0) { LOG(INFO) << "ttl_db: finished"; return; } - if (now < ttl_db_expire_from_) { + if (now < ttl_db_expires_from_) { ttl_db_slot_.set_event(EventCreator::yield(actor_shared(this, YieldType::TtlDb))); - auto wakeup_in = ttl_db_expire_from_ - server_now; + auto wakeup_in = ttl_db_expires_from_ - server_now; ttl_db_slot_.set_timeout_in(wakeup_in); LOG(INFO) << "ttl_db: " << tag("wakeup in", wakeup_in); return; @@ -8957,10 +8957,10 @@ void MessagesManager::ttl_db_loop(double server_now) { ttl_db_has_query_ = true; int32 limit = 50; - LOG(INFO) << "ttl_db: send query " << tag("expire_from", ttl_db_expire_from_) - << tag("expire_till", ttl_db_expire_till_) << tag("limit", limit); + LOG(INFO) << "ttl_db: send query " << tag("expires_from", ttl_db_expires_from_) + << tag("expires_till", ttl_db_expires_till_) << tag("limit", limit); G()->td_db()->get_messages_db_async()->get_expiring_messages( - ttl_db_expire_from_, ttl_db_expire_till_, limit, + ttl_db_expires_from_, ttl_db_expires_till_, limit, PromiseCreator::lambda( [actor_id = actor_id(this)](Result>, int32>> result) { send_closure(actor_id, &MessagesManager::ttl_db_on_result, std::move(result), false); @@ -8971,10 +8971,10 @@ void MessagesManager::ttl_db_on_result(Result(auth_data_.get_server_time(auth_data_.get_tmp_auth_key().expire_at())); + int32 expires_at = static_cast(auth_data_.get_server_time(auth_data_.get_tmp_auth_key().expires_at())); int64 message_id; BufferSlice encrypted; - std::tie(message_id, encrypted) = info->connection->encrypted_bind(perm_auth_key_id, nonce, expire_at); + std::tie(message_id, encrypted) = info->connection->encrypted_bind(perm_auth_key_id, nonce, expires_at); LOG(INFO) << "Bind key: " << tag("tmp", key_id) << tag("perm", static_cast(perm_auth_key_id)); NetQueryPtr query = G()->net_query_creator().create( last_bind_id_, - create_storer(telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expire_at, std::move(encrypted)))); + create_storer(telegram_api::auth_bindTempAuthKey(perm_auth_key_id, nonce, expires_at, std::move(encrypted)))); query->dispatch_ttl = 0; query->set_callback(actor_shared(this)); connection_send_query(info, std::move(query), message_id); diff --git a/tdactor/td/actor/impl/Scheduler.cpp b/tdactor/td/actor/impl/Scheduler.cpp index e9ea181a8..3939b44e4 100644 --- a/tdactor/td/actor/impl/Scheduler.cpp +++ b/tdactor/td/actor/impl/Scheduler.cpp @@ -423,8 +423,8 @@ void Scheduler::set_actor_timeout_in(ActorInfo *actor_info, double timeout) { if (timeout < 0) { timeout = 0; } - double expire_at = Time::now() + timeout; - set_actor_timeout_at(actor_info, expire_at); + double expires_at = Time::now() + timeout; + set_actor_timeout_at(actor_info, expires_at); } void Scheduler::set_actor_timeout_at(ActorInfo *actor_info, double timeout_at) {