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
|
|
|
|
|
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/DcOptions.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
|
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
2018-07-03 21:29:04 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-12-27 20:24:44 +01:00
|
|
|
#include "td/utils/logging.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/port/IPAddress.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
#include "td/utils/Time.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-12-26 21:58:18 +01:00
|
|
|
extern int VERBOSITY_NAME(config_recoverer);
|
|
|
|
|
2018-06-30 15:35:37 +02:00
|
|
|
class ConfigShared;
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
using SimpleConfig = tl_object_ptr<telegram_api::help_configSimple>;
|
2019-07-11 13:25:20 +02:00
|
|
|
struct SimpleConfigResult {
|
|
|
|
Result<SimpleConfig> r_config;
|
2019-07-11 22:32:45 +02:00
|
|
|
Result<int32> r_http_date;
|
2019-07-11 13:25:20 +02:00
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Result<SimpleConfig> decode_config(Slice input);
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
ActorOwn<> get_simple_config_azure(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, bool is_test,
|
2018-06-30 15:35:37 +02:00
|
|
|
int32 scheduler_id);
|
2018-03-12 19:04:03 +01:00
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-10-03 21:20:15 +02:00
|
|
|
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-11-19 15:58:24 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise,
|
|
|
|
const ConfigShared *shared_config, bool is_test,
|
|
|
|
int32 scheduler_id);
|
|
|
|
|
2019-11-19 17:01:12 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-11-19 17:26:39 +01:00
|
|
|
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id);
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
class HttpDate {
|
2019-07-11 22:32:45 +02:00
|
|
|
static bool is_leap(int32 year) {
|
2019-07-11 13:25:20 +02:00
|
|
|
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
static int32 days_in_month(int32 year, int32 month) {
|
2019-07-11 13:25:20 +02:00
|
|
|
static int cnt[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
|
return cnt[month - 1] + (month == 2 && is_leap(year));
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
static int32 seconds_in_day() {
|
2019-07-11 13:25:20 +02:00
|
|
|
return 24 * 60 * 60;
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
static Result<int32> to_unix_time(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second);
|
|
|
|
static Result<int32> parse_http_date(std::string slice);
|
2019-07-11 13:25:20 +02:00
|
|
|
};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
using FullConfig = tl_object_ptr<telegram_api::config>;
|
|
|
|
|
2018-05-18 13:38:49 +02:00
|
|
|
ActorOwn<> get_full_config(DcId dc_id, IPAddress ip_address, Promise<FullConfig> promise);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
class ConfigRecoverer;
|
|
|
|
class ConfigManager : public NetQueryCallback {
|
|
|
|
public:
|
|
|
|
explicit ConfigManager(ActorShared<> parent);
|
|
|
|
|
|
|
|
void request_config();
|
|
|
|
|
|
|
|
void on_dc_options_update(DcOptions dc_options);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
|
|
|
int32 config_sent_cnt_{0};
|
|
|
|
ActorOwn<ConfigRecoverer> config_recoverer_;
|
|
|
|
int ref_cnt_{1};
|
2019-02-10 01:45:15 +01:00
|
|
|
Timestamp expire_time_;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void start_up() override;
|
|
|
|
void hangup_shared() override;
|
|
|
|
void hangup() override;
|
|
|
|
void loop() override;
|
|
|
|
void try_stop();
|
|
|
|
|
|
|
|
void on_result(NetQueryPtr res) override;
|
|
|
|
|
|
|
|
void request_config_from_dc_impl(DcId dc_id);
|
|
|
|
void process_config(tl_object_ptr<telegram_api::config> config);
|
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
Timestamp load_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
void save_config_expire(Timestamp timestamp);
|
|
|
|
void save_dc_options_update(DcOptions dc_options);
|
|
|
|
DcOptions load_dc_options_update();
|
|
|
|
};
|
2018-10-28 18:30:47 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|