Send updates for "unix_time" option.

GitOrigin-RevId: 08f48634a02602060d55b8b8628e20d7d2618381
This commit is contained in:
levlam 2020-01-08 23:41:03 +03:00
parent 1b1bd481e3
commit 53da415b5c
5 changed files with 41 additions and 12 deletions

View File

@ -224,6 +224,7 @@ function split_file($file, $chunks, $undo) {
'std::reverse' => 'algorithm',
'std::rotate' => 'algorithm',
'std::sort' => 'algorithm',
'std::abs' => 'cmath',
'std::numeric_limits' => 'limits',
'std::make_shared' => 'memory',
'std::shared_ptr' => 'memory',

View File

@ -331,7 +331,7 @@ Status SessionConnection::on_packet(const MsgInfo &info,
InvalidContainer = 64
};
Slice common = " BUG! CALL FOR A DEVELOPER! Session will be closed";
Slice common = ". BUG! CALL FOR A DEVELOPER! Session will be closed";
switch (bad_msg_notification.error_code_) {
case MsgIdTooLow: {
LOG(WARNING) << bad_info << ": MessageId is too low. Message will be re-sent";
@ -340,18 +340,18 @@ Status SessionConnection::on_packet(const MsgInfo &info,
break;
}
case MsgIdTooHigh: {
LOG(ERROR) << bad_info << ": MessageId is too high. Session will be closed";
LOG(WARNING) << bad_info << ": MessageId is too high. Session will be closed";
// All this queries will be re-sent by parent
to_send_.clear();
callback_->on_session_failed(Status::Error("MessageId is too high"));
return Status::Error("MessageId is too high");
}
case MsgIdMod4: {
LOG(ERROR) << bad_info << ": MessageId is not divisible by 4." << common;
LOG(ERROR) << bad_info << ": MessageId is not divisible by 4" << common;
return Status::Error("MessageId is not divisible by 4");
}
case MsgIdCollision: {
LOG(ERROR) << bad_info << ": Container and older message MessageId collision." << common;
LOG(ERROR) << bad_info << ": Container and older message MessageId collision" << common;
return Status::Error("Container and older message MessageId collision");
}
@ -362,29 +362,29 @@ Status SessionConnection::on_packet(const MsgInfo &info,
}
case SeqNoTooLow: {
LOG(ERROR) << bad_info << ": SeqNo is too low." << common;
LOG(ERROR) << bad_info << ": SeqNo is too low" << common;
return Status::Error("SeqNo is too low");
}
case SeqNoTooHigh: {
LOG(ERROR) << bad_info << ": SeqNo is too high." << common;
LOG(ERROR) << bad_info << ": SeqNo is too high" << common;
return Status::Error("SeqNo is too high");
}
case SeqNoNotEven: {
LOG(ERROR) << bad_info << ": SeqNo is not even for an irrelevant message." << common;
LOG(ERROR) << bad_info << ": SeqNo is not even for an irrelevant message" << common;
return Status::Error("SeqNo is not even for an irrelevant message");
}
case SeqNoNotOdd: {
LOG(ERROR) << bad_info << ": SeqNo is not odd for an irrelevant message." << common;
LOG(ERROR) << bad_info << ": SeqNo is not odd for an irrelevant message" << common;
return Status::Error("SeqNo is not odd for an irrelevant message");
}
case InvalidContainer: {
LOG(ERROR) << bad_info << ": Invalid Contailer." << common;
LOG(ERROR) << bad_info << ": Invalid Contailer" << common;
return Status::Error("Invalid Contailer");
}
default: {
LOG(ERROR) << bad_info << ": Unknown error [code:" << bad_msg_notification.error_code_ << "]." << common;
LOG(ERROR) << bad_info << ": Unknown error [code:" << bad_msg_notification.error_code_ << "]" << common;
return Status::Error("Unknown error code");
}
}

View File

@ -12,6 +12,7 @@
#include "td/telegram/net/NetQueryDispatcher.h"
#include "td/telegram/net/TempAuthKeyWatchdog.h"
#include "td/telegram/StateManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
#include "td/actor/PromiseFuture.h"
@ -138,6 +139,9 @@ void Global::update_server_time_difference(double diff) {
server_time_difference_ = diff;
server_time_difference_was_updated_ = true;
do_save_server_time_difference();
CHECK(Scheduler::instance());
send_closure(td(), &Td::on_update_server_time_difference);
}
}

View File

@ -121,6 +121,7 @@
#include "td/utils/tl_parsers.h"
#include "td/utils/utf8.h"
#include <cmath>
#include <limits>
#include <tuple>
#include <type_traits>
@ -3309,6 +3310,17 @@ void Td::on_alarm_timeout_callback(void *td_ptr, int64 alarm_id) {
send_closure_later(td_id, &Td::on_alarm_timeout, alarm_id);
}
void Td::on_update_server_time_difference() {
auto diff = G()->get_server_time_difference();
if (std::abs(diff - last_sent_server_time_difference_) < 0.5) {
return;
}
last_sent_server_time_difference_ = diff;
send_update(td_api::make_object<td_api::updateOption>(
"unix_time", td_api::make_object<td_api::optionValueInteger>(G()->unix_time())));
}
void Td::on_alarm_timeout(int64 alarm_id) {
if (alarm_id == ONLINE_ALARM_ID) {
on_online_updated(false, true);
@ -4304,7 +4316,11 @@ Status Td::init(DbKey key) {
LOG(INFO) << "Successfully inited database in " << tag("database_directory", parameters_.database_directory)
<< " and " << tag("files_directory", parameters_.files_directory);
VLOG(td_init) << "Successfully inited database";
G()->init(parameters_, actor_id(this), r_td_db.move_as_ok()).ensure();
last_sent_server_time_difference_ = G()->get_server_time_difference();
send_update(td_api::make_object<td_api::updateOption>(
"unix_time", td_api::make_object<td_api::optionValueInteger>(G()->unix_time())));
init_options_and_network();
@ -4676,6 +4692,7 @@ void Td::send_update(tl_object_ptr<td_api::Update> &&object) {
case td_api::updateTrendingStickerSets::ID:
VLOG(td_requests) << "Sending update: updateTrendingStickerSets { ... }";
break;
case td_api::updateOption::ID / 2:
case td_api::updateChatReadInbox::ID / 2:
case td_api::updateUnreadMessageCount::ID / 2:
case td_api::updateUnreadChatCount::ID / 2:

View File

@ -106,7 +106,9 @@ class Td final : public NetQueryCallback {
void schedule_get_terms_of_service(int32 expires_in);
void on_result(NetQueryPtr query) override;
void on_connection_state_changed(StateManager::State new_state);
void on_update_server_time_difference();
void on_authorization_lost();
void on_online_updated(bool force, bool send_update);
@ -186,6 +188,7 @@ class Td final : public NetQueryCallback {
ResultHandler(const ResultHandler &) = delete;
ResultHandler &operator=(const ResultHandler &) = delete;
virtual ~ResultHandler() = default;
virtual void on_result(NetQueryPtr query);
virtual void on_result(uint64 id, BufferSlice packet) {
UNREACHABLE();
@ -197,7 +200,7 @@ class Td final : public NetQueryCallback {
friend class Td;
protected:
void send_query(NetQueryPtr);
void send_query(NetQueryPtr query);
Td *td = nullptr;
@ -230,6 +233,8 @@ class Td final : public NetQueryCallback {
static constexpr int32 PING_SERVER_TIMEOUT = 300;
static constexpr int64 TERMS_OF_SERVICE_ALARM_ID = -2;
void on_connection_state_changed(StateManager::State new_state);
void send_result(uint64 id, tl_object_ptr<td_api::Object> object);
void send_error(uint64 id, Status error);
void send_error_impl(uint64 id, tl_object_ptr<td_api::error> error);
@ -277,6 +282,8 @@ class Td final : public NetQueryCallback {
TermsOfService pending_terms_of_service_;
double last_sent_server_time_difference_ = 1e100;
struct DownloadInfo {
int32 offset = -1;
int32 limit = -1;