2018-12-31 20:04:05 +01:00
|
|
|
//
|
2021-01-01 13:57:46 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
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)
|
|
|
|
//
|
|
|
|
#include "td/telegram/ConfigManager.h"
|
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
#include "td/telegram/AuthManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/ConfigShared.h"
|
|
|
|
#include "td/telegram/Global.h"
|
2019-12-19 02:23:14 +01:00
|
|
|
#include "td/telegram/JsonValue.h"
|
2021-05-25 01:39:29 +02:00
|
|
|
#include "td/telegram/LinkManager.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/logevent/LogEvent.h"
|
2019-07-23 01:14:34 +02:00
|
|
|
#include "td/telegram/net/AuthDataShared.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/ConnectionCreator.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/DcOptions.h"
|
|
|
|
#include "td/telegram/net/NetQuery.h"
|
|
|
|
#include "td/telegram/net/NetQueryDispatcher.h"
|
2018-06-26 01:43:11 +02:00
|
|
|
#include "td/telegram/net/NetType.h"
|
|
|
|
#include "td/telegram/net/PublicRsaKeyShared.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/telegram/net/Session.h"
|
2018-10-28 18:30:47 +01:00
|
|
|
#include "td/telegram/StateManager.h"
|
2019-12-19 21:00:28 +01:00
|
|
|
#include "td/telegram/Td.h"
|
2019-01-06 20:59:17 +01:00
|
|
|
#include "td/telegram/TdDb.h"
|
2019-01-31 03:05:40 +01:00
|
|
|
#include "td/telegram/telegram_api.h"
|
|
|
|
|
|
|
|
#include "td/mtproto/AuthData.h"
|
|
|
|
#include "td/mtproto/AuthKey.h"
|
|
|
|
#include "td/mtproto/RawConnection.h"
|
2020-05-17 16:07:16 +02:00
|
|
|
#include "td/mtproto/RSA.h"
|
2019-07-23 00:50:12 +02:00
|
|
|
#include "td/mtproto/TransportType.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2020-01-08 15:42:55 +01:00
|
|
|
#if !TD_EMSCRIPTEN //FIXME
|
2018-08-15 14:41:42 +02:00
|
|
|
#include "td/net/SslStream.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/net/Wget.h"
|
|
|
|
#endif
|
|
|
|
|
2021-06-23 02:22:23 +02:00
|
|
|
#include "td/net/HttpQuery.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2021-01-01 13:59:53 +01:00
|
|
|
#include "td/utils/algorithm.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/base64.h"
|
|
|
|
#include "td/utils/buffer.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/crypto.h"
|
|
|
|
#include "td/utils/format.h"
|
|
|
|
#include "td/utils/JsonBuilder.h"
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/misc.h"
|
2019-07-23 00:50:12 +02:00
|
|
|
#include "td/utils/Parser.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/port/Clocks.h"
|
|
|
|
#include "td/utils/Random.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Time.h"
|
2018-06-05 19:44:41 +02:00
|
|
|
#include "td/utils/tl_helpers.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/tl_parsers.h"
|
2018-12-19 22:18:53 +01:00
|
|
|
#include "td/utils/UInt.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2021-02-25 13:56:26 +01:00
|
|
|
#include <functional>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <memory>
|
2020-04-21 18:08:01 +02:00
|
|
|
#include <unordered_map>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2018-12-26 21:58:18 +01:00
|
|
|
int VERBOSITY_NAME(config_recoverer) = VERBOSITY_NAME(INFO);
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
Result<int32> HttpDate::to_unix_time(int32 year, int32 month, int32 day, int32 hour, int32 minute, int32 second) {
|
2019-07-11 13:25:20 +02:00
|
|
|
if (year < 1970 || year > 2037) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid year");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (month < 1 || month > 12) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid month");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (day < 1 || day > days_in_month(year, month)) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid day");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
if (hour < 0 || hour >= 24) {
|
|
|
|
return Status::Error("Invalid hour");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
if (minute < 0 || minute >= 60) {
|
|
|
|
return Status::Error("Invalid minute");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
if (second < 0 || second > 60) {
|
2019-07-11 22:32:45 +02:00
|
|
|
return Status::Error("Invalid second");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
|
|
|
|
int32 res = 0;
|
|
|
|
for (int32 y = 1970; y < year; y++) {
|
2019-07-11 13:25:20 +02:00
|
|
|
res += (is_leap(y) + 365) * seconds_in_day();
|
|
|
|
}
|
2019-07-11 22:32:45 +02:00
|
|
|
for (int32 m = 1; m < month; m++) {
|
2019-07-11 13:25:20 +02:00
|
|
|
res += days_in_month(year, m) * seconds_in_day();
|
|
|
|
}
|
|
|
|
res += (day - 1) * seconds_in_day();
|
|
|
|
res += hour * 60 * 60;
|
|
|
|
res += minute * 60;
|
|
|
|
res += second;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-02-22 16:25:49 +01:00
|
|
|
Result<int32> HttpDate::parse_http_date(string slice) {
|
2019-07-11 22:32:45 +02:00
|
|
|
Parser p(slice);
|
2019-07-11 13:25:20 +02:00
|
|
|
p.read_till(','); // ignore week day
|
|
|
|
p.skip(',');
|
|
|
|
p.skip_whitespaces();
|
2019-07-11 22:32:45 +02:00
|
|
|
p.skip_nofail('0');
|
2019-07-11 13:25:20 +02:00
|
|
|
TRY_RESULT(day, to_integer_safe<int32>(p.read_word()));
|
|
|
|
auto month_name = p.read_word();
|
|
|
|
to_lower_inplace(month_name);
|
|
|
|
TRY_RESULT(year, to_integer_safe<int32>(p.read_word()));
|
|
|
|
p.skip_whitespaces();
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(hour, to_integer_safe<int32>(p.read_till(':')));
|
|
|
|
p.skip(':');
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(minute, to_integer_safe<int32>(p.read_till(':')));
|
|
|
|
p.skip(':');
|
|
|
|
p.skip_nofail('0');
|
|
|
|
TRY_RESULT(second, to_integer_safe<int32>(p.read_word()));
|
|
|
|
auto gmt = p.read_word();
|
|
|
|
TRY_STATUS(std::move(p.status()));
|
|
|
|
if (gmt != "GMT") {
|
2019-08-26 03:53:22 +02:00
|
|
|
return Status::Error("Timezone must be GMT");
|
2019-07-11 13:25:20 +02:00
|
|
|
}
|
|
|
|
|
2019-07-11 22:32:45 +02:00
|
|
|
static Slice month_names[12] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
|
2019-07-11 13:25:20 +02:00
|
|
|
|
|
|
|
int month = 0;
|
|
|
|
|
|
|
|
for (int m = 1; m <= 12; m++) {
|
|
|
|
if (month_names[m - 1] == month_name) {
|
|
|
|
month = m;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (month == 0) {
|
|
|
|
return Status::Error("Unknown month name");
|
|
|
|
}
|
|
|
|
|
|
|
|
return HttpDate::to_unix_time(year, month, day, hour, minute, second);
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
Result<SimpleConfig> decode_config(Slice input) {
|
2021-07-05 20:04:23 +02:00
|
|
|
static auto rsa = mtproto::RSA::from_pem_public_key(
|
2018-12-31 20:04:05 +01:00
|
|
|
"-----BEGIN RSA PUBLIC KEY-----\n"
|
|
|
|
"MIIBCgKCAQEAyr+18Rex2ohtVy8sroGP\n"
|
|
|
|
"BwXD3DOoKCSpjDqYoXgCqB7ioln4eDCFfOBUlfXUEvM/fnKCpF46VkAftlb4VuPD\n"
|
|
|
|
"eQSS/ZxZYEGqHaywlroVnXHIjgqoxiAd192xRGreuXIaUKmkwlM9JID9WS2jUsTp\n"
|
|
|
|
"zQ91L8MEPLJ/4zrBwZua8W5fECwCCh2c9G5IzzBm+otMS/YKwmR1olzRCyEkyAEj\n"
|
|
|
|
"XWqBI9Ftv5eG8m0VkBzOG655WIYdyV0HfDK/NWcvGqa0w/nriMD6mDjKOryamw0O\n"
|
|
|
|
"P9QuYgMN0C9xMW9y8SmP4h92OAWodTYgY1hZCxdv6cs5UnW9+PWvS+WIbkh+GaWY\n"
|
|
|
|
"xwIDAQAB\n"
|
|
|
|
"-----END RSA PUBLIC KEY-----\n")
|
|
|
|
.move_as_ok();
|
|
|
|
|
|
|
|
if (input.size() < 344 || input.size() > 1024) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", input.size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data_base64 = base64_filter(input);
|
|
|
|
if (data_base64.size() != 344) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", data_base64.size()) << " after base64_filter");
|
|
|
|
}
|
|
|
|
TRY_RESULT(data_rsa, base64_decode(data_base64));
|
|
|
|
if (data_rsa.size() != 256) {
|
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("length", data_rsa.size()) << " after base64_decode");
|
|
|
|
}
|
|
|
|
|
|
|
|
MutableSlice data_rsa_slice(data_rsa);
|
2020-03-10 16:27:43 +01:00
|
|
|
rsa.decrypt_signature(data_rsa_slice, data_rsa_slice);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
MutableSlice data_cbc = data_rsa_slice.substr(32);
|
|
|
|
UInt256 key;
|
|
|
|
UInt128 iv;
|
2018-11-06 17:00:03 +01:00
|
|
|
as_slice(key).copy_from(data_rsa_slice.substr(0, 32));
|
|
|
|
as_slice(iv).copy_from(data_rsa_slice.substr(16, 16));
|
2019-08-12 15:53:17 +02:00
|
|
|
aes_cbc_decrypt(as_slice(key), as_slice(iv), data_cbc, data_cbc);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
CHECK(data_cbc.size() == 224);
|
|
|
|
string hash(32, ' ');
|
|
|
|
sha256(data_cbc.substr(0, 208), MutableSlice(hash));
|
|
|
|
if (data_cbc.substr(208) != Slice(hash).substr(0, 16)) {
|
2019-08-26 03:53:22 +02:00
|
|
|
return Status::Error("SHA256 mismatch");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TlParser len_parser{data_cbc};
|
|
|
|
int len = len_parser.fetch_int();
|
2019-07-11 02:12:27 +02:00
|
|
|
if (len < 8 || len > 208) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return Status::Error(PSLICE() << "Invalid " << tag("data length", len) << " after aes_cbc_decrypt");
|
|
|
|
}
|
|
|
|
int constructor_id = len_parser.fetch_int();
|
|
|
|
if (constructor_id != telegram_api::help_configSimple::ID) {
|
|
|
|
return Status::Error(PSLICE() << "Wrong " << tag("constructor", format::as_hex(constructor_id)));
|
|
|
|
}
|
2019-07-11 02:12:27 +02:00
|
|
|
BufferSlice raw_config(data_cbc.substr(8, len - 8));
|
2018-12-31 20:04:05 +01:00
|
|
|
TlBufferParser parser{&raw_config};
|
|
|
|
auto config = telegram_api::help_configSimple::fetch(parser);
|
2019-07-11 02:12:27 +02:00
|
|
|
parser.fetch_end();
|
2018-12-31 20:04:05 +01:00
|
|
|
TRY_STATUS(parser.get_status());
|
|
|
|
return std::move(config);
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
static ActorOwn<> get_simple_config_impl(Promise<SimpleConfigResult> promise, int32 scheduler_id, string url,
|
2019-11-19 16:12:51 +01:00
|
|
|
string host, std::vector<std::pair<string, string>> headers, bool prefer_ipv6,
|
2020-01-08 15:42:55 +01:00
|
|
|
std::function<Result<string>(HttpQuery &)> get_config,
|
|
|
|
string content = string(), string content_type = string()) {
|
2018-03-12 19:04:03 +01:00
|
|
|
VLOG(config_recoverer) << "Request simple config from " << url;
|
2018-12-31 20:04:05 +01:00
|
|
|
#if TD_EMSCRIPTEN // FIXME
|
|
|
|
return ActorOwn<>();
|
|
|
|
#else
|
2018-07-01 03:45:25 +02:00
|
|
|
const int timeout = 10;
|
|
|
|
const int ttl = 3;
|
2019-11-19 16:12:51 +01:00
|
|
|
headers.emplace_back("Host", std::move(host));
|
|
|
|
headers.emplace_back("User-Agent",
|
|
|
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
|
|
|
"Chrome/77.0.3865.90 Safari/537.36");
|
2018-12-31 20:04:05 +01:00
|
|
|
return ActorOwn<>(create_actor_on_scheduler<Wget>(
|
|
|
|
"Wget", scheduler_id,
|
2019-11-19 15:58:24 +01:00
|
|
|
PromiseCreator::lambda([get_config = std::move(get_config),
|
|
|
|
promise = std::move(promise)](Result<unique_ptr<HttpQuery>> r_query) mutable {
|
2019-07-11 13:25:20 +02:00
|
|
|
promise.set_result([&]() -> Result<SimpleConfigResult> {
|
2018-12-31 20:04:05 +01:00
|
|
|
TRY_RESULT(http_query, std::move(r_query));
|
2019-07-11 13:25:20 +02:00
|
|
|
SimpleConfigResult res;
|
2019-07-11 22:32:45 +02:00
|
|
|
res.r_http_date = HttpDate::parse_http_date(http_query->get_header("date").str());
|
2019-11-19 15:58:24 +01:00
|
|
|
auto r_config = get_config(*http_query);
|
|
|
|
if (r_config.is_error()) {
|
|
|
|
res.r_config = r_config.move_as_error();
|
|
|
|
} else {
|
|
|
|
res.r_config = decode_config(r_config.ok());
|
|
|
|
}
|
2019-07-22 06:05:50 +02:00
|
|
|
return std::move(res);
|
2018-12-31 20:04:05 +01:00
|
|
|
}());
|
|
|
|
}),
|
2019-11-19 16:12:51 +01:00
|
|
|
std::move(url), std::move(headers), timeout, ttl, prefer_ipv6, SslStream::VerifyPeer::Off, std::move(content),
|
|
|
|
std::move(content_type)));
|
2018-12-31 20:04:05 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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-05-24 17:09:27 +02:00
|
|
|
string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod")
|
|
|
|
<< "v2/config.txt";
|
2018-07-02 03:21:05 +02:00
|
|
|
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
|
2019-11-19 16:12:51 +01:00
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "tcdnb.azureedge.net", {},
|
2020-01-07 16:16:57 +01:00
|
|
|
prefer_ipv6,
|
2020-01-08 15:42:55 +01:00
|
|
|
[](HttpQuery &http_query) -> Result<string> { return http_query.content_.str(); });
|
2018-03-12 19:04:03 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 21:20:15 +02:00
|
|
|
static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<SimpleConfigResult> promise,
|
|
|
|
const ConfigShared *shared_config, bool is_test, int32 scheduler_id) {
|
2018-06-30 15:35:37 +02:00
|
|
|
string name = shared_config == nullptr ? string() : shared_config->get_option_string("dc_txt_domain_name");
|
2018-07-02 03:21:05 +02:00
|
|
|
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
|
2019-11-12 20:21:37 +01:00
|
|
|
if (name.empty()) {
|
2019-07-11 13:25:20 +02:00
|
|
|
name = is_test ? "tapv3.stel.com" : "apv3.stel.com";
|
2018-06-30 15:35:37 +02:00
|
|
|
}
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2020-02-26 14:17:43 +01:00
|
|
|
VLOG(config_recoverer) << "Receive DNS response " << http_query.content_;
|
2019-11-19 16:12:51 +01:00
|
|
|
TRY_RESULT(json, json_decode(http_query.content_));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
2019-11-19 17:26:39 +01:00
|
|
|
return Status::Error("Expected JSON object");
|
2019-11-19 16:12:51 +01:00
|
|
|
}
|
|
|
|
auto &answer_object = json.get_object();
|
|
|
|
TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false));
|
|
|
|
auto &answer_array = answer.get_array();
|
|
|
|
vector<string> parts;
|
2020-06-24 13:33:20 +02:00
|
|
|
for (auto &answer_part : answer_array) {
|
|
|
|
if (answer_part.type() != JsonValue::Type::Object) {
|
2019-11-19 17:26:39 +01:00
|
|
|
return Status::Error("Expected JSON object");
|
2019-11-19 16:12:51 +01:00
|
|
|
}
|
2020-06-24 13:33:20 +02:00
|
|
|
auto &data_object = answer_part.get_object();
|
2019-11-19 16:12:51 +01:00
|
|
|
TRY_RESULT(part, get_json_object_string_field(data_object, "data", false));
|
|
|
|
parts.push_back(std::move(part));
|
|
|
|
}
|
|
|
|
if (parts.size() != 2) {
|
|
|
|
return Status::Error("Expected data in two parts");
|
|
|
|
}
|
|
|
|
string data;
|
|
|
|
if (parts[0].size() < parts[1].size()) {
|
|
|
|
data = parts[1] + parts[0];
|
|
|
|
} else {
|
|
|
|
data = parts[0] + parts[1];
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id,
|
2020-02-26 14:17:43 +01:00
|
|
|
PSTRING() << "https://" << address << "?name=" << url_encode(name) << "&type=TXT",
|
2019-11-19 16:12:51 +01:00
|
|
|
host.str(), {{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-10-03 21:20:15 +02:00
|
|
|
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id) {
|
2020-01-25 21:36:49 +01:00
|
|
|
return get_simple_config_dns("dns.google/resolve", "dns.google", std::move(promise), shared_config, is_test,
|
2019-10-03 21:20:15 +02:00
|
|
|
scheduler_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorOwn<> get_simple_config_mozilla_dns(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
|
|
|
|
bool is_test, int32 scheduler_id) {
|
|
|
|
return get_simple_config_dns("mozilla.cloudflare-dns.com/dns-query", "mozilla.cloudflare-dns.com", std::move(promise),
|
|
|
|
shared_config, is_test, scheduler_id);
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:58:24 +01:00
|
|
|
static string generate_firebase_remote_config_payload() {
|
|
|
|
unsigned char buf[17];
|
|
|
|
Random::secure_bytes(buf, sizeof(buf));
|
|
|
|
buf[0] = static_cast<unsigned char>((buf[0] & 0xF0) | 0x07);
|
|
|
|
auto app_instance_id = base64url_encode(Slice(buf, sizeof(buf)));
|
|
|
|
app_instance_id.resize(22);
|
|
|
|
return PSTRING() << "{\"app_id\":\"1:560508485281:web:4ee13a6af4e84d49e67ae0\",\"app_instance_id\":\""
|
|
|
|
<< app_instance_id << "\"}";
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult> promise,
|
|
|
|
const ConfigShared *shared_config, bool is_test,
|
|
|
|
int32 scheduler_id) {
|
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const string payload = generate_firebase_remote_config_payload();
|
|
|
|
string url =
|
|
|
|
"https://firebaseremoteconfig.googleapis.com/v1/projects/peak-vista-421/namespaces/"
|
|
|
|
"firebase:fetch?key=AIzaSyC2-kAkpDsroixRXw-sTw-Wfqo4NxjMwwM";
|
|
|
|
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 15:58:24 +01:00
|
|
|
TRY_RESULT(json, json_decode(http_query.get_arg("entries")));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
2019-11-19 17:26:39 +01:00
|
|
|
return Status::Error("Expected JSON object");
|
2019-11-19 15:58:24 +01:00
|
|
|
}
|
|
|
|
auto &entries_object = json.get_object();
|
|
|
|
TRY_RESULT(config, get_json_object_string_field(entries_object, "ipconfigv3", false));
|
|
|
|
return std::move(config);
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firebaseremoteconfig.googleapis.com",
|
2019-11-19 16:12:51 +01:00
|
|
|
{}, prefer_ipv6, std::move(get_config), payload, "application/json");
|
2019-11-19 15:58:24 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
string url = "https://reserve-5a846.firebaseio.com/ipconfigv3.json";
|
|
|
|
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 17:01:12 +01:00
|
|
|
return http_query.get_arg("content").str();
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "reserve-5a846.firebaseio.com", {},
|
|
|
|
prefer_ipv6, std::move(get_config));
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (is_test) {
|
|
|
|
promise.set_error(Status::Error(400, "Test config is not supported"));
|
|
|
|
return ActorOwn<>();
|
|
|
|
}
|
|
|
|
|
|
|
|
string url = "https://www.google.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3";
|
|
|
|
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
|
2020-01-08 15:42:55 +01:00
|
|
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
2019-11-19 17:26:39 +01:00
|
|
|
TRY_RESULT(json, json_decode(http_query.get_arg("fields")));
|
|
|
|
if (json.type() != JsonValue::Type::Object) {
|
|
|
|
return Status::Error("Expected JSON object");
|
|
|
|
}
|
|
|
|
TRY_RESULT(data, get_json_object_field(json.get_object(), "data", JsonValue::Type::Object, false));
|
|
|
|
TRY_RESULT(config, get_json_object_string_field(data.get_object(), "stringValue", false));
|
|
|
|
return std::move(config);
|
|
|
|
};
|
|
|
|
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firestore.googleapis.com", {},
|
|
|
|
prefer_ipv6, std::move(get_config));
|
|
|
|
}
|
|
|
|
|
2019-08-09 14:14:07 +02:00
|
|
|
ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorShared<> parent) {
|
2021-07-04 04:58:54 +02:00
|
|
|
class SessionCallback final : public Session::Callback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2019-07-11 13:25:20 +02:00
|
|
|
SessionCallback(ActorShared<> parent, DcOption option) : parent_(std::move(parent)), option_(std::move(option)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
void on_failed() final {
|
|
|
|
}
|
|
|
|
void on_closed() final {
|
|
|
|
}
|
2019-05-06 20:53:39 +02:00
|
|
|
void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
|
|
|
|
Promise<unique_ptr<mtproto::RawConnection>> promise) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
request_raw_connection_cnt_++;
|
2019-07-11 13:25:20 +02:00
|
|
|
VLOG(config_recoverer) << "Request full config from " << option_.get_ip_address()
|
|
|
|
<< ", try = " << request_raw_connection_cnt_;
|
2018-05-18 13:38:49 +02:00
|
|
|
if (request_raw_connection_cnt_ <= 2) {
|
2019-07-11 13:25:20 +02:00
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::request_raw_connection_by_ip,
|
|
|
|
option_.get_ip_address(),
|
|
|
|
mtproto::TransportType{mtproto::TransportType::ObfuscatedTcp,
|
|
|
|
narrow_cast<int16>(option_.get_dc_id().get_raw_id()), option_.get_secret()},
|
|
|
|
std::move(promise));
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2018-02-07 21:48:40 +01:00
|
|
|
// Delay all queries except first forever
|
2018-12-31 20:04:05 +01:00
|
|
|
delay_forever_.push_back(std::move(promise));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key) final {
|
2018-02-07 21:48:40 +01:00
|
|
|
// nop
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2019-03-15 10:00:18 +01:00
|
|
|
void on_result(NetQueryPtr net_query) final {
|
|
|
|
G()->net_query_dispatcher().dispatch(std::move(net_query));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
ActorShared<> parent_;
|
2019-07-11 13:25:20 +02:00
|
|
|
DcOption option_;
|
2018-12-31 20:04:05 +01:00
|
|
|
size_t request_raw_connection_cnt_{0};
|
2018-09-27 03:19:03 +02:00
|
|
|
std::vector<Promise<unique_ptr<mtproto::RawConnection>>> delay_forever_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class SimpleAuthData final : public AuthDataShared {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2018-05-18 13:38:49 +02:00
|
|
|
explicit SimpleAuthData(DcId dc_id) : dc_id_(dc_id) {
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
DcId dc_id() const final {
|
2018-05-18 13:38:49 +02:00
|
|
|
return dc_id_;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
const std::shared_ptr<PublicRsaKeyShared> &public_rsa_key() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
return public_rsa_key_;
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
mtproto::AuthKey get_auth_key() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
string dc_key = G()->td_db()->get_binlog_pmc()->get(auth_key_key());
|
|
|
|
|
|
|
|
mtproto::AuthKey res;
|
|
|
|
if (!dc_key.empty()) {
|
|
|
|
unserialize(res, dc_key).ensure();
|
|
|
|
}
|
|
|
|
return res;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
AuthKeyState get_auth_key_state() final {
|
2021-02-01 13:07:10 +01:00
|
|
|
return AuthDataShared::get_auth_key_state(get_auth_key());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void set_auth_key(const mtproto::AuthKey &auth_key) final {
|
2018-05-18 13:38:49 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set(auth_key_key(), serialize(auth_key));
|
|
|
|
|
|
|
|
//notify();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void update_server_time_difference(double diff) final {
|
2018-05-18 13:38:49 +02:00
|
|
|
G()->update_server_time_difference(diff);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
double get_server_time_difference() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
return G()->get_server_time_difference();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void add_auth_key_listener(unique_ptr<Listener> listener) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (listener->notify()) {
|
|
|
|
auth_key_listeners_.push_back(std::move(listener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void set_future_salts(const std::vector<mtproto::ServerSalt> &future_salts) final {
|
2018-05-18 13:38:49 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set(future_salts_key(), serialize(future_salts));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-05-18 13:38:49 +02:00
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
std::vector<mtproto::ServerSalt> get_future_salts() final {
|
2018-05-18 13:38:49 +02:00
|
|
|
string future_salts = G()->td_db()->get_binlog_pmc()->get(future_salts_key());
|
|
|
|
std::vector<mtproto::ServerSalt> res;
|
|
|
|
if (!future_salts.empty()) {
|
|
|
|
unserialize(res, future_salts).ensure();
|
|
|
|
}
|
|
|
|
return res;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-05-18 13:38:49 +02:00
|
|
|
DcId dc_id_;
|
2019-01-02 00:43:37 +01:00
|
|
|
std::shared_ptr<PublicRsaKeyShared> public_rsa_key_ =
|
|
|
|
std::make_shared<PublicRsaKeyShared>(DcId::empty(), G()->is_test_dc());
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-09-27 03:19:03 +02:00
|
|
|
std::vector<unique_ptr<Listener>> auth_key_listeners_;
|
2018-12-31 20:04:05 +01:00
|
|
|
void notify() {
|
2019-10-21 15:25:56 +02:00
|
|
|
td::remove_if(auth_key_listeners_, [&](auto &listener) { return !listener->notify(); });
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-05-18 13:38:49 +02:00
|
|
|
|
2018-05-18 18:44:46 +02:00
|
|
|
string auth_key_key() const {
|
2018-05-18 13:38:49 +02:00
|
|
|
return PSTRING() << "config_recovery_auth" << dc_id().get_raw_id();
|
|
|
|
}
|
2018-05-18 18:44:46 +02:00
|
|
|
string future_salts_key() const {
|
2018-05-18 13:38:49 +02:00
|
|
|
return PSTRING() << "config_recovery_salt" << dc_id().get_raw_id();
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class GetConfigActor final : public NetQueryCallback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
2019-08-09 14:14:07 +02:00
|
|
|
GetConfigActor(DcOption option, Promise<FullConfig> promise, ActorShared<> parent)
|
|
|
|
: option_(std::move(option)), promise_(std::move(promise)), parent_(std::move(parent)) {
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final {
|
2019-07-11 13:25:20 +02:00
|
|
|
auto auth_data = std::make_shared<SimpleAuthData>(option_.get_dc_id());
|
2019-12-18 01:47:51 +01:00
|
|
|
int32 raw_dc_id = option_.get_dc_id().get_raw_id();
|
2019-07-11 13:25:20 +02:00
|
|
|
auto session_callback = make_unique<SessionCallback>(actor_shared(this, 1), std::move(option_));
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-12-18 01:47:51 +01:00
|
|
|
int32 int_dc_id = raw_dc_id;
|
2018-05-23 18:49:05 +02:00
|
|
|
if (G()->is_test_dc()) {
|
|
|
|
int_dc_id += 10000;
|
|
|
|
}
|
2019-12-18 01:47:51 +01:00
|
|
|
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data), raw_dc_id,
|
|
|
|
int_dc_id, false /*is_main*/, true /*use_pfs*/, false /*is_cdn*/,
|
|
|
|
false /*need_destroy_auth_key*/, mtproto::AuthKey(),
|
|
|
|
std::vector<mtproto::ServerSalt>());
|
2020-03-15 23:01:14 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), DcId::empty());
|
2020-06-10 01:44:54 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
2018-12-31 20:04:05 +01:00
|
|
|
query->set_callback(actor_shared(this));
|
2020-06-10 01:44:54 +02:00
|
|
|
query->dispatch_ttl_ = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(session_, &Session::send, std::move(query));
|
|
|
|
set_timeout_in(10);
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void on_result(NetQueryPtr query) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
promise_.set_result(fetch_result<telegram_api::help_getConfig>(std::move(query)));
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup_shared() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (get_link_token() == 1) {
|
2018-05-18 13:38:49 +02:00
|
|
|
if (promise_) {
|
|
|
|
promise_.set_error(Status::Error("Failed"));
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
session_.reset();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void timeout_expired() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
promise_.set_error(Status::Error("Timeout expired"));
|
2018-05-18 13:38:49 +02:00
|
|
|
session_.reset();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
DcOption option_;
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<Session> session_;
|
|
|
|
Promise<FullConfig> promise_;
|
2019-08-09 14:14:07 +02:00
|
|
|
ActorShared<> parent_;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2019-08-09 14:14:07 +02:00
|
|
|
return ActorOwn<>(create_actor<GetConfigActor>("GetConfigActor", option, std::move(promise), std::move(parent)));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class ConfigRecoverer final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit ConfigRecoverer(ActorShared<> parent) : parent_(std::move(parent)) {
|
2020-06-18 01:42:01 +02:00
|
|
|
connecting_since_ = Time::now();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_dc_options_update(DcOptions dc_options) {
|
|
|
|
dc_options_update_ = dc_options;
|
|
|
|
update_dc_options();
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void on_network(bool has_network, uint32 network_generation) {
|
|
|
|
has_network_ = has_network;
|
|
|
|
if (network_generation_ != network_generation) {
|
|
|
|
if (has_network_) {
|
|
|
|
has_network_since_ = Time::now_cached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
void on_online(bool is_online) {
|
2018-08-04 23:35:50 +02:00
|
|
|
if (is_online_ == is_online) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
is_online_ = is_online;
|
2018-08-04 23:35:50 +02:00
|
|
|
if (is_online) {
|
|
|
|
if (simple_config_.dc_options.empty()) {
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = 0;
|
2018-08-04 23:35:50 +02:00
|
|
|
}
|
|
|
|
if (full_config_ == nullptr) {
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = 0;
|
2018-08-04 23:35:50 +02:00
|
|
|
}
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
loop();
|
|
|
|
}
|
|
|
|
void on_connecting(bool is_connecting) {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "On connecting " << is_connecting;
|
2018-12-31 20:04:05 +01:00
|
|
|
if (is_connecting && !is_connecting_) {
|
|
|
|
connecting_since_ = Time::now_cached();
|
|
|
|
}
|
|
|
|
is_connecting_ = is_connecting;
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
2018-05-24 17:09:27 +02:00
|
|
|
static bool check_phone_number_rules(Slice phone_number, Slice rules) {
|
2018-05-24 18:40:00 +02:00
|
|
|
if (rules.empty() || phone_number.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-24 17:09:27 +02:00
|
|
|
bool found = false;
|
|
|
|
for (auto prefix : full_split(rules, ',')) {
|
|
|
|
if (prefix.empty()) {
|
|
|
|
found = true;
|
|
|
|
} else if (prefix[0] == '+' && begins_with(phone_number, prefix.substr(1))) {
|
|
|
|
found = true;
|
|
|
|
} else if (prefix[0] == '-' && begins_with(phone_number, prefix.substr(1))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Invalid prefix rule " << prefix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
void on_simple_config(Result<SimpleConfigResult> r_simple_config_result, bool dummy) {
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_query_.reset();
|
|
|
|
dc_options_i_ = 0;
|
2019-07-11 13:25:20 +02:00
|
|
|
|
|
|
|
SimpleConfigResult cfg;
|
|
|
|
if (r_simple_config_result.is_error()) {
|
|
|
|
cfg.r_http_date = r_simple_config_result.error().clone();
|
|
|
|
cfg.r_config = r_simple_config_result.move_as_error();
|
|
|
|
} else {
|
|
|
|
cfg = r_simple_config_result.move_as_ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg.r_http_date.is_ok() && (date_option_i_ == 0 || cfg.r_config.is_error())) {
|
|
|
|
G()->update_dns_time_difference(cfg.r_http_date.ok() - Time::now());
|
|
|
|
} else if (cfg.r_config.is_ok()) {
|
|
|
|
G()->update_dns_time_difference(cfg.r_config.ok()->date_ - Time::now());
|
|
|
|
}
|
|
|
|
date_option_i_ = (date_option_i_ + 1) % 2;
|
|
|
|
|
|
|
|
do_on_simple_config(std::move(cfg.r_config));
|
|
|
|
update_dc_options();
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void do_on_simple_config(Result<SimpleConfig> r_simple_config) {
|
2018-05-24 17:09:27 +02:00
|
|
|
if (r_simple_config.is_ok()) {
|
|
|
|
auto config = r_simple_config.move_as_ok();
|
2018-11-17 22:24:19 +01:00
|
|
|
VLOG(config_recoverer) << "Receive raw " << to_string(config);
|
2018-05-24 17:09:27 +02:00
|
|
|
if (config->expires_ >= G()->unix_time()) {
|
|
|
|
string phone_number = G()->shared_config().get_option_string("my_phone_number");
|
|
|
|
simple_config_.dc_options.clear();
|
|
|
|
|
|
|
|
for (auto &rule : config->rules_) {
|
|
|
|
if (check_phone_number_rules(phone_number, rule->phone_prefix_rules_) && DcId::is_valid(rule->dc_id_)) {
|
|
|
|
DcId dc_id = DcId::internal(rule->dc_id_);
|
|
|
|
for (auto &ip_port : rule->ips_) {
|
|
|
|
DcOption option(dc_id, *ip_port);
|
|
|
|
if (option.is_valid()) {
|
|
|
|
simple_config_.dc_options.push_back(std::move(option));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VLOG(config_recoverer) << "Got SimpleConfig " << simple_config_;
|
2019-01-23 04:13:51 +01:00
|
|
|
} else {
|
|
|
|
VLOG(config_recoverer) << "Config has expired at " << config->expires_;
|
2018-05-24 17:09:27 +02:00
|
|
|
}
|
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = get_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_at_ = Time::now_cached();
|
|
|
|
for (size_t i = 1; i < simple_config_.dc_options.size(); i++) {
|
|
|
|
std::swap(simple_config_.dc_options[i], simple_config_.dc_options[Random::fast(0, static_cast<int>(i))]);
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-24 17:09:27 +02:00
|
|
|
VLOG(config_recoverer) << "Get SimpleConfig error " << r_simple_config.error();
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_ = DcOptions();
|
2019-02-10 01:45:15 +01:00
|
|
|
simple_config_expires_at_ = get_failed_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_full_config(Result<FullConfig> r_full_config, bool dummy) {
|
|
|
|
full_config_query_.reset();
|
|
|
|
if (r_full_config.is_ok()) {
|
|
|
|
full_config_ = r_full_config.move_as_ok();
|
|
|
|
VLOG(config_recoverer) << "Got FullConfig " << to_string(full_config_);
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = get_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(full_config_->dc_options_));
|
|
|
|
} else {
|
|
|
|
VLOG(config_recoverer) << "Get FullConfig error " << r_full_config.error();
|
|
|
|
full_config_ = FullConfig();
|
2019-02-10 01:45:15 +01:00
|
|
|
full_config_expires_at_ = get_failed_config_expire_time();
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
loop();
|
|
|
|
}
|
|
|
|
|
2018-05-03 12:18:07 +02:00
|
|
|
bool expect_blocking() const {
|
|
|
|
return G()->shared_config().get_option_boolean("expect_blocking", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
double get_config_expire_time() const {
|
2018-08-04 23:35:50 +02:00
|
|
|
auto offline_delay = is_online_ ? 0 : 5 * 60;
|
|
|
|
auto expire_time = expect_blocking() ? Random::fast(2 * 60, 3 * 60) : Random::fast(20 * 60, 30 * 60);
|
|
|
|
return Time::now() + offline_delay + expire_time;
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double get_failed_config_expire_time() const {
|
2018-08-04 23:35:50 +02:00
|
|
|
auto offline_delay = is_online_ ? 0 : 5 * 60;
|
|
|
|
auto expire_time = expect_blocking() ? Random::fast(5, 7) : Random::fast(15, 30);
|
|
|
|
return Time::now() + offline_delay + expire_time;
|
2018-05-03 12:18:07 +02:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
bool is_connecting_{false};
|
|
|
|
double connecting_since_{0};
|
|
|
|
|
|
|
|
bool is_online_{false};
|
|
|
|
|
|
|
|
bool has_network_{false};
|
|
|
|
double has_network_since_{0};
|
|
|
|
uint32 network_generation_{0};
|
|
|
|
|
|
|
|
DcOptions simple_config_;
|
2019-02-10 01:45:15 +01:00
|
|
|
double simple_config_expires_at_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
double simple_config_at_{0};
|
|
|
|
ActorOwn<> simple_config_query_;
|
|
|
|
|
|
|
|
DcOptions dc_options_update_;
|
|
|
|
|
|
|
|
DcOptions dc_options_; // dc_options_update_ + simple_config_
|
|
|
|
double dc_options_at_{0};
|
|
|
|
size_t dc_options_i_;
|
|
|
|
|
2019-07-11 13:25:20 +02:00
|
|
|
size_t date_option_i_{0};
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
FullConfig full_config_;
|
2019-02-10 01:45:15 +01:00
|
|
|
double full_config_expires_at_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
ActorOwn<> full_config_query_;
|
|
|
|
|
|
|
|
uint32 ref_cnt_{1};
|
|
|
|
bool close_flag_{false};
|
2020-06-01 22:52:25 +02:00
|
|
|
uint32 simple_config_turn_{0};
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup_shared() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
try_stop();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
close_flag_ = true;
|
|
|
|
full_config_query_.reset();
|
|
|
|
simple_config_query_.reset();
|
|
|
|
try_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void try_stop() {
|
|
|
|
if (ref_cnt_ == 0) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double max_connecting_delay() const {
|
2018-05-03 12:18:07 +02:00
|
|
|
return expect_blocking() ? 5 : 20;
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
void loop() final {
|
2018-12-31 20:04:05 +01:00
|
|
|
if (close_flag_) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-07 21:48:40 +01:00
|
|
|
if (is_connecting_) {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Failed to connect for " << Time::now() - connecting_since_;
|
2018-02-07 21:48:40 +01:00
|
|
|
} else {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Successfully connected in " << Time::now() - connecting_since_;
|
2018-02-07 21:48:40 +01:00
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
Timestamp wakeup_timestamp;
|
|
|
|
auto check_timeout = [&](Timestamp timestamp) {
|
|
|
|
if (timestamp.at() < Time::now_cached()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
wakeup_timestamp.relax(timestamp);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool has_connecting_problem =
|
|
|
|
is_connecting_ && check_timeout(Timestamp::at(connecting_since_ + max_connecting_delay()));
|
2019-02-10 01:45:15 +01:00
|
|
|
bool is_valid_simple_config = !check_timeout(Timestamp::at(simple_config_expires_at_));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (!is_valid_simple_config && !simple_config_.dc_options.empty()) {
|
|
|
|
simple_config_ = DcOptions();
|
|
|
|
update_dc_options();
|
|
|
|
}
|
|
|
|
bool need_simple_config = has_connecting_problem && !is_valid_simple_config && simple_config_query_.empty();
|
|
|
|
bool has_dc_options = !dc_options_.dc_options.empty();
|
2019-02-10 01:45:15 +01:00
|
|
|
bool is_valid_full_config = !check_timeout(Timestamp::at(full_config_expires_at_));
|
2018-12-31 20:04:05 +01:00
|
|
|
bool need_full_config = has_connecting_problem && has_dc_options && !is_valid_full_config &&
|
2018-05-03 12:18:07 +02:00
|
|
|
full_config_query_.empty() &&
|
|
|
|
check_timeout(Timestamp::at(dc_options_at_ + (expect_blocking() ? 5 : 10)));
|
2018-12-31 20:04:05 +01:00
|
|
|
if (need_simple_config) {
|
|
|
|
ref_cnt_++;
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Ask simple config with turn " << simple_config_turn_;
|
2019-07-11 13:25:20 +02:00
|
|
|
auto promise =
|
|
|
|
PromiseCreator::lambda([actor_id = actor_shared(this)](Result<SimpleConfigResult> r_simple_config) {
|
|
|
|
send_closure(actor_id, &ConfigRecoverer::on_simple_config, std::move(r_simple_config), false);
|
|
|
|
});
|
2020-02-26 16:15:19 +01:00
|
|
|
auto get_simple_config = [&] {
|
2020-06-01 22:52:25 +02:00
|
|
|
switch (simple_config_turn_ % 10) {
|
|
|
|
case 6:
|
2018-05-24 17:09:27 +02:00
|
|
|
return get_simple_config_azure;
|
2020-06-01 22:52:25 +02:00
|
|
|
case 2:
|
2019-11-19 15:58:24 +01:00
|
|
|
return get_simple_config_firebase_remote_config;
|
2019-11-19 17:01:12 +01:00
|
|
|
case 4:
|
|
|
|
return get_simple_config_firebase_realtime;
|
2020-06-01 22:52:25 +02:00
|
|
|
case 9:
|
2019-11-19 17:26:39 +01:00
|
|
|
return get_simple_config_firebase_firestore;
|
2018-05-24 17:09:27 +02:00
|
|
|
case 0:
|
2020-06-01 22:52:25 +02:00
|
|
|
case 3:
|
|
|
|
case 8:
|
2018-03-12 19:04:03 +01:00
|
|
|
return get_simple_config_google_dns;
|
2019-10-03 21:28:01 +02:00
|
|
|
case 1:
|
2020-06-01 22:52:25 +02:00
|
|
|
case 5:
|
|
|
|
case 7:
|
2019-10-03 21:28:01 +02:00
|
|
|
default:
|
|
|
|
return get_simple_config_mozilla_dns;
|
2018-03-12 19:04:03 +01:00
|
|
|
}
|
|
|
|
}();
|
2018-06-30 15:35:37 +02:00
|
|
|
simple_config_query_ =
|
|
|
|
get_simple_config(std::move(promise), &G()->shared_config(), G()->is_test_dc(), G()->get_gc_scheduler_id());
|
2018-12-31 20:04:05 +01:00
|
|
|
simple_config_turn_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_full_config) {
|
|
|
|
ref_cnt_++;
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Ask full config with dc_options_i_ = " << dc_options_i_;
|
2019-07-11 13:25:20 +02:00
|
|
|
full_config_query_ =
|
|
|
|
get_full_config(dc_options_.dc_options[dc_options_i_],
|
2019-08-09 14:14:07 +02:00
|
|
|
PromiseCreator::lambda([actor_id = actor_id(this)](Result<FullConfig> r_full_config) {
|
2019-07-11 13:25:20 +02:00
|
|
|
send_closure(actor_id, &ConfigRecoverer::on_full_config, std::move(r_full_config), false);
|
2019-08-09 14:14:07 +02:00
|
|
|
}),
|
|
|
|
actor_shared(this));
|
2018-12-31 20:04:05 +01:00
|
|
|
dc_options_i_ = (dc_options_i_ + 1) % dc_options_.dc_options.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wakeup_timestamp) {
|
|
|
|
VLOG(config_recoverer) << "Wakeup in " << format::as_time(wakeup_timestamp.in());
|
|
|
|
set_timeout_at(wakeup_timestamp.at());
|
|
|
|
} else {
|
2020-06-01 22:52:25 +02:00
|
|
|
VLOG(config_recoverer) << "Wakeup never";
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void start_up() final {
|
2021-07-04 04:58:54 +02:00
|
|
|
class StateCallback final : public StateManager::Callback {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit StateCallback(ActorId<ConfigRecoverer> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool on_state(StateManager::State state) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(parent_, &ConfigRecoverer::on_connecting, state == StateManager::State::Connecting);
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool on_network(NetType network_type, uint32 network_generation) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(parent_, &ConfigRecoverer::on_network, network_type != NetType::None, network_generation);
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
2021-07-03 22:51:36 +02:00
|
|
|
bool on_online(bool online_flag) final {
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(parent_, &ConfigRecoverer::on_online, online_flag);
|
|
|
|
return parent_.is_alive();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ActorId<ConfigRecoverer> parent_;
|
|
|
|
};
|
|
|
|
send_closure(G()->state_manager(), &StateManager::add_callback, make_unique<StateCallback>(actor_id(this)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_dc_options() {
|
2020-06-24 13:33:20 +02:00
|
|
|
auto new_dc_options = simple_config_.dc_options;
|
|
|
|
new_dc_options.insert(new_dc_options.begin(), dc_options_update_.dc_options.begin(),
|
|
|
|
dc_options_update_.dc_options.end());
|
|
|
|
if (new_dc_options != dc_options_.dc_options) {
|
|
|
|
dc_options_.dc_options = std::move(new_dc_options);
|
2018-12-31 20:04:05 +01:00
|
|
|
dc_options_i_ = 0;
|
|
|
|
dc_options_at_ = Time::now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ConfigManager::ConfigManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
2020-08-23 19:34:05 +02:00
|
|
|
lazy_request_flood_control_.add_limit(20, 1);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::start_up() {
|
2020-08-11 15:31:50 +02:00
|
|
|
config_recoverer_ = create_actor<ConfigRecoverer>("Recoverer", create_reference());
|
2018-12-31 20:04:05 +01:00
|
|
|
send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, load_dc_options_update());
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
auto expire_time = load_config_expire_time();
|
2020-07-26 14:41:32 +02:00
|
|
|
if (expire_time.is_in_past() || true) {
|
2018-12-31 20:04:05 +01:00
|
|
|
request_config();
|
|
|
|
} else {
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = expire_time;
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:31:50 +02:00
|
|
|
ActorShared<> ConfigManager::create_reference() {
|
|
|
|
ref_cnt_++;
|
|
|
|
return actor_shared(this, REFCNT_TOKEN);
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::hangup_shared() {
|
2020-08-11 15:31:50 +02:00
|
|
|
LOG_CHECK(get_link_token() == REFCNT_TOKEN) << "Expected REFCNT_TOKEN, got " << get_link_token();
|
2018-12-31 20:04:05 +01:00
|
|
|
ref_cnt_--;
|
|
|
|
try_stop();
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::hangup() {
|
|
|
|
ref_cnt_--;
|
|
|
|
config_recoverer_.reset();
|
|
|
|
try_stop();
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::loop() {
|
2019-02-10 01:45:15 +01:00
|
|
|
if (expire_time_ && expire_time_.is_in_past()) {
|
2018-12-31 20:04:05 +01:00
|
|
|
request_config();
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = {};
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::try_stop() {
|
|
|
|
if (ref_cnt_ == 0) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::request_config() {
|
2019-12-19 21:00:28 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
if (config_sent_cnt_ != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2020-07-16 21:36:59 +02:00
|
|
|
|
2020-08-23 19:34:05 +02:00
|
|
|
lazy_request_flood_control_.add_event(static_cast<int32>(Timestamp::now().at()));
|
2018-12-31 20:04:05 +01:00
|
|
|
request_config_from_dc_impl(DcId::main());
|
|
|
|
}
|
|
|
|
|
2020-07-16 20:37:13 +02:00
|
|
|
void ConfigManager::lazy_request_config() {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config_sent_cnt_ != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-23 19:34:05 +02:00
|
|
|
expire_time_.relax(Timestamp::at(lazy_request_flood_control_.get_wakeup_at()));
|
2020-07-16 20:37:13 +02:00
|
|
|
set_timeout_at(expire_time_.at());
|
|
|
|
}
|
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
void ConfigManager::get_app_config(Promise<td_api::object_ptr<td_api::JsonValue>> &&promise) {
|
2019-12-19 21:00:28 +01:00
|
|
|
if (G()->close_flag()) {
|
|
|
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
|
|
|
}
|
|
|
|
|
2019-12-23 14:14:43 +01:00
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
|
|
|
if (auth_manager != nullptr && auth_manager->is_bot()) {
|
|
|
|
return promise.set_value(nullptr);
|
|
|
|
}
|
|
|
|
|
2019-12-19 02:23:14 +01:00
|
|
|
get_app_config_queries_.push_back(std::move(promise));
|
|
|
|
if (get_app_config_queries_.size() == 1) {
|
2020-03-15 23:01:14 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getAppConfig());
|
2020-06-10 01:44:54 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
2020-03-14 23:44:21 +01:00
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 1));
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 21:00:28 +01:00
|
|
|
void ConfigManager::get_content_settings(Promise<Unit> &&promise) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
2019-12-20 14:16:30 +01:00
|
|
|
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
|
2019-12-19 21:00:28 +01:00
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
get_content_settings_queries_.push_back(std::move(promise));
|
|
|
|
if (get_content_settings_queries_.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2020-03-15 22:17:11 +01:00
|
|
|
G()->net_query_creator().create(telegram_api::account_getContentSettings()), actor_shared(this, 2));
|
2019-12-19 21:00:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 00:58:41 +01:00
|
|
|
void ConfigManager::set_content_settings(bool ignore_sensitive_content_restrictions, Promise<Unit> &&promise) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
|
|
|
}
|
|
|
|
|
2019-12-20 02:06:38 +01:00
|
|
|
last_set_content_settings_ = ignore_sensitive_content_restrictions;
|
2019-12-20 00:58:41 +01:00
|
|
|
auto &queries = set_content_settings_queries_[ignore_sensitive_content_restrictions];
|
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (!is_set_content_settings_request_sent_) {
|
|
|
|
is_set_content_settings_request_sent_ = true;
|
|
|
|
int32 flags = 0;
|
|
|
|
if (ignore_sensitive_content_restrictions) {
|
|
|
|
flags |= telegram_api::account_setContentSettings::SENSITIVE_ENABLED_MASK;
|
|
|
|
}
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2020-03-15 22:17:11 +01:00
|
|
|
G()->net_query_creator().create(telegram_api::account_setContentSettings(flags, false /*ignored*/)),
|
2019-12-20 00:58:41 +01:00
|
|
|
actor_shared(this, 3 + static_cast<uint64>(ignore_sensitive_content_restrictions)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::get_global_privacy_settings(Promise<Unit> &&promise) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto auth_manager = G()->td().get_actor_unsafe()->auth_manager_.get();
|
|
|
|
if (auth_manager == nullptr || !auth_manager->is_authorized() || auth_manager->is_bot()) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
get_global_privacy_settings_queries_.push_back(std::move(promise));
|
|
|
|
if (get_global_privacy_settings_queries_.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
|
|
|
G()->net_query_creator().create(telegram_api::account_getGlobalPrivacySettings()), actor_shared(this, 5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::set_archive_and_mute(bool archive_and_mute, Promise<Unit> &&promise) {
|
|
|
|
if (G()->close_flag()) {
|
|
|
|
return promise.set_error(Status::Error(500, "Request aborted"));
|
|
|
|
}
|
2020-07-11 22:50:21 +02:00
|
|
|
if (archive_and_mute) {
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats});
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
|
|
|
|
last_set_archive_and_mute_ = archive_and_mute;
|
|
|
|
auto &queries = set_archive_and_mute_queries_[archive_and_mute];
|
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (!is_set_archive_and_mute_request_sent_) {
|
|
|
|
is_set_archive_and_mute_request_sent_ = true;
|
|
|
|
int32 flags = telegram_api::globalPrivacySettings::ARCHIVE_AND_MUTE_NEW_NONCONTACT_PEERS_MASK;
|
|
|
|
auto settings = make_tl_object<telegram_api::globalPrivacySettings>(flags, archive_and_mute);
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
|
|
|
G()->net_query_creator().create(telegram_api::account_setGlobalPrivacySettings(std::move(settings))),
|
|
|
|
actor_shared(this, 6 + static_cast<uint64>(archive_and_mute)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::on_dc_options_update(DcOptions dc_options) {
|
|
|
|
save_dc_options_update(dc_options);
|
|
|
|
send_closure(config_recoverer_, &ConfigRecoverer::on_dc_options_update, std::move(dc_options));
|
|
|
|
if (dc_options.dc_options.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = Timestamp::now();
|
|
|
|
save_config_expire(expire_time_);
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::request_config_from_dc_impl(DcId dc_id) {
|
|
|
|
config_sent_cnt_++;
|
2020-03-15 23:01:14 +01:00
|
|
|
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), dc_id);
|
2020-06-10 01:44:54 +02:00
|
|
|
query->total_timeout_limit_ = 60 * 60 * 24;
|
2020-08-27 00:27:34 +02:00
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(std::move(query), actor_shared(this, 8));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::do_set_ignore_sensitive_content_restrictions(bool ignore_sensitive_content_restrictions) {
|
2019-12-20 14:11:58 +01:00
|
|
|
G()->shared_config().set_option_boolean("ignore_sensitive_content_restrictions",
|
|
|
|
ignore_sensitive_content_restrictions);
|
2019-12-20 02:19:40 +01:00
|
|
|
bool have_ignored_restriction_reasons = G()->shared_config().have_option("ignored_restriction_reasons");
|
|
|
|
if (have_ignored_restriction_reasons != ignore_sensitive_content_restrictions) {
|
|
|
|
get_app_config(Auto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 19:28:30 +02:00
|
|
|
void ConfigManager::do_set_archive_and_mute(bool archive_and_mute) {
|
2020-07-11 22:50:21 +02:00
|
|
|
if (archive_and_mute) {
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats});
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
G()->shared_config().set_option_boolean("archive_and_mute_new_chats_from_unknown_users", archive_and_mute);
|
|
|
|
}
|
|
|
|
|
2021-06-11 01:13:46 +02:00
|
|
|
void ConfigManager::hide_suggested_action(SuggestedAction suggested_action) {
|
|
|
|
remove_suggested_action(suggested_actions_, suggested_action);
|
|
|
|
}
|
|
|
|
|
2020-07-12 14:04:49 +02:00
|
|
|
void ConfigManager::dismiss_suggested_action(SuggestedAction suggested_action, Promise<Unit> &&promise) {
|
2021-02-20 23:06:45 +01:00
|
|
|
auto action_str = suggested_action.get_suggested_action_str();
|
2020-07-12 14:04:49 +02:00
|
|
|
if (action_str.empty()) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!td::contains(suggested_actions_, suggested_action)) {
|
|
|
|
return promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
|
|
|
|
dismiss_suggested_action_request_count_++;
|
2021-02-20 23:06:45 +01:00
|
|
|
auto type = static_cast<int32>(suggested_action.type_);
|
|
|
|
auto &queries = dismiss_suggested_action_queries_[type];
|
2020-07-12 14:04:49 +02:00
|
|
|
queries.push_back(std::move(promise));
|
|
|
|
if (queries.size() == 1) {
|
|
|
|
G()->net_query_dispatcher().dispatch_with_callback(
|
2021-02-02 00:00:28 +01:00
|
|
|
G()->net_query_creator().create(
|
|
|
|
telegram_api::help_dismissSuggestion(make_tl_object<telegram_api::inputPeerEmpty>(), action_str)),
|
2021-02-20 23:06:45 +01:00
|
|
|
actor_shared(this, 100 + type));
|
2020-07-12 14:04:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
void ConfigManager::on_result(NetQueryPtr res) {
|
2019-12-19 02:23:14 +01:00
|
|
|
auto token = get_link_token();
|
2020-07-12 14:04:49 +02:00
|
|
|
if (token >= 100 && token <= 200) {
|
2021-02-20 23:06:45 +01:00
|
|
|
auto type = static_cast<int32>(token - 100);
|
|
|
|
SuggestedAction suggested_action{static_cast<SuggestedAction::Type>(type)};
|
|
|
|
auto promises = std::move(dismiss_suggested_action_queries_[type]);
|
|
|
|
dismiss_suggested_action_queries_.erase(type);
|
2020-07-12 14:04:49 +02:00
|
|
|
CHECK(!promises.empty());
|
|
|
|
CHECK(dismiss_suggested_action_request_count_ >= promises.size());
|
|
|
|
dismiss_suggested_action_request_count_ -= promises.size();
|
|
|
|
|
|
|
|
auto result_ptr = fetch_result<telegram_api::help_dismissSuggestion>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-02-22 16:25:49 +01:00
|
|
|
remove_suggested_action(suggested_actions_, suggested_action);
|
2020-07-12 14:04:49 +02:00
|
|
|
get_app_config(Auto());
|
|
|
|
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
if (token == 6 || token == 7) {
|
|
|
|
is_set_archive_and_mute_request_sent_ = false;
|
|
|
|
bool archive_and_mute = (token == 7);
|
|
|
|
auto promises = std::move(set_archive_and_mute_queries_[archive_and_mute]);
|
|
|
|
set_archive_and_mute_queries_[archive_and_mute].clear();
|
|
|
|
CHECK(!promises.empty());
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_setGlobalPrivacySettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (last_set_archive_and_mute_ == archive_and_mute) {
|
|
|
|
do_set_archive_and_mute(archive_and_mute);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_archive_and_mute_queries_[!archive_and_mute].empty()) {
|
|
|
|
if (archive_and_mute == last_set_archive_and_mute_) {
|
|
|
|
promises = std::move(set_archive_and_mute_queries_[!archive_and_mute]);
|
|
|
|
set_archive_and_mute_queries_[!archive_and_mute].clear();
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_archive_and_mute(!archive_and_mute, Auto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (token == 5) {
|
|
|
|
auto promises = std::move(get_global_privacy_settings_queries_);
|
|
|
|
get_global_privacy_settings_queries_.clear();
|
|
|
|
CHECK(!promises.empty());
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_getGlobalPrivacySettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = result_ptr.move_as_ok();
|
|
|
|
if ((result->flags_ & telegram_api::globalPrivacySettings::ARCHIVE_AND_MUTE_NEW_NONCONTACT_PEERS_MASK) != 0) {
|
|
|
|
do_set_archive_and_mute(result->archive_and_mute_new_noncontact_peers_);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong response: " << to_string(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-12-20 00:58:41 +01:00
|
|
|
if (token == 3 || token == 4) {
|
|
|
|
is_set_content_settings_request_sent_ = false;
|
|
|
|
bool ignore_sensitive_content_restrictions = (token == 4);
|
|
|
|
auto promises = std::move(set_content_settings_queries_[ignore_sensitive_content_restrictions]);
|
|
|
|
set_content_settings_queries_[ignore_sensitive_content_restrictions].clear();
|
|
|
|
CHECK(!promises.empty());
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_setContentSettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
|
|
|
} else {
|
2019-12-20 02:19:40 +01:00
|
|
|
if (G()->shared_config().get_option_boolean("can_ignore_sensitive_content_restrictions") &&
|
2019-12-20 02:06:38 +01:00
|
|
|
last_set_content_settings_ == ignore_sensitive_content_restrictions) {
|
2020-07-10 19:28:30 +02:00
|
|
|
do_set_ignore_sensitive_content_restrictions(ignore_sensitive_content_restrictions);
|
2019-12-20 00:58:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!set_content_settings_queries_[!ignore_sensitive_content_restrictions].empty()) {
|
2019-12-20 02:06:38 +01:00
|
|
|
if (ignore_sensitive_content_restrictions == last_set_content_settings_) {
|
|
|
|
promises = std::move(set_content_settings_queries_[!ignore_sensitive_content_restrictions]);
|
|
|
|
set_content_settings_queries_[!ignore_sensitive_content_restrictions].clear();
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_content_settings(!ignore_sensitive_content_restrictions, Auto());
|
|
|
|
}
|
2019-12-20 00:58:41 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-12-19 21:00:28 +01:00
|
|
|
if (token == 2) {
|
|
|
|
auto promises = std::move(get_content_settings_queries_);
|
|
|
|
get_content_settings_queries_.clear();
|
|
|
|
CHECK(!promises.empty());
|
|
|
|
auto result_ptr = fetch_result<telegram_api::account_getContentSettings>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto result = result_ptr.move_as_ok();
|
2020-07-10 19:28:30 +02:00
|
|
|
do_set_ignore_sensitive_content_restrictions(result->sensitive_enabled_);
|
2019-12-20 02:19:40 +01:00
|
|
|
G()->shared_config().set_option_boolean("can_ignore_sensitive_content_restrictions", result->sensitive_can_change_);
|
2019-12-19 21:00:28 +01:00
|
|
|
|
|
|
|
for (auto &promise : promises) {
|
|
|
|
promise.set_value(Unit());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
if (token == 1) {
|
|
|
|
auto promises = std::move(get_app_config_queries_);
|
|
|
|
get_app_config_queries_.clear();
|
|
|
|
CHECK(!promises.empty());
|
|
|
|
auto result_ptr = fetch_result<telegram_api::help_getAppConfig>(std::move(res));
|
|
|
|
if (result_ptr.is_error()) {
|
|
|
|
for (auto &promise : promises) {
|
2019-12-19 02:58:03 +01:00
|
|
|
if (!promise) {
|
|
|
|
promise.set_value(nullptr);
|
|
|
|
} else {
|
|
|
|
promise.set_error(result_ptr.error().clone());
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
2019-12-19 21:00:28 +01:00
|
|
|
return;
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto result = result_ptr.move_as_ok();
|
2019-12-19 02:58:03 +01:00
|
|
|
process_app_config(result);
|
2019-12-19 02:23:14 +01:00
|
|
|
for (auto &promise : promises) {
|
2019-12-19 02:58:03 +01:00
|
|
|
if (!promise) {
|
|
|
|
promise.set_value(nullptr);
|
|
|
|
} else {
|
|
|
|
promise.set_value(convert_json_value_object(result));
|
|
|
|
}
|
2019-12-19 02:23:14 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-27 00:27:34 +02:00
|
|
|
CHECK(token == 8);
|
2018-12-31 20:04:05 +01:00
|
|
|
CHECK(config_sent_cnt_ > 0);
|
|
|
|
config_sent_cnt_--;
|
|
|
|
auto r_config = fetch_result<telegram_api::help_getConfig>(std::move(res));
|
|
|
|
if (r_config.is_error()) {
|
2018-04-19 19:21:26 +02:00
|
|
|
if (!G()->close_flag()) {
|
2020-04-21 02:29:20 +02:00
|
|
|
LOG(WARNING) << "Failed to get config: " << r_config.error();
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = Timestamp::in(60.0); // try again in a minute
|
|
|
|
set_timeout_in(expire_time_.in());
|
2018-04-19 19:21:26 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
|
|
|
on_dc_options_update(DcOptions());
|
|
|
|
process_config(r_config.move_as_ok());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::save_dc_options_update(DcOptions dc_options) {
|
|
|
|
if (dc_options.dc_options.empty()) {
|
|
|
|
G()->td_db()->get_binlog_pmc()->erase("dc_options_update");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
G()->td_db()->get_binlog_pmc()->set("dc_options_update", log_event_store(dc_options).as_slice().str());
|
|
|
|
}
|
|
|
|
|
|
|
|
DcOptions ConfigManager::load_dc_options_update() {
|
|
|
|
auto log_event_dc_options = G()->td_db()->get_binlog_pmc()->get("dc_options_update");
|
|
|
|
DcOptions dc_options;
|
|
|
|
if (!log_event_dc_options.empty()) {
|
|
|
|
log_event_parse(dc_options, log_event_dc_options).ensure();
|
|
|
|
}
|
|
|
|
return dc_options;
|
|
|
|
}
|
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
Timestamp ConfigManager::load_config_expire_time() {
|
|
|
|
auto expires_in = to_integer<int32>(G()->td_db()->get_binlog_pmc()->get("config_expire")) - Clocks::system();
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-02-10 01:45:15 +01:00
|
|
|
if (expires_in < 0 || expires_in > 60 * 60 /* 1 hour */) {
|
2018-12-31 20:04:05 +01:00
|
|
|
return Timestamp::now();
|
|
|
|
} else {
|
2019-02-10 01:45:15 +01:00
|
|
|
return Timestamp::in(expires_in);
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::save_config_expire(Timestamp timestamp) {
|
2020-07-26 14:41:32 +02:00
|
|
|
G()->td_db()->get_binlog_pmc()->set("config_expire", to_string(static_cast<int>(Clocks::system() + timestamp.in())));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::process_config(tl_object_ptr<telegram_api::config> config) {
|
|
|
|
bool is_from_main_dc = G()->net_query_dispatcher().main_dc_id().get_value() == config->this_dc_;
|
|
|
|
|
|
|
|
LOG(INFO) << to_string(config);
|
2019-12-19 02:58:03 +01:00
|
|
|
auto reload_in = clamp(config->expires_ - config->date_, 60, 86400);
|
2018-12-31 20:04:05 +01:00
|
|
|
save_config_expire(Timestamp::in(reload_in));
|
|
|
|
reload_in -= Random::fast(0, reload_in / 5);
|
|
|
|
if (!is_from_main_dc) {
|
|
|
|
reload_in = 0;
|
|
|
|
}
|
2019-02-10 01:45:15 +01:00
|
|
|
expire_time_ = Timestamp::in(reload_in);
|
|
|
|
set_timeout_at(expire_time_.at());
|
2018-12-31 20:04:05 +01:00
|
|
|
LOG_IF(ERROR, config->test_mode_ != G()->is_test_dc()) << "Wrong parameter is_test";
|
|
|
|
|
|
|
|
ConfigShared &shared_config = G()->shared_config();
|
|
|
|
|
|
|
|
// Do not save dc_options in config, because it will be interpreted and saved by ConnectionCreator.
|
|
|
|
send_closure(G()->connection_creator(), &ConnectionCreator::on_dc_options, DcOptions(config->dc_options_));
|
|
|
|
|
2018-03-08 14:49:45 +01:00
|
|
|
shared_config.set_option_integer("recent_stickers_limit", config->stickers_recent_limit_);
|
2018-12-31 20:04:05 +01:00
|
|
|
shared_config.set_option_integer("favorite_stickers_limit", config->stickers_faved_limit_);
|
|
|
|
shared_config.set_option_integer("saved_animations_limit", config->saved_gifs_limit_);
|
|
|
|
shared_config.set_option_integer("channels_read_media_period", config->channels_read_media_period_);
|
|
|
|
|
|
|
|
shared_config.set_option_boolean("test_mode", config->test_mode_);
|
|
|
|
shared_config.set_option_integer("forwarded_message_count_max", config->forwarded_count_max_);
|
|
|
|
shared_config.set_option_integer("basic_group_size_max", config->chat_size_max_);
|
|
|
|
shared_config.set_option_integer("supergroup_size_max", config->megagroup_size_max_);
|
|
|
|
shared_config.set_option_integer("pinned_chat_count_max", config->pinned_dialogs_count_max_);
|
2019-08-22 17:24:02 +02:00
|
|
|
shared_config.set_option_integer("pinned_archived_chat_count_max", config->pinned_infolder_count_max_);
|
2018-05-03 12:18:07 +02:00
|
|
|
if (is_from_main_dc || !shared_config.have_option("expect_blocking")) {
|
2018-05-03 14:36:05 +02:00
|
|
|
shared_config.set_option_boolean("expect_blocking",
|
2018-05-03 12:18:07 +02:00
|
|
|
(config->flags_ & telegram_api::config::BLOCKED_MODE_MASK) != 0);
|
|
|
|
}
|
2018-06-26 22:46:15 +02:00
|
|
|
if (is_from_main_dc || !shared_config.have_option("dc_txt_domain_name")) {
|
|
|
|
shared_config.set_option_string("dc_txt_domain_name", config->dc_txt_domain_name_);
|
|
|
|
}
|
2018-03-08 16:01:45 +01:00
|
|
|
if (is_from_main_dc || !shared_config.have_option("t_me_url")) {
|
2018-05-17 20:08:51 +02:00
|
|
|
auto url = config->me_url_prefix_;
|
|
|
|
if (!url.empty()) {
|
|
|
|
if (url.back() != '/') {
|
|
|
|
url.push_back('/');
|
|
|
|
}
|
|
|
|
shared_config.set_option_string("t_me_url", url);
|
|
|
|
}
|
2018-03-08 16:01:45 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
if (is_from_main_dc) {
|
2018-06-26 22:46:15 +02:00
|
|
|
shared_config.set_option_integer("webfile_dc_id", config->webfile_dc_id_);
|
2018-12-31 20:04:05 +01:00
|
|
|
if ((config->flags_ & telegram_api::config::TMP_SESSIONS_MASK) != 0) {
|
2018-09-04 03:29:26 +02:00
|
|
|
shared_config.set_option_integer("session_count", config->tmp_sessions_);
|
2018-12-31 20:04:05 +01:00
|
|
|
} else {
|
2018-09-04 03:29:26 +02:00
|
|
|
shared_config.set_option_empty("session_count");
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
2018-07-03 00:52:43 +02:00
|
|
|
if ((config->flags_ & telegram_api::config::SUGGESTED_LANG_CODE_MASK) != 0) {
|
2018-09-04 03:29:26 +02:00
|
|
|
shared_config.set_option_string("suggested_language_pack_id", config->suggested_lang_code_);
|
|
|
|
shared_config.set_option_integer("language_pack_version", config->lang_pack_version_);
|
2019-02-11 01:45:09 +01:00
|
|
|
shared_config.set_option_integer("base_language_pack_version", config->base_lang_pack_version_);
|
2018-07-03 00:52:43 +02:00
|
|
|
} else {
|
2018-09-04 03:29:26 +02:00
|
|
|
shared_config.set_option_empty("suggested_language_pack_id");
|
|
|
|
shared_config.set_option_empty("language_pack_version");
|
2019-02-11 01:45:09 +01:00
|
|
|
shared_config.set_option_empty("base_language_pack_version");
|
2018-07-03 00:52:43 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2018-03-08 16:01:45 +01:00
|
|
|
if (is_from_main_dc) {
|
|
|
|
shared_config.set_option_integer("edit_time_limit", config->edit_time_limit_);
|
|
|
|
shared_config.set_option_boolean("revoke_pm_inbox",
|
|
|
|
(config->flags_ & telegram_api::config::REVOKE_PM_INBOX_MASK) != 0);
|
|
|
|
shared_config.set_option_integer("revoke_time_limit", config->revoke_time_limit_);
|
|
|
|
shared_config.set_option_integer("revoke_pm_time_limit", config->revoke_pm_time_limit_);
|
2018-03-04 21:50:38 +01:00
|
|
|
|
2018-03-08 16:01:45 +01:00
|
|
|
shared_config.set_option_integer("rating_e_decay", config->rating_e_decay_);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
shared_config.set_option_boolean("calls_enabled", config->phonecalls_enabled_);
|
|
|
|
}
|
|
|
|
shared_config.set_option_integer("call_ring_timeout_ms", config->call_ring_timeout_ms_);
|
|
|
|
shared_config.set_option_integer("call_connect_timeout_ms", config->call_connect_timeout_ms_);
|
|
|
|
shared_config.set_option_integer("call_packet_timeout_ms", config->call_packet_timeout_ms_);
|
|
|
|
shared_config.set_option_integer("call_receive_timeout_ms", config->call_receive_timeout_ms_);
|
|
|
|
|
2018-06-27 01:28:49 +02:00
|
|
|
shared_config.set_option_integer("message_text_length_max", config->message_length_max_);
|
|
|
|
shared_config.set_option_integer("message_caption_length_max", config->caption_length_max_);
|
|
|
|
|
2018-06-27 01:35:32 +02:00
|
|
|
if (config->gif_search_username_.empty()) {
|
|
|
|
shared_config.set_option_empty("animation_search_bot_username");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("animation_search_bot_username", config->gif_search_username_);
|
|
|
|
}
|
|
|
|
if (config->venue_search_username_.empty()) {
|
|
|
|
shared_config.set_option_empty("venue_search_bot_username");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("venue_search_bot_username", config->venue_search_username_);
|
|
|
|
}
|
|
|
|
if (config->img_search_username_.empty()) {
|
|
|
|
shared_config.set_option_empty("photo_search_bot_username");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("photo_search_bot_username", config->img_search_username_);
|
|
|
|
}
|
|
|
|
|
2019-09-28 04:14:21 +02:00
|
|
|
auto fix_timeout_ms = [](int32 timeout_ms) {
|
|
|
|
return clamp(timeout_ms, 1000, 86400 * 1000);
|
|
|
|
};
|
2018-11-15 23:03:04 +01:00
|
|
|
|
|
|
|
shared_config.set_option_integer("online_update_period_ms", fix_timeout_ms(config->online_update_period_ms_));
|
|
|
|
|
|
|
|
shared_config.set_option_integer("online_cloud_timeout_ms", fix_timeout_ms(config->online_cloud_timeout_ms_));
|
|
|
|
shared_config.set_option_integer("notification_cloud_delay_ms", fix_timeout_ms(config->notify_cloud_delay_ms_));
|
|
|
|
shared_config.set_option_integer("notification_default_delay_ms", fix_timeout_ms(config->notify_default_delay_ms_));
|
2018-11-08 14:06:17 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// delete outdated options
|
2018-09-04 03:29:26 +02:00
|
|
|
shared_config.set_option_empty("suggested_language_code");
|
2018-12-31 20:04:05 +01:00
|
|
|
shared_config.set_option_empty("chat_big_size");
|
|
|
|
shared_config.set_option_empty("group_size_max");
|
|
|
|
shared_config.set_option_empty("saved_gifs_limit");
|
|
|
|
shared_config.set_option_empty("sessions_count");
|
|
|
|
shared_config.set_option_empty("forwarded_messages_count_max");
|
|
|
|
shared_config.set_option_empty("broadcast_size_max");
|
|
|
|
shared_config.set_option_empty("group_chat_size_max");
|
|
|
|
shared_config.set_option_empty("chat_size_max");
|
|
|
|
shared_config.set_option_empty("megagroup_size_max");
|
|
|
|
shared_config.set_option_empty("offline_blur_timeout_ms");
|
|
|
|
shared_config.set_option_empty("offline_idle_timeout_ms");
|
|
|
|
shared_config.set_option_empty("notify_cloud_delay_ms");
|
|
|
|
shared_config.set_option_empty("notify_default_delay_ms");
|
2018-03-05 16:34:33 +01:00
|
|
|
shared_config.set_option_empty("large_chat_size");
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
// TODO implement online status updates
|
|
|
|
// shared_config.set_option_integer("offline_blur_timeout_ms", config->offline_blur_timeout_ms_);
|
|
|
|
// shared_config.set_option_integer("offline_idle_timeout_ms", config->offline_idle_timeout_ms_);
|
2018-11-08 14:06:17 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
// shared_config.set_option_integer("push_chat_period_ms", config->push_chat_period_ms_);
|
|
|
|
// shared_config.set_option_integer("push_chat_limit", config->push_chat_limit_);
|
2019-12-19 02:58:03 +01:00
|
|
|
|
|
|
|
if (is_from_main_dc) {
|
|
|
|
get_app_config(Auto());
|
2019-12-19 21:00:28 +01:00
|
|
|
if (!shared_config.have_option("can_ignore_sensitive_content_restrictions") ||
|
|
|
|
!shared_config.have_option("ignore_sensitive_content_restrictions")) {
|
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2020-07-10 19:28:30 +02:00
|
|
|
if (!shared_config.have_option("archive_and_mute_new_chats_from_unknown_users")) {
|
|
|
|
get_global_privacy_settings(Auto());
|
|
|
|
}
|
2019-12-19 02:58:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &config) {
|
|
|
|
CHECK(config != nullptr);
|
|
|
|
LOG(INFO) << "Receive app config " << to_string(config);
|
|
|
|
|
2020-07-11 22:50:21 +02:00
|
|
|
const bool archive_and_mute =
|
|
|
|
G()->shared_config().get_option_boolean("archive_and_mute_new_chats_from_unknown_users");
|
|
|
|
|
2021-06-03 22:19:35 +02:00
|
|
|
string autologin_token;
|
|
|
|
vector<string> autologin_domains;
|
|
|
|
vector<string> url_auth_domains;
|
2021-03-15 23:29:54 +01:00
|
|
|
|
2019-12-19 17:18:42 +01:00
|
|
|
vector<tl_object_ptr<telegram_api::jsonObjectValue>> new_values;
|
2019-12-19 17:58:33 +01:00
|
|
|
string ignored_restriction_reasons;
|
2020-04-21 14:45:33 +02:00
|
|
|
vector<string> dice_emojis;
|
2020-04-21 18:08:01 +02:00
|
|
|
std::unordered_map<string, size_t> dice_emoji_index;
|
|
|
|
std::unordered_map<string, string> dice_emoji_success_value;
|
2020-05-30 01:42:45 +02:00
|
|
|
string animation_search_provider;
|
|
|
|
string animation_search_emojis;
|
2020-07-11 22:50:21 +02:00
|
|
|
vector<SuggestedAction> suggested_actions;
|
2020-11-28 14:39:56 +01:00
|
|
|
bool can_archive_and_mute_new_chats_from_unknown_users = false;
|
2019-12-19 02:58:03 +01:00
|
|
|
if (config->get_id() == telegram_api::jsonObject::ID) {
|
2019-12-19 17:18:42 +01:00
|
|
|
for (auto &key_value : static_cast<telegram_api::jsonObject *>(config.get())->value_) {
|
|
|
|
Slice key = key_value->key_;
|
|
|
|
telegram_api::JSONValue *value = key_value->value_.get();
|
2021-08-08 10:14:26 +02:00
|
|
|
if (key == "test" || key == "wallet_enabled" || key == "wallet_blockchain_name" || key == "wallet_config" ||
|
|
|
|
key == "stickers_emoji_cache_time") {
|
2019-12-19 02:58:03 +01:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
if (key == "ignore_restriction_reasons") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto reasons = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &reason : reasons) {
|
2021-09-03 17:14:15 +02:00
|
|
|
auto reason_name = get_json_value_string(std::move(reason), "ignore_restriction_reasons");
|
|
|
|
if (!reason_name.empty() && reason_name.find(',') == string::npos) {
|
|
|
|
if (!ignored_restriction_reasons.empty()) {
|
|
|
|
ignored_restriction_reasons += ',';
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
2021-09-03 17:14:15 +02:00
|
|
|
ignored_restriction_reasons += reason_name;
|
2019-12-19 17:58:33 +01:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unexpected restriction reason " << reason_name;
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected ignore_restriction_reasons " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-19 10:17:51 +02:00
|
|
|
if (key == "emojies_send_dice") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &emoji : emojis) {
|
2021-09-03 17:14:15 +02:00
|
|
|
auto emoji_text = get_json_value_string(std::move(emoji), "emojies_send_dice");
|
|
|
|
if (!emoji_text.empty()) {
|
|
|
|
dice_emoji_index[emoji_text] = dice_emojis.size();
|
|
|
|
dice_emojis.push_back(emoji_text);
|
2020-04-19 10:17:51 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive empty dice emoji";
|
2020-04-19 10:17:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emojies_send_dice " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-04-21 13:51:46 +02:00
|
|
|
if (key == "emojies_send_dice_success") {
|
2020-04-21 18:08:01 +02:00
|
|
|
if (value->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
auto success_values = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
2020-04-21 13:51:46 +02:00
|
|
|
for (auto &success_value : success_values) {
|
|
|
|
CHECK(success_value != nullptr);
|
2020-04-21 18:08:01 +02:00
|
|
|
if (success_value->value_->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
int32 dice_value = -1;
|
|
|
|
int32 frame_start = -1;
|
|
|
|
for (auto &dice_key_value :
|
|
|
|
static_cast<telegram_api::jsonObject *>(success_value->value_.get())->value_) {
|
|
|
|
if (dice_key_value->value_->get_id() != telegram_api::jsonNumber::ID) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-03 16:54:04 +02:00
|
|
|
auto current_value = get_json_value_int(std::move(dice_key_value->value_), Slice());
|
2020-04-21 18:08:01 +02:00
|
|
|
if (dice_key_value->key_ == "value") {
|
|
|
|
dice_value = current_value;
|
|
|
|
}
|
|
|
|
if (dice_key_value->key_ == "frame_start") {
|
|
|
|
frame_start = current_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dice_value < 0 || frame_start < 0) {
|
|
|
|
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
|
|
|
} else {
|
|
|
|
dice_emoji_success_value[success_value->key_] = PSTRING() << dice_value << ':' << frame_start;
|
2020-04-21 13:51:46 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected dice success value " << to_string(success_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected emojies_send_dice_success " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-05-30 01:42:45 +02:00
|
|
|
if (key == "gif_search_branding") {
|
2021-09-03 17:14:15 +02:00
|
|
|
animation_search_provider = get_json_value_string(std::move(key_value->value_), "gif_search_branding");
|
2020-05-30 01:42:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "gif_search_emojies") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto emojis = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &emoji : emojis) {
|
2021-09-03 17:14:15 +02:00
|
|
|
auto emoji_str = get_json_value_string(std::move(emoji), "gif_search_emojies");
|
|
|
|
if (!emoji_str.empty() && emoji_str.find(',') == string::npos) {
|
|
|
|
if (!animation_search_emojis.empty()) {
|
|
|
|
animation_search_emojis += ',';
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
2021-09-03 17:14:15 +02:00
|
|
|
animation_search_emojis += emoji_str;
|
2020-05-30 01:42:45 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unexpected animation search emoji " << emoji_str;
|
2020-05-30 01:42:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected gif_search_emojies " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-11 22:50:21 +02:00
|
|
|
if (key == "pending_suggestions") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto actions = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &action : actions) {
|
2021-09-03 17:14:15 +02:00
|
|
|
auto action_str = get_json_value_string(std::move(action), "pending_suggestions");
|
|
|
|
SuggestedAction suggested_action(action_str);
|
|
|
|
if (!suggested_action.is_empty()) {
|
|
|
|
if (archive_and_mute &&
|
|
|
|
suggested_action == SuggestedAction{SuggestedAction::Type::EnableArchiveAndMuteNewChats}) {
|
|
|
|
LOG(INFO) << "Skip EnableArchiveAndMuteNewChats suggested action";
|
2020-07-11 22:50:21 +02:00
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
suggested_actions.push_back(suggested_action);
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-09-03 17:14:15 +02:00
|
|
|
LOG(ERROR) << "Receive unsupported suggested action " << action_str;
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected pending_suggestions " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-11-28 14:39:56 +01:00
|
|
|
if (key == "autoarchive_setting_available") {
|
2021-09-03 17:17:11 +02:00
|
|
|
can_archive_and_mute_new_chats_from_unknown_users =
|
|
|
|
get_json_value_bool(std::move(key_value->value_), "autoarchive_setting_available");
|
2020-11-28 14:39:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
2021-02-04 12:36:11 +01:00
|
|
|
if (key == "autologin_token") {
|
2021-09-03 17:14:15 +02:00
|
|
|
autologin_token = get_json_value_string(std::move(key_value->value_), "autologin_token");
|
2021-02-04 12:36:11 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (key == "autologin_domains") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &domain : domains) {
|
2021-09-03 17:14:15 +02:00
|
|
|
autologin_domains.push_back(get_json_value_string(std::move(domain), "autologin_domains"));
|
2021-02-04 12:36:11 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected autologin_domains " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-03-15 23:29:54 +01:00
|
|
|
if (key == "url_auth_domains") {
|
|
|
|
if (value->get_id() == telegram_api::jsonArray::ID) {
|
|
|
|
auto domains = std::move(static_cast<telegram_api::jsonArray *>(value)->value_);
|
|
|
|
for (auto &domain : domains) {
|
2021-09-03 17:14:15 +02:00
|
|
|
autologin_domains.push_back(get_json_value_string(std::move(domain), "url_auth_domains"));
|
2021-03-15 23:29:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected url_auth_domains " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2021-07-28 05:15:57 +02:00
|
|
|
if (key == "round_video_encoding") {
|
|
|
|
if (value->get_id() == telegram_api::jsonObject::ID) {
|
|
|
|
auto video_note_settings = std::move(static_cast<telegram_api::jsonObject *>(value)->value_);
|
|
|
|
for (auto &video_note_setting : video_note_settings) {
|
|
|
|
CHECK(video_note_setting != nullptr);
|
|
|
|
if (video_note_setting->key_ != "diameter" && video_note_setting->key_ != "video_bitrate" &&
|
2021-07-29 22:39:07 +02:00
|
|
|
video_note_setting->key_ != "audio_bitrate" && video_note_setting->key_ != "max_size") {
|
2021-07-28 05:15:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (video_note_setting->value_->get_id() == telegram_api::jsonNumber::ID) {
|
2021-09-03 16:54:04 +02:00
|
|
|
auto setting_value = get_json_value_int(std::move(video_note_setting->value_), Slice());
|
2021-07-29 12:02:38 +02:00
|
|
|
if (setting_value > 0) {
|
2021-07-28 05:15:57 +02:00
|
|
|
if (video_note_setting->key_ == "diameter") {
|
|
|
|
G()->shared_config().set_option_integer("suggested_video_note_length", setting_value);
|
|
|
|
}
|
|
|
|
if (video_note_setting->key_ == "video_bitrate") {
|
|
|
|
G()->shared_config().set_option_integer("suggested_video_note_video_bitrate", setting_value);
|
|
|
|
}
|
|
|
|
if (video_note_setting->key_ == "audio_bitrate") {
|
|
|
|
G()->shared_config().set_option_integer("suggested_video_note_audio_bitrate", setting_value);
|
|
|
|
}
|
2021-07-29 22:39:07 +02:00
|
|
|
if (video_note_setting->key_ == "max_size") {
|
|
|
|
G()->shared_config().set_option_integer("video_note_size_max", setting_value);
|
|
|
|
}
|
2021-07-28 05:15:57 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected video note setting " << to_string(video_note_setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive unexpected round_video_encoding " << to_string(*value);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-19 02:58:03 +01:00
|
|
|
|
2019-12-19 17:18:42 +01:00
|
|
|
new_values.push_back(std::move(key_value));
|
2019-12-19 02:58:03 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Receive wrong app config " << to_string(config);
|
|
|
|
}
|
2019-12-19 17:18:42 +01:00
|
|
|
config = make_tl_object<telegram_api::jsonObject>(std::move(new_values));
|
|
|
|
|
2021-06-03 22:19:35 +02:00
|
|
|
send_closure(G()->link_manager(), &LinkManager::update_autologin_domains, std::move(autologin_token),
|
|
|
|
std::move(autologin_domains), std::move(url_auth_domains));
|
2021-02-04 23:40:53 +01:00
|
|
|
|
2019-12-19 17:18:42 +01:00
|
|
|
ConfigShared &shared_config = G()->shared_config();
|
2019-12-20 14:11:58 +01:00
|
|
|
|
2019-12-19 17:58:33 +01:00
|
|
|
if (ignored_restriction_reasons.empty()) {
|
|
|
|
shared_config.set_option_empty("ignored_restriction_reasons");
|
2019-12-19 21:00:28 +01:00
|
|
|
|
|
|
|
if (shared_config.get_option_boolean("ignore_sensitive_content_restrictions", true)) {
|
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("ignored_restriction_reasons", ignored_restriction_reasons);
|
2019-12-19 21:00:28 +01:00
|
|
|
|
|
|
|
if (!shared_config.get_option_boolean("can_ignore_sensitive_content_restrictions")) {
|
|
|
|
get_content_settings(Auto());
|
|
|
|
}
|
2019-12-19 17:58:33 +01:00
|
|
|
}
|
2020-04-19 10:17:51 +02:00
|
|
|
|
|
|
|
if (!dice_emojis.empty()) {
|
2020-04-21 18:08:01 +02:00
|
|
|
vector<string> dice_success_values(dice_emojis.size());
|
|
|
|
for (auto &it : dice_emoji_success_value) {
|
|
|
|
if (dice_emoji_index.find(it.first) == dice_emoji_index.end()) {
|
|
|
|
LOG(ERROR) << "Can't find emoji " << it.first;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dice_success_values[dice_emoji_index[it.first]] = it.second;
|
|
|
|
}
|
|
|
|
shared_config.set_option_string("dice_success_values", implode(dice_success_values, ','));
|
2020-05-22 19:59:00 +02:00
|
|
|
shared_config.set_option_string("dice_emojis", implode(dice_emojis, '\x01'));
|
2020-04-21 13:51:46 +02:00
|
|
|
}
|
2020-05-30 01:42:45 +02:00
|
|
|
|
|
|
|
if (animation_search_provider.empty()) {
|
|
|
|
shared_config.set_option_empty("animation_search_provider");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("animation_search_provider", animation_search_provider);
|
|
|
|
}
|
|
|
|
if (animation_search_emojis.empty()) {
|
|
|
|
shared_config.set_option_empty("animation_search_emojis");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_string("animation_search_emojis", animation_search_emojis);
|
|
|
|
}
|
2020-11-28 14:39:56 +01:00
|
|
|
if (!can_archive_and_mute_new_chats_from_unknown_users) {
|
|
|
|
shared_config.set_option_empty("can_archive_and_mute_new_chats_from_unknown_users");
|
|
|
|
} else {
|
|
|
|
shared_config.set_option_boolean("can_archive_and_mute_new_chats_from_unknown_users",
|
|
|
|
can_archive_and_mute_new_chats_from_unknown_users);
|
|
|
|
}
|
2020-06-08 01:12:57 +02:00
|
|
|
|
|
|
|
shared_config.set_option_empty("default_ton_blockchain_config");
|
|
|
|
shared_config.set_option_empty("default_ton_blockchain_name");
|
2020-07-11 22:50:21 +02:00
|
|
|
|
2020-07-12 14:04:49 +02:00
|
|
|
// do not update suggested actions while changing content settings or dismissing an action
|
|
|
|
if (!is_set_content_settings_request_sent_ && dismiss_suggested_action_request_count_ == 0) {
|
2021-02-22 16:25:49 +01:00
|
|
|
update_suggested_actions(suggested_actions_, std::move(suggested_actions));
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
|
|
|
|
if (!suggested_actions_.empty()) {
|
2021-02-20 22:21:14 +01:00
|
|
|
updates.push_back(get_update_suggested_actions_object(suggested_actions_, {}));
|
2020-07-11 22:50:21 +02:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|