From 7ef40eea0c4382d33cd492ef60d4bd9e1df83da1 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Mon, 28 Dec 2020 16:10:05 +0100 Subject: [PATCH] Group call patches Add disable_group_calls boolean option Add memory_cleanup and memory_stats to FileReferenceManager Add memory_cleanup and memory_stats to GroupCallManager --- td/telegram/FileReferenceManager.cpp | 10 +++++++ td/telegram/FileReferenceManager.h | 4 +++ td/telegram/GroupCallManager.cpp | 43 ++++++++++++++++++++++++++-- td/telegram/GroupCallManager.h | 4 +++ td/telegram/MemoryManager.cpp | 15 ++++++++++ td/telegram/MessagesManager.cpp | 1 + td/telegram/Td.cpp | 3 ++ 7 files changed, 78 insertions(+), 2 deletions(-) diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 10b4b9779..1a61d5f12 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -365,6 +365,10 @@ void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise pr } } +void FileReferenceManager::memory_cleanup() { + +} + void FileReferenceManager::memory_cleanup(NodeId node_id) { auto find_node = nodes_.find(node_id); if (find_node != nodes_.end()) { @@ -375,4 +379,10 @@ void FileReferenceManager::memory_cleanup(NodeId node_id) { } } +void FileReferenceManager::memory_stats(vector &output) { + output.push_back("\"nodes_\":"); output.push_back(std::to_string(nodes_.size())); + output.push_back(","); + output.push_back("\"file_sources_\":"); output.push_back(std::to_string(file_sources_.size())); +} + } // namespace td diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index 4ac2a5db8..99d3a8daf 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -74,6 +74,10 @@ class FileReferenceManager : public Actor { void memory_cleanup(NodeId node_id); + void memory_cleanup(); + + void memory_stats(vector &output); + private: struct Destination { bool empty() const { diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 379c0ea27..320a6bb26 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -8,6 +8,8 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/AuthManager.h" +#include "td/telegram/ConfigManager.h" +#include "td/telegram/ConfigShared.h" #include "td/telegram/ContactsManager.h" #include "td/telegram/DialogParticipant.h" #include "td/telegram/Global.h" @@ -456,6 +458,34 @@ void GroupCallManager::tear_down() { parent_.reset(); } +void GroupCallManager::memory_cleanup() { + this->group_call_participants_.clear(); + this->group_call_participants_.rehash(0); + this->group_call_recent_speakers_.clear(); + this->group_call_recent_speakers_.rehash(0); + this->group_calls_.clear(); + this->group_calls_.rehash(0); + + //todo: check if we can clear call ids vector + // this->input_group_call_ids_.clear(); + + this->pending_join_requests_.clear(); + this->pending_join_requests_.rehash(0); + +} + +void GroupCallManager::memory_stats(vector &output) { + output.push_back("\"group_call_participants_\":"); output.push_back(std::to_string(group_call_participants_.size())); + output.push_back(","); + output.push_back("\"group_call_recent_speakers_\":"); output.push_back(std::to_string(group_call_recent_speakers_.size())); + output.push_back(","); + output.push_back("\"group_calls_\":"); output.push_back(std::to_string(group_calls_.size())); + output.push_back(","); + output.push_back("\"input_group_call_ids_\":"); output.push_back(std::to_string(input_group_call_ids_.size())); + output.push_back(","); + output.push_back("\"pending_join_requests_\":"); output.push_back(std::to_string(pending_join_requests_.size())); +} + void GroupCallManager::on_pending_send_speaking_action_timeout_callback(void *group_call_manager_ptr, int64 group_call_id_int) { if (G()->close_flag()) { @@ -536,7 +566,7 @@ void GroupCallManager::on_sync_participants_timeout(GroupCallId group_call_id) { } GroupCallId GroupCallManager::get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id) { - if (td_->auth_manager_->is_bot() || !input_group_call_id.is_valid()) { + if (G()->shared_config().get_option_boolean("disable_group_calls") || td_->auth_manager_->is_bot() || !input_group_call_id.is_valid()) { return GroupCallId(); } return add_group_call(input_group_call_id, dialog_id)->group_call_id; @@ -1825,7 +1855,7 @@ void GroupCallManager::discard_group_call(GroupCallId group_call_id, Promise group_call_ptr, DialogId dialog_id) { - if (td_->auth_manager_->is_bot()) { + if (G()->shared_config().get_option_boolean("disable_group_calls") || td_->auth_manager_->is_bot()) { LOG(ERROR) << "Receive " << to_string(group_call_ptr); return; } @@ -2258,17 +2288,26 @@ tl_object_ptr GroupCallManager::get_update_g void GroupCallManager::send_update_group_call(const GroupCall *group_call, const char *source) { LOG(INFO) << "Send update about " << group_call->group_call_id << " from " << source; + if (G()->shared_config().get_option_boolean("disable_group_calls")) { + return; + } send_closure(G()->td(), &Td::send_update, get_update_group_call_object(group_call, get_recent_speaker_user_ids(group_call, true))); } void GroupCallManager::send_update_group_call_participant(GroupCallId group_call_id, const GroupCallParticipant &participant) { + if (G()->shared_config().get_option_boolean("disable_group_calls")) { + return; + } send_closure(G()->td(), &Td::send_update, get_update_group_call_participant_object(group_call_id, participant)); } void GroupCallManager::send_update_group_call_participant(InputGroupCallId input_group_call_id, const GroupCallParticipant &participant) { + if (G()->shared_config().get_option_boolean("disable_group_calls")) { + return; + } auto group_call = get_group_call(input_group_call_id); CHECK(group_call != nullptr && group_call->is_inited); send_update_group_call_participant(group_call->group_call_id, participant); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index fbd0dca24..5faa283ea 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -37,6 +37,10 @@ class GroupCallManager : public Actor { GroupCallManager &operator=(GroupCallManager &&) = delete; ~GroupCallManager() override; + void memory_cleanup(); + + void memory_stats(vector &output); + GroupCallId get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id); void create_voice_chat(DialogId dialog_id, Promise &&promise); diff --git a/td/telegram/MemoryManager.cpp b/td/telegram/MemoryManager.cpp index b3cc8c978..c80a358fa 100644 --- a/td/telegram/MemoryManager.cpp +++ b/td/telegram/MemoryManager.cpp @@ -27,6 +27,7 @@ #include "td/telegram/VideosManager.h" #include "td/telegram/AudiosManager.h" #include "td/telegram/AnimationsManager.h" +#include "td/telegram/GroupCallManager.h" #include "td/telegram/files/FileType.h" #include "td/telegram/Global.h" #include "td/telegram/LanguagePackManager.h" @@ -150,6 +151,18 @@ void MemoryManager::get_memory_stats(bool full, Promise promise) co td_->file_manager_->memory_stats(output); output.push_back("}"); + output.push_back(","); + + output.push_back("\"file_reference_manager_\":{"); + td_->file_reference_manager_->memory_stats(output); + output.push_back("}"); + + output.push_back(","); + + output.push_back("\"group_call_manager_\":{"); + td_->group_call_manager_->memory_stats(output); + output.push_back("}"); + output.push_back("}}"); string s; @@ -175,6 +188,8 @@ void MemoryManager::clean_memory(bool full, Promise promise) const { td_->audios_manager_->memory_cleanup(); td_->animations_manager_->memory_cleanup(); td_->file_manager_->memory_cleanup(); + td_->file_reference_manager_->memory_cleanup(); + td_->group_call_manager_->memory_cleanup(); #ifdef __linux__ #if defined(__GLIBC__) && !defined(__UCLIBC__) && !defined(__MUSL__) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 23b1e3d1f..01457e49d 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -5916,6 +5916,7 @@ void MessagesManager::memory_cleanup() { full_message_id_to_file_source_id_.clear(); full_message_id_to_file_source_id_.rehash(0); } + void MessagesManager::memory_stats(vector &output) { output.push_back("\"being_sent_messages_\":"); output.push_back(std::to_string(this->being_sent_messages_.size())); output.push_back(","); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index c1b85874c..aa75a2abb 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7315,6 +7315,9 @@ void Td::on_request(uint64 id, td_api::setOption &request) { if (set_boolean_option("disable_notifications")) { return; } + if (set_boolean_option("disable_group_calls")) { + return; + } if (set_integer_option("delete_file_reference_after_seconds")) { return; }