2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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
|
2018-06-25 23:10:53 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/AuthDataShared.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
|
2019-01-31 03:05:40 +01:00
|
|
|
#include "td/mtproto/AuthData.h"
|
|
|
|
#include "td/mtproto/AuthKey.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace td {
|
2018-04-24 18:21:47 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class Session;
|
2018-04-24 18:21:47 +02:00
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class SessionProxy final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
friend class SessionCallback;
|
2019-03-15 10:00:18 +01:00
|
|
|
class Callback {
|
|
|
|
public:
|
|
|
|
virtual ~Callback() = default;
|
|
|
|
virtual void on_query_finished() = 0;
|
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-03-15 10:00:18 +01:00
|
|
|
SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main,
|
|
|
|
bool allow_media_only, bool is_media, bool use_pfs, bool is_cdn, bool need_destroy);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void send(NetQueryPtr query);
|
|
|
|
void update_main_flag(bool is_main);
|
2018-06-13 17:17:27 +02:00
|
|
|
void update_mtproto_header();
|
2017-12-29 21:34:39 +01:00
|
|
|
void update_destroy(bool need_destroy);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
2019-03-15 10:00:18 +01:00
|
|
|
unique_ptr<Callback> callback_;
|
2018-12-31 20:04:05 +01:00
|
|
|
std::shared_ptr<AuthDataShared> auth_data_;
|
2021-11-11 15:39:09 +01:00
|
|
|
AuthKeyState auth_key_state_ = AuthKeyState::Empty;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_main_;
|
|
|
|
bool allow_media_only_;
|
|
|
|
bool is_media_;
|
|
|
|
bool use_pfs_;
|
|
|
|
mtproto::AuthKey tmp_auth_key_;
|
2018-06-13 17:17:27 +02:00
|
|
|
std::vector<mtproto::ServerSalt> server_salts_;
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_cdn_;
|
2017-12-29 21:34:39 +01:00
|
|
|
bool need_destroy_;
|
2018-12-31 20:04:05 +01:00
|
|
|
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);
|
|
|
|
|
2019-07-23 01:14:34 +02:00
|
|
|
void update_auth_key_state();
|
2018-12-31 20:04:05 +01:00
|
|
|
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key);
|
2018-06-13 17:17:27 +02:00
|
|
|
void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-03-15 10:00:18 +01:00
|
|
|
void on_query_finished();
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final;
|
|
|
|
void tear_down() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-04-24 18:21:47 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|