2018-12-31 22:04:05 +03:00
|
|
|
//
|
2023-01-01 00:28:08 +03:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 22:04:05 +03: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
|
|
|
|
|
|
|
|
#include "td/telegram/net/AuthDataShared.h"
|
2023-05-18 14:33:00 +03:00
|
|
|
#include "td/telegram/net/AuthKeyState.h"
|
2018-06-26 02:43:11 +03:00
|
|
|
#include "td/telegram/net/DcId.h"
|
2018-12-31 22:04:05 +03:00
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2018-11-01 20:08:20 +03:00
|
|
|
|
2018-12-31 22:04:05 +03:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
2020-10-08 18:30:36 +03:00
|
|
|
#include "td/utils/logging.h"
|
2022-06-27 13:30:18 +03:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 22:04:05 +03:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace td {
|
2018-10-28 20:30:47 +03:00
|
|
|
|
2020-10-05 18:07:23 +03:00
|
|
|
extern int VERBOSITY_NAME(dc);
|
|
|
|
|
2021-07-04 05:58:54 +03:00
|
|
|
class DcAuthManager final : public NetQueryCallback {
|
2018-12-31 22:04:05 +03:00
|
|
|
public:
|
|
|
|
explicit DcAuthManager(ActorShared<> parent);
|
|
|
|
|
|
|
|
void add_dc(std::shared_ptr<AuthDataShared> auth_data);
|
|
|
|
void update_main_dc(DcId new_main_dc_id);
|
2017-12-29 23:34:39 +03:00
|
|
|
void destroy(Promise<> promise);
|
2018-12-31 22:04:05 +03:00
|
|
|
|
2022-05-02 19:34:01 +04:00
|
|
|
void check_authorization_is_ok();
|
|
|
|
|
2018-12-31 22:04:05 +03:00
|
|
|
private:
|
|
|
|
struct DcInfo {
|
|
|
|
DcId dc_id;
|
|
|
|
std::shared_ptr<AuthDataShared> shared_auth_data;
|
2019-07-23 02:14:34 +03:00
|
|
|
AuthKeyState auth_key_state;
|
2018-12-31 22:04:05 +03:00
|
|
|
|
2018-04-19 16:08:30 +03:00
|
|
|
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
|
2018-12-31 22:04:05 +03:00
|
|
|
State state = State::Waiting;
|
2021-11-11 17:39:09 +03:00
|
|
|
uint64 wait_id = 0;
|
|
|
|
int64 export_id = 0;
|
2018-12-31 22:04:05 +03:00
|
|
|
BufferSlice export_bytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
|
|
|
std::vector<DcInfo> dcs_;
|
|
|
|
DcId main_dc_id_;
|
2022-05-02 20:44:37 +03:00
|
|
|
bool need_check_authorization_is_ok_{false};
|
2017-12-29 23:34:39 +03:00
|
|
|
bool close_flag_{false};
|
|
|
|
Promise<> destroy_promise_;
|
2018-12-31 22:04:05 +03:00
|
|
|
|
|
|
|
DcInfo &get_dc(int32 dc_id);
|
|
|
|
DcInfo *find_dc(int32 dc_id);
|
|
|
|
|
2019-07-23 02:14:34 +03:00
|
|
|
void update_auth_key_state();
|
2018-12-31 22:04:05 +03:00
|
|
|
|
2021-07-03 23:51:36 +03:00
|
|
|
void on_result(NetQueryPtr result) final;
|
2018-12-31 22:04:05 +03:00
|
|
|
void dc_loop(DcInfo &dc);
|
|
|
|
|
2017-12-29 23:34:39 +03:00
|
|
|
void destroy_loop();
|
2021-07-03 23:51:36 +03:00
|
|
|
void loop() final;
|
2018-12-31 22:04:05 +03:00
|
|
|
};
|
2018-10-28 20:30:47 +03:00
|
|
|
|
2018-12-31 22:04:05 +03:00
|
|
|
} // namespace td
|