// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 // // 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" #include "td/telegram/net/NetQuery.h" #include "td/actor/actor.h" #include "td/utils/common.h" #include "td/utils/Status.h" #include #include #include #include #include namespace td { class NetQueryDelayer; class DataCenter; class DcAuthManager; class SessionMultiProxy; class PublicRsaKeyShared; class PublicRsaKeyWatchdog; } // namespace td namespace td { // Not just dispatcher. class NetQueryDispatcher { public: explicit NetQueryDispatcher(std::function()> create_reference); NetQueryDispatcher(); NetQueryDispatcher(const NetQueryDispatcher &) = delete; NetQueryDispatcher &operator=(const NetQueryDispatcher &) = delete; NetQueryDispatcher(NetQueryDispatcher &&) = delete; NetQueryDispatcher &operator=(NetQueryDispatcher &&) = delete; ~NetQueryDispatcher(); void dispatch(NetQueryPtr net_query); void dispatch_with_callback(NetQueryPtr net_query, ActorShared callback); void stop(); void update_session_count(); void update_use_pfs(); void update_valid_dc(DcId dc_id); DcId main_dc_id() { return DcId::internal(main_dc_id_.load()); } private: std::atomic stop_flag_{false}; ActorOwn delayer_; ActorOwn dc_auth_manager_; struct Dc { std::atomic is_valid_{false}; std::atomic is_inited_{false}; // TODO: cache in scheduler local storage :D ActorOwn main_session_; ActorOwn download_session_; ActorOwn download_small_session_; ActorOwn upload_session_; }; static constexpr size_t MAX_DC_COUNT = 1000; std::array dcs_; #if TD_EMSCRIPTEN // FIXME std::atomic main_dc_id_{2}; #else std::atomic main_dc_id_{1}; #endif std::shared_ptr common_public_rsa_key_; ActorOwn public_rsa_key_watchdog_; std::mutex main_dc_id_mutex_; Status wait_dc_init(DcId dc_id, bool force); bool is_dc_inited(int32 raw_dc_id); static int32 get_session_count(); static bool get_use_pfs(); void try_fix_migrate(NetQueryPtr &net_query); }; } // namespace td