Skip to content

Commit

Permalink
Init sessions if there are multiple sessions.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Jul 12, 2023
1 parent a9712d7 commit 1669f8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions td/telegram/OptionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "td/telegram/Td.h"
#include "td/telegram/TdDb.h"
#include "td/telegram/TopDialogManager.h"
#include "td/telegram/UpdatesManager.h"

#include "td/db/KeyValueSyncInterface.h"
#include "td/db/TsSeqKeyValue.h"
Expand Down Expand Up @@ -450,6 +451,7 @@ void OptionManager::on_option_updated(Slice name) {
}
if (name == "session_count") {
G()->net_query_dispatcher().update_session_count();
td_->updates_manager_->init_sessions(false);
}
break;
case 'u':
Expand Down
35 changes: 35 additions & 0 deletions td/telegram/UpdatesManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ class PingServerQuery final : public Td::ResultHandler {
}
};

class InitSessionQuery final : public Td::ResultHandler {
public:
void send() {
send_query(G()->net_query_creator().create(telegram_api::help_getCdnConfig()));
}

void on_result(BufferSlice) final {
}

void on_error(Status) final {
}
};

class GetDifferenceQuery final : public Td::ResultHandler {
Promise<tl_object_ptr<telegram_api::updates_Difference>> promise_;

Expand Down Expand Up @@ -1732,6 +1745,26 @@ void UpdatesManager::on_server_pong(tl_object_ptr<telegram_api::updates_state> &
}
}

void UpdatesManager::init_sessions(bool is_first) {
if (G()->close_flag()) {
return;
}
if (are_sessions_inited_ == is_first || !td_->auth_manager_->is_authorized()) {
return;
}
are_sessions_inited_ = true;

auto session_count = td_->option_manager_->get_option_integer("session_count", 1);
if (session_count <= 1) {
return;
}

LOG(INFO) << "Init " << session_count << " sessions";
for (size_t i = 0; i < session_count; i++) {
td_->create_handler<InitSessionQuery>()->send();
}
}

void UpdatesManager::process_get_difference_updates(
vector<tl_object_ptr<telegram_api::Message>> &&new_messages,
vector<tl_object_ptr<telegram_api::EncryptedMessage>> &&new_encrypted_messages,
Expand Down Expand Up @@ -2097,6 +2130,8 @@ void UpdatesManager::after_get_difference() {
send_closure(G()->state_manager(), &StateManager::on_synchronized, true);
get_difference_start_time_ = 0.0;

init_sessions(true);

try_reload_data();
}

Expand Down
4 changes: 4 additions & 0 deletions td/telegram/UpdatesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class UpdatesManager final : public Actor {

void ping_server();

void init_sessions(bool is_first);

bool running_get_difference() const {
return running_get_difference_;
}
Expand Down Expand Up @@ -258,6 +260,8 @@ class UpdatesManager final : public Actor {

bool is_ping_sent_ = false;

bool are_sessions_inited_ = false;

bool running_get_difference_ = false;
bool finished_first_get_difference_ = false;
int32 last_confirmed_pts_ = 0;
Expand Down

0 comments on commit 1669f8d

Please sign in to comment.