2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
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
|
|
|
|
|
|
|
|
#include "td/telegram/net/AuthDataShared.h"
|
2018-06-26 01:43:11 +02:00
|
|
|
#include "td/telegram/net/DcId.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/NetQuery.h"
|
2018-11-01 18:08:20 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
2018-12-11 21:18:58 +01:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace td {
|
2018-10-28 18:30:47 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class DcAuthManager : public NetQueryCallback {
|
|
|
|
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 21:34:39 +01:00
|
|
|
void destroy(Promise<> promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct DcInfo {
|
|
|
|
DcId dc_id;
|
|
|
|
std::shared_ptr<AuthDataShared> shared_auth_data;
|
|
|
|
AuthState auth_state;
|
|
|
|
|
2018-04-19 15:08:30 +02:00
|
|
|
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
|
2018-12-31 20:04:05 +01:00
|
|
|
State state = State::Waiting;
|
|
|
|
uint64 wait_id;
|
|
|
|
int32 export_id;
|
|
|
|
BufferSlice export_bytes;
|
|
|
|
};
|
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
|
|
|
std::vector<DcInfo> dcs_;
|
2017-12-29 21:34:39 +01:00
|
|
|
bool was_auth_{false};
|
2018-12-31 20:04:05 +01:00
|
|
|
DcId main_dc_id_;
|
2017-12-29 21:34:39 +01:00
|
|
|
bool close_flag_{false};
|
|
|
|
Promise<> destroy_promise_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
DcInfo &get_dc(int32 dc_id);
|
|
|
|
DcInfo *find_dc(int32 dc_id);
|
|
|
|
|
|
|
|
void update_auth_state();
|
|
|
|
|
|
|
|
void on_result(NetQueryPtr result) override;
|
|
|
|
void dc_loop(DcInfo &dc);
|
|
|
|
|
2017-12-29 21:34:39 +01:00
|
|
|
void destroy_loop();
|
2018-12-31 20:04:05 +01:00
|
|
|
void loop() override;
|
|
|
|
};
|
2018-10-28 18:30:47 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|