Unify spelling of "expires_".

GitOrigin-RevId: 46aaff38317dd490f9d5a1250e426d94cb8aba75
This commit is contained in:
levlam 2019-02-10 03:45:15 +03:00
parent d1022a389b
commit 0075f91e2e
15 changed files with 92 additions and 91 deletions

View File

@ -89,7 +89,7 @@ class AuthData {
if (tmp_auth_key_.empty()) { if (tmp_auth_key_.empty()) {
return true; 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; return true;
} }
if (!has_tmp_auth_key(now)) { if (!has_tmp_auth_key(now)) {
@ -110,7 +110,7 @@ class AuthData {
if (tmp_auth_key_.empty()) { if (tmp_auth_key_.empty()) {
return false; 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 false;
} }
return true; return true;

View File

@ -44,12 +44,12 @@ class AuthKey {
void set_need_header(bool need_header) { void set_need_header(bool need_header) {
need_header_ = need_header; need_header_ = need_header;
} }
double expire_at() const { double expires_at() const {
return expire_at_; return expires_at_;
} }
void set_expire_at(double expire_at) { void set_expires_at(double expires_at) {
expire_at_ = expire_at; expires_at_ = expires_at;
// expire_at_ = Time::now() + 60 * 60 + 10 * 60; // expires_at_ = Time::now() + 60 * 60 + 10 * 60;
} }
void clear() { void clear() {
auth_key_.clear(); auth_key_.clear();
@ -80,7 +80,7 @@ class AuthKey {
bool auth_flag_ = false; bool auth_flag_ = false;
bool was_auth_flag_ = false; bool was_auth_flag_ = false;
bool need_header_ = true; bool need_header_ = true;
double expire_at_ = 0; double expires_at_ = 0;
}; };
} // namespace mtproto } // namespace mtproto

View File

@ -91,8 +91,8 @@ Status AuthKeyHandshake::on_res_pq(Slice message, Callback *connection, PublicRs
case Mode::Temp: case Mode::Temp:
r_data_size = fill_data_with_hash( r_data_size = fill_data_with_hash(
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_)); mtproto_api::p_q_inner_data_temp_dc(res_pq->pq_, p, q, nonce, server_nonce, new_nonce, dc_id_, expires_in_));
expire_at_ = Time::now() + expire_in_; expires_at_ = Time::now() + expires_in_;
break; break;
case Mode::Unknown: case Mode::Unknown:
default: 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)); auth_key = AuthKey(auth_key_params.first, std::move(auth_key_params.second));
if (mode_ == Mode::Temp) { if (mode_ == Mode::Temp) {
auth_key.set_expire_at(expire_at_); auth_key.set_expires_at(expires_at_);
} }
server_salt = as<int64>(new_nonce.raw) ^ as<int64>(server_nonce.raw); server_salt = as<int64>(new_nonce.raw) ^ as<int64>(server_nonce.raw);
@ -252,9 +252,9 @@ Status AuthKeyHandshake::start_main(Callback *connection) {
return on_start(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; mode_ = Mode::Temp;
expire_in_ = expire_in; expires_in_ = expires_in;
return on_start(connection); return on_start(connection);
} }

View File

@ -46,30 +46,30 @@ class AuthKeyHandshake {
bool is_ready_for_start(); bool is_ready_for_start();
Status start_main(Callback *connection) TD_WARN_UNUSED_RESULT; 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_message(const UInt128 &message_nonce);
bool is_ready_for_finish(); bool is_ready_for_finish();
void on_finish(); void on_finish();
AuthKeyHandshake(int32 dc_id, int32 expire_in) { AuthKeyHandshake(int32 dc_id, int32 expires_in) {
dc_id_ = dc_id; dc_id_ = dc_id;
if (expire_in == 0) { if (expires_in == 0) {
mode_ = Mode::Main; mode_ = Mode::Main;
} else { } else {
mode_ = Mode::Temp; mode_ = Mode::Temp;
expire_in_ = expire_in; expires_in_ = expires_in;
} }
} }
void init_main() { void init_main() {
clear(); clear();
mode_ = Mode::Main; mode_ = Mode::Main;
} }
void init_temp(int32 expire_in) { void init_temp(int32 expires_in) {
clear(); clear();
mode_ = Mode::Temp; mode_ = Mode::Temp;
expire_in_ = expire_in; expires_in_ = expires_in;
} }
void resume(Callback *connection); void resume(Callback *connection);
Status on_message(Slice message, Callback *connection, Context *context) TD_WARN_UNUSED_RESULT; Status on_message(Slice message, Callback *connection, Context *context) TD_WARN_UNUSED_RESULT;
@ -83,8 +83,8 @@ class AuthKeyHandshake {
State state_ = Start; State state_ = Start;
Mode mode_ = Mode::Unknown; Mode mode_ = Mode::Unknown;
int32 dc_id_ = 0; int32 dc_id_ = 0;
int32 expire_in_ = 0; int32 expires_in_ = 0;
double expire_at_ = 0; double expires_at_ = 0;
UInt128 nonce; UInt128 nonce;
UInt128 server_nonce; UInt128 server_nonce;

View File

@ -782,10 +782,10 @@ void SessionConnection::destroy_key() {
need_destroy_auth_key_ = true; need_destroy_auth_key_ = true;
} }
std::pair<uint64, BufferSlice> SessionConnection::encrypted_bind(int64 perm_key, int64 nonce, int32 expire_at) { std::pair<uint64, BufferSlice> SessionConnection::encrypted_bind(int64 perm_key, int64 nonce, int32 expires_at) {
int64 temp_key = auth_data_->get_tmp_auth_key().id(); 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 object_storer = create_storer(object);
auto size = object_storer.size(); auto size = object_storer.size();
auto object_packet = BufferWriter{size, 0, 0}; auto object_packet = BufferWriter{size, 0, 0};

View File

@ -71,7 +71,7 @@ class SessionConnection
// Interface // Interface
Result<uint64> TD_WARN_UNUSED_RESULT send_query(BufferSlice buffer, bool gzip_flag, int64 message_id = 0, Result<uint64> 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); uint64 invoke_after_id = 0, bool use_quick_ack = false);
std::pair<uint64, BufferSlice> encrypted_bind(int64 perm_key, int64 nonce, int32 expire_at); std::pair<uint64, BufferSlice> encrypted_bind(int64 perm_key, int64 nonce, int32 expires_at);
void get_state_info(int64 message_id); void get_state_info(int64 message_id);
void resend_answer(int64 message_id); void resend_answer(int64 message_id);

View File

@ -388,10 +388,10 @@ class ConfigRecoverer : public Actor {
is_online_ = is_online; is_online_ = is_online;
if (is_online) { if (is_online) {
if (simple_config_.dc_options.empty()) { if (simple_config_.dc_options.empty()) {
simple_config_expire_at_ = 0; simple_config_expires_at_ = 0;
} }
if (full_config_ == nullptr) { if (full_config_ == nullptr) {
full_config_expire_at_ = 0; full_config_expires_at_ = 0;
} }
} }
loop(); loop();
@ -451,7 +451,7 @@ class ConfigRecoverer : public Actor {
VLOG(config_recoverer) << "Config has expired at " << config->expires_; 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(); simple_config_at_ = Time::now_cached();
for (size_t i = 1; i < simple_config_.dc_options.size(); i++) { 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<int>(i))]); std::swap(simple_config_.dc_options[i], simple_config_.dc_options[Random::fast(0, static_cast<int>(i))]);
@ -459,7 +459,7 @@ class ConfigRecoverer : public Actor {
} else { } else {
VLOG(config_recoverer) << "Get SimpleConfig error " << r_simple_config.error(); VLOG(config_recoverer) << "Get SimpleConfig error " << r_simple_config.error();
simple_config_ = DcOptions(); simple_config_ = DcOptions();
simple_config_expire_at_ = get_failed_config_expire_time(); simple_config_expires_at_ = get_failed_config_expire_time();
} }
update_dc_options(); update_dc_options();
loop(); loop();
@ -470,12 +470,12 @@ class ConfigRecoverer : public Actor {
if (r_full_config.is_ok()) { if (r_full_config.is_ok()) {
full_config_ = r_full_config.move_as_ok(); full_config_ = r_full_config.move_as_ok();
VLOG(config_recoverer) << "Got FullConfig " << to_string(full_config_); 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_)); send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(full_config_->dc_options_));
} else { } else {
VLOG(config_recoverer) << "Get FullConfig error " << r_full_config.error(); VLOG(config_recoverer) << "Get FullConfig error " << r_full_config.error();
full_config_ = FullConfig(); full_config_ = FullConfig();
full_config_expire_at_ = get_failed_config_expire_time(); full_config_expires_at_ = get_failed_config_expire_time();
} }
loop(); loop();
} }
@ -506,7 +506,7 @@ class ConfigRecoverer : public Actor {
uint32 network_generation_{0}; uint32 network_generation_{0};
DcOptions simple_config_; DcOptions simple_config_;
double simple_config_expire_at_{0}; double simple_config_expires_at_{0};
double simple_config_at_{0}; double simple_config_at_{0};
ActorOwn<> simple_config_query_; ActorOwn<> simple_config_query_;
@ -517,7 +517,7 @@ class ConfigRecoverer : public Actor {
size_t dc_options_i_; size_t dc_options_i_;
FullConfig full_config_; FullConfig full_config_;
double full_config_expire_at_{0}; double full_config_expires_at_{0};
ActorOwn<> full_config_query_; ActorOwn<> full_config_query_;
uint32 ref_cnt_{1}; uint32 ref_cnt_{1};
@ -569,14 +569,14 @@ class ConfigRecoverer : public Actor {
bool has_connecting_problem = bool has_connecting_problem =
is_connecting_ && check_timeout(Timestamp::at(connecting_since_ + max_connecting_delay())); 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()) { if (!is_valid_simple_config && !simple_config_.dc_options.empty()) {
simple_config_ = DcOptions(); simple_config_ = DcOptions();
update_dc_options(); update_dc_options();
} }
bool need_simple_config = has_connecting_problem && !is_valid_simple_config && simple_config_query_.empty(); 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 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 && bool need_full_config = has_connecting_problem && has_dc_options && !is_valid_full_config &&
full_config_query_.empty() && full_config_query_.empty() &&
check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10))); check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10)));
@ -665,12 +665,12 @@ void ConfigManager::start_up() {
config_recoverer_ = create_actor<ConfigRecoverer>("Recoverer", actor_shared()); config_recoverer_ = create_actor<ConfigRecoverer>("Recoverer", actor_shared());
send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, load_dc_options_update()); send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, load_dc_options_update());
// } // }
auto expire = load_config_expire(); auto expire_time = load_config_expire_time();
if (expire.is_in_past()) { if (expire_time.is_in_past()) {
request_config(); request_config();
} else { } else {
expire_ = expire; expire_time_ = expire_time;
set_timeout_in(expire_.in()); set_timeout_in(expire_time_.in());
} }
} }
@ -684,9 +684,9 @@ void ConfigManager::hangup() {
try_stop(); try_stop();
} }
void ConfigManager::loop() { void ConfigManager::loop() {
if (expire_ && expire_.is_in_past()) { if (expire_time_ && expire_time_.is_in_past()) {
request_config(); request_config();
expire_ = {}; expire_time_ = {};
} }
} }
void ConfigManager::try_stop() { void ConfigManager::try_stop() {
@ -707,9 +707,9 @@ void ConfigManager::on_dc_options_update(DcOptions dc_options) {
if (dc_options.dc_options.empty()) { if (dc_options.dc_options.empty()) {
return; return;
} }
expire_ = Timestamp::now(); expire_time_ = Timestamp::now();
save_config_expire(expire_); save_config_expire(expire_time_);
set_timeout_in(expire_.in()); set_timeout_in(expire_time_.in());
} }
void ConfigManager::request_config_from_dc_impl(DcId dc_id) { 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 (r_config.is_error()) {
if (!G()->close_flag()) { if (!G()->close_flag()) {
LOG(ERROR) << "TODO: getConfig failed: " << r_config.error(); LOG(ERROR) << "TODO: getConfig failed: " << r_config.error();
expire_ = Timestamp::in(60.0); // try again in a minute expire_time_ = Timestamp::in(60.0); // try again in a minute
set_timeout_in(expire_.in()); set_timeout_in(expire_time_.in());
} }
} else { } else {
on_dc_options_update(DcOptions()); on_dc_options_update(DcOptions());
@ -753,18 +753,19 @@ DcOptions ConfigManager::load_dc_options_update() {
return dc_options; return dc_options;
} }
Timestamp ConfigManager::load_config_expire() { Timestamp ConfigManager::load_config_expire_time() {
auto expire_in = to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("config_expire")) - Clocks::system(); auto expires_in = to_integer<int32>(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(); return Timestamp::now();
} else { } else {
return Timestamp::in(expire_in); return Timestamp::in(expires_in);
} }
} }
void ConfigManager::save_config_expire(Timestamp timestamp) { void ConfigManager::save_config_expire(Timestamp timestamp) {
G()->td_db()->get_binlog_pmc()->set("config_expire", to_string(static_cast<int>(Clocks::system() + expire_.in()))); G()->td_db()->get_binlog_pmc()->set("config_expire",
to_string(static_cast<int>(Clocks::system() + expire_time_.in())));
} }
void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) { void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
@ -777,8 +778,8 @@ void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
if (!is_from_main_dc) { if (!is_from_main_dc) {
reload_in = 0; reload_in = 0;
} }
expire_ = Timestamp::in(reload_in); expire_time_ = Timestamp::in(reload_in);
set_timeout_at(expire_.at()); set_timeout_at(expire_time_.at());
LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test"; LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test";
ConfigShared &shared_config = G()->shared_config(); ConfigShared &shared_config = G()->shared_config();

View File

@ -55,7 +55,7 @@ class ConfigManager : public NetQueryCallback {
int32 config_sent_cnt_{0}; int32 config_sent_cnt_{0};
ActorOwn<ConfigRecoverer> config_recoverer_; ActorOwn<ConfigRecoverer> config_recoverer_;
int ref_cnt_{1}; int ref_cnt_{1};
Timestamp expire_; Timestamp expire_time_;
void start_up() override; void start_up() override;
void hangup_shared() override; void hangup_shared() override;
@ -68,7 +68,7 @@ class ConfigManager : public NetQueryCallback {
void request_config_from_dc_impl(DcId dc_id); void request_config_from_dc_impl(DcId dc_id);
void process_config(tl_object_ptr<telegram_api::config> config); void process_config(tl_object_ptr<telegram_api::config> config);
Timestamp load_config_expire(); Timestamp load_config_expire_time();
void save_config_expire(Timestamp timestamp); void save_config_expire(Timestamp timestamp);
void save_dc_options_update(DcOptions dc_options); void save_dc_options_update(DcOptions dc_options);
DcOptions load_dc_options_update(); DcOptions load_dc_options_update();

View File

@ -491,8 +491,8 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
return Status::Error("Not found"); return Status::Error("Not found");
} }
Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> get_expiring_messages(int32 expire_from, Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> get_expiring_messages(int32 expires_from,
int32 expire_till, int32 expires_till,
int32 limit) override { int32 limit) override {
SCOPE_EXIT { SCOPE_EXIT {
get_expiring_messages_stmt_.reset(); get_expiring_messages_stmt_.reset();
@ -501,9 +501,9 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
std::vector<std::pair<DialogId, BufferSlice>> messages; std::vector<std::pair<DialogId, BufferSlice>> messages;
// load messages // load messages
if (expire_from <= expire_till) { if (expires_from <= expires_till) {
get_expiring_messages_stmt_.bind_int32(1, expire_from).ensure(); get_expiring_messages_stmt_.bind_int32(1, expires_from).ensure();
get_expiring_messages_stmt_.bind_int32(2, expire_till).ensure(); get_expiring_messages_stmt_.bind_int32(2, expires_till).ensure();
get_expiring_messages_stmt_.step().ensure(); get_expiring_messages_stmt_.step().ensure();
while (get_expiring_messages_stmt_.has_row()) { while (get_expiring_messages_stmt_.has_row()) {
@ -514,17 +514,17 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
} }
} }
// calc next expire_till // calc next expires_till
get_expiring_messages_helper_stmt_.bind_int32(1, expire_till).ensure(); 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_.bind_int32(2, limit).ensure();
get_expiring_messages_helper_stmt_.step().ensure(); get_expiring_messages_helper_stmt_.step().ensure();
CHECK(get_expiring_messages_helper_stmt_.has_row()); CHECK(get_expiring_messages_helper_stmt_.has_row());
int32 count = get_expiring_messages_helper_stmt_.view_int32(1); int32 count = get_expiring_messages_helper_stmt_.view_int32(1);
int32 next_expire_till = -1; int32 next_expires_till = -1;
if (count != 0) { 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<std::vector<BufferSlice>> get_messages(MessagesDbMessagesQuery query) override { Result<std::vector<BufferSlice>> 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)); send_closure_later(impl_, &Impl::get_messages_fts, std::move(query), std::move(promise));
} }
void get_expiring_messages( void get_expiring_messages(
int32 expire_from, int32 expire_till, int32 limit, int32 expires_from, int32 expires_till, int32 limit,
Promise<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> promise) override { Promise<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, 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 { void close(Promise<> promise) override {
@ -999,10 +999,10 @@ class MessagesDbAsync : public MessagesDbAsyncInterface {
add_read_query(); add_read_query();
promise.set_result(sync_db_->get_messages_fts(std::move(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<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> promise) { Promise<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> promise) {
add_read_query(); 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) { void close(Promise<> promise) {

View File

@ -108,7 +108,7 @@ class MessagesDbSyncInterface {
int32 limit) = 0; int32 limit) = 0;
virtual Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> get_expiring_messages( virtual Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> get_expiring_messages(
int32 expire_from, int32 expire_till, int32 limit) = 0; int32 expires_from, int32 expires_till, int32 limit) = 0;
virtual Result<MessagesDbCallsResult> get_calls(MessagesDbCallsQuery query) = 0; virtual Result<MessagesDbCallsResult> get_calls(MessagesDbCallsQuery query) = 0;
virtual Result<MessagesDbFtsResult> get_messages_fts(MessagesDbFtsQuery query) = 0; virtual Result<MessagesDbFtsResult> get_messages_fts(MessagesDbFtsQuery query) = 0;
@ -156,7 +156,7 @@ class MessagesDbAsyncInterface {
virtual void get_messages_fts(MessagesDbFtsQuery query, Promise<MessagesDbFtsResult> promise) = 0; virtual void get_messages_fts(MessagesDbFtsQuery query, Promise<MessagesDbFtsResult> promise) = 0;
virtual void get_expiring_messages( virtual void get_expiring_messages(
int32 expire_from, int32 expire_till, int32 limit, int32 expires_from, int32 expires_till, int32 limit,
Promise<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> promise) = 0; Promise<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> promise) = 0;
virtual void close(Promise<> promise) = 0; virtual void close(Promise<> promise) = 0;

View File

@ -8926,15 +8926,15 @@ void MessagesManager::init() {
} }
void MessagesManager::ttl_db_loop_start(double server_now) { void MessagesManager::ttl_db_loop_start(double server_now) {
ttl_db_expire_from_ = 0; ttl_db_expires_from_ = 0;
ttl_db_expire_till_ = static_cast<int32>(server_now) + 15 /* 15 seconds */; ttl_db_expires_till_ = static_cast<int32>(server_now) + 15 /* 15 seconds */;
ttl_db_has_query_ = false; ttl_db_has_query_ = false;
ttl_db_loop(server_now); ttl_db_loop(server_now);
} }
void MessagesManager::ttl_db_loop(double 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_); << tag("has_query", ttl_db_has_query_);
if (ttl_db_has_query_) { if (ttl_db_has_query_) {
return; return;
@ -8942,14 +8942,14 @@ void MessagesManager::ttl_db_loop(double server_now) {
auto now = static_cast<int32>(server_now); auto now = static_cast<int32>(server_now);
if (ttl_db_expire_till_ < 0) { if (ttl_db_expires_till_ < 0) {
LOG(INFO) << "ttl_db: finished"; LOG(INFO) << "ttl_db: finished";
return; 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))); 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); ttl_db_slot_.set_timeout_in(wakeup_in);
LOG(INFO) << "ttl_db: " << tag("wakeup in", wakeup_in); LOG(INFO) << "ttl_db: " << tag("wakeup in", wakeup_in);
return; return;
@ -8957,10 +8957,10 @@ void MessagesManager::ttl_db_loop(double server_now) {
ttl_db_has_query_ = true; ttl_db_has_query_ = true;
int32 limit = 50; int32 limit = 50;
LOG(INFO) << "ttl_db: send query " << tag("expire_from", ttl_db_expire_from_) LOG(INFO) << "ttl_db: send query " << tag("expires_from", ttl_db_expires_from_)
<< tag("expire_till", ttl_db_expire_till_) << tag("limit", limit); << tag("expires_till", ttl_db_expires_till_) << tag("limit", limit);
G()->td_db()->get_messages_db_async()->get_expiring_messages( 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( PromiseCreator::lambda(
[actor_id = actor_id(this)](Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> result) { [actor_id = actor_id(this)](Result<std::pair<std::vector<std::pair<DialogId, BufferSlice>>, int32>> result) {
send_closure(actor_id, &MessagesManager::ttl_db_on_result, std::move(result), false); send_closure(actor_id, &MessagesManager::ttl_db_on_result, std::move(result), false);
@ -8971,10 +8971,10 @@ void MessagesManager::ttl_db_on_result(Result<std::pair<std::vector<std::pair<Di
bool dummy) { bool dummy) {
auto result = r_result.move_as_ok(); auto result = r_result.move_as_ok();
ttl_db_has_query_ = false; ttl_db_has_query_ = false;
ttl_db_expire_from_ = ttl_db_expire_till_; ttl_db_expires_from_ = ttl_db_expires_till_;
ttl_db_expire_till_ = result.second; ttl_db_expires_till_ = result.second;
LOG(INFO) << "ttl_db: query result " << tag("new expire_till", ttl_db_expire_till_) LOG(INFO) << "ttl_db: query result " << tag("new expires_till", ttl_db_expires_till_)
<< tag("got messages", result.first.size()); << tag("got messages", result.first.size());
for (auto &dialog_message : result.first) { for (auto &dialog_message : result.first) {
on_get_message_from_database(dialog_message.first, get_dialog_force(dialog_message.first), dialog_message.second, on_get_message_from_database(dialog_message.first, get_dialog_force(dialog_message.first), dialog_message.second,

View File

@ -2127,8 +2127,8 @@ class MessagesManager : public Actor {
Slot ttl_slot_; Slot ttl_slot_;
enum YieldType : int32 { None, Ttl, TtlDb }; // None must be first enum YieldType : int32 { None, Ttl, TtlDb }; // None must be first
int32 ttl_db_expire_from_; int32 ttl_db_expires_from_;
int32 ttl_db_expire_till_; int32 ttl_db_expires_till_;
bool ttl_db_has_query_; bool ttl_db_has_query_;
Slot ttl_db_slot_; Slot ttl_db_slot_;

View File

@ -926,8 +926,8 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
// Remove expired ready connections // Remove expired ready connections
client.ready_connections.erase( client.ready_connections.erase(
std::remove_if(client.ready_connections.begin(), client.ready_connections.end(), std::remove_if(client.ready_connections.begin(), client.ready_connections.end(),
[&, expire_at = Time::now_cached() - ClientInfo::READY_CONNECTIONS_TIMEOUT](auto &v) { [&, expires_at = Time::now_cached() - ClientInfo::READY_CONNECTIONS_TIMEOUT](auto &v) {
bool drop = v.second < expire_at; bool drop = v.second < expires_at;
VLOG_IF(connections, drop) << "Drop expired " << tag("connection", v.first.get()); VLOG_IF(connections, drop) << "Drop expired " << tag("connection", v.first.get());
return drop; return drop;
}), }),

View File

@ -1024,15 +1024,15 @@ bool Session::connection_send_bind_key(ConnectionInfo *info) {
int64 perm_auth_key_id = auth_data_.get_main_auth_key().id(); int64 perm_auth_key_id = auth_data_.get_main_auth_key().id();
int64 nonce = Random::secure_int64(); int64 nonce = Random::secure_int64();
int32 expire_at = static_cast<int32>(auth_data_.get_server_time(auth_data_.get_tmp_auth_key().expire_at())); int32 expires_at = static_cast<int32>(auth_data_.get_server_time(auth_data_.get_tmp_auth_key().expires_at()));
int64 message_id; int64 message_id;
BufferSlice encrypted; 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<uint64>(perm_auth_key_id)); LOG(INFO) << "Bind key: " << tag("tmp", key_id) << tag("perm", static_cast<uint64>(perm_auth_key_id));
NetQueryPtr query = G()->net_query_creator().create( NetQueryPtr query = G()->net_query_creator().create(
last_bind_id_, 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->dispatch_ttl = 0;
query->set_callback(actor_shared(this)); query->set_callback(actor_shared(this));
connection_send_query(info, std::move(query), message_id); connection_send_query(info, std::move(query), message_id);

View File

@ -423,8 +423,8 @@ void Scheduler::set_actor_timeout_in(ActorInfo *actor_info, double timeout) {
if (timeout < 0) { if (timeout < 0) {
timeout = 0; timeout = 0;
} }
double expire_at = Time::now() + timeout; double expires_at = Time::now() + timeout;
set_actor_timeout_at(actor_info, expire_at); set_actor_timeout_at(actor_info, expires_at);
} }
void Scheduler::set_actor_timeout_at(ActorInfo *actor_info, double timeout_at) { void Scheduler::set_actor_timeout_at(ActorInfo *actor_info, double timeout_at) {