1 // 2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #pragma once 8 9 #include "td/telegram/net/AuthDataShared.h" 10 #include "td/telegram/net/NetQuery.h" 11 12 #include "td/mtproto/AuthData.h" 13 #include "td/mtproto/AuthKey.h" 14 15 #include "td/actor/actor.h" 16 17 #include <memory> 18 19 namespace td { 20 21 class Session; 22 23 class SessionProxy final : public Actor { 24 public: 25 friend class SessionCallback; 26 class Callback { 27 public: 28 virtual ~Callback() = default; 29 virtual void on_query_finished() = 0; 30 }; 31 32 SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main, 33 bool allow_media_only, bool is_media, bool use_pfs, bool is_cdn, bool need_destroy); 34 35 void send(NetQueryPtr query); 36 void update_main_flag(bool is_main); 37 void update_mtproto_header(); 38 void update_destroy(bool need_destroy); 39 40 private: 41 unique_ptr<Callback> callback_; 42 std::shared_ptr<AuthDataShared> auth_data_; 43 AuthKeyState auth_key_state_ = AuthKeyState::Empty; 44 bool is_main_; 45 bool allow_media_only_; 46 bool is_media_; 47 bool use_pfs_; 48 mtproto::AuthKey tmp_auth_key_; 49 std::vector<mtproto::ServerSalt> server_salts_; 50 bool is_cdn_; 51 bool need_destroy_; 52 ActorOwn<Session> session_; 53 std::vector<NetQueryPtr> pending_queries_; 54 uint64 session_generation_ = 1; 55 56 void on_failed(); 57 void on_closed(); 58 void close_session(); 59 void open_session(bool force = false); 60 61 void update_auth_key_state(); 62 void on_tmp_auth_key_updated(mtproto::AuthKey auth_key); 63 void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts); 64 65 void on_query_finished(); 66 67 void start_up() final; 68 void tear_down() final; 69 }; 70 71 } // namespace td 72