From 295878b217990e0cbb7e2e687708150c21e26371 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 31 Mar 2019 22:29:34 +0300 Subject: [PATCH] Check connection aliveness after push is received. GitOrigin-RevId: 526a06642617ada66ef6d84f5858cb332f1c1406 --- td/mtproto/SessionConnection.cpp | 3 ++- td/telegram/NotificationManager.cpp | 6 ++++++ td/telegram/SecretChatsManager.cpp | 4 ++++ td/telegram/net/ConnectionCreator.cpp | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index d215e5d6..7bc85ccb 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -713,10 +713,11 @@ Status SessionConnection::init() { } void SessionConnection::set_online(bool online_flag, bool is_main) { + bool need_ping = online_flag || !online_flag_; online_flag_ = online_flag; is_main_ = is_main; auto now = Time::now(); - if (online_flag_) { + if (need_ping) { last_pong_at_ = now - ping_disconnect_delay() + rtt(); last_read_at_ = now - read_disconnect_delay() + rtt(); } else { diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index cee9b743..721aeabe 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2520,6 +2520,12 @@ void NotificationManager::process_push_notification(string payload, Promiseis_online()) { + // reset online flag to false to immediately check all connections aliveness + send_closure(G()->state_manager(), &StateManager::on_online, false); + } + if (receiver_id == 0 || receiver_id == G()->get_my_id()) { auto status = process_push_notification_payload(payload); if (status.is_error()) { diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index ccbafe99..7140e1c3 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -564,6 +564,10 @@ void SecretChatsManager::flush_pending_chat_updates() { } void SecretChatsManager::on_online(bool is_online) { + if (is_online_ == is_online) { + return; + } + is_online_ = is_online; flush_pending_chat_updates(); } diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 0c841cf7..74ff1062 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -776,8 +776,9 @@ void ConnectionCreator::on_network(bool network_flag, uint32 network_generation) void ConnectionCreator::on_online(bool online_flag) { VLOG(connections) << "Receive online flag " << online_flag; + bool need_drop_flood_control = online_flag || !online_flag_; online_flag_ = online_flag; - if (online_flag_) { + if (need_drop_flood_control) { for (auto &client : clients_) { client.second.backoff.clear(); client.second.flood_control_online.clear_events();