tdlight/td/telegram/net/SessionProxy.h

81 lines
2.0 KiB
C
Raw Normal View History

//
2024-01-01 01:07:21 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/net/AuthDataShared.h"
2023-05-18 13:33:00 +02:00
#include "td/telegram/net/AuthKeyState.h"
#include "td/telegram/net/NetQuery.h"
#include "td/mtproto/AuthData.h"
#include "td/mtproto/AuthKey.h"
#include "td/actor/actor.h"
2023-08-05 15:09:36 +02:00
#include "td/utils/common.h"
#include <memory>
namespace td {
class Session;
class SessionProxy final : public Actor {
public:
friend class SessionCallback;
class Callback {
public:
virtual ~Callback() = default;
virtual void on_query_finished() = 0;
};
SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_primary,
bool is_main, bool allow_media_only, bool is_media, bool use_pfs, bool persist_tmp_auth_key, bool is_cdn,
2023-10-23 13:10:39 +02:00
bool need_destroy_auth_key);
void send(NetQueryPtr query);
void update_main_flag(bool is_main);
void update_mtproto_header();
private:
unique_ptr<Callback> callback_;
std::shared_ptr<AuthDataShared> auth_data_;
2021-11-11 15:39:09 +01:00
AuthKeyState auth_key_state_ = AuthKeyState::Empty;
const bool is_primary_;
bool is_main_;
bool allow_media_only_;
bool is_media_;
bool use_pfs_;
bool persist_tmp_auth_key_;
mtproto::AuthKey tmp_auth_key_;
std::vector<mtproto::ServerSalt> server_salts_;
bool is_cdn_;
2023-10-23 13:10:39 +02:00
bool need_destroy_auth_key_;
ActorOwn<Session> session_;
std::vector<NetQueryPtr> pending_queries_;
uint64 session_generation_ = 1;
void on_failed();
void on_closed();
void close_session();
void open_session(bool force = false);
void update_auth_key_state();
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key);
void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts);
void on_query_finished();
string tmp_auth_key_key() const;
2021-07-03 22:51:36 +02:00
void start_up() final;
void tear_down() final;
};
} // namespace td