Add new get_simple_config URL.

GitOrigin-RevId: 911173a3eb4756590745adafb9e10fdbe741f105
This commit is contained in:
levlam 2018-03-12 21:04:03 +03:00
parent 1d7a59023a
commit 8b2df8c233
3 changed files with 36 additions and 12 deletions

View File

@ -105,8 +105,8 @@ Result<SimpleConfig> decode_config(Slice input) {
return std::move(config);
}
ActorOwn<> get_simple_config_google_app(Promise<SimpleConfig> promise, bool is_test, int32 scheduler_id) {
VLOG(config_recoverer) << "Request simple config from Google App";
static ActorOwn<> get_simple_config_impl(Promise<SimpleConfig> promise, int32 scheduler_id, string url, string host) {
VLOG(config_recoverer) << "Request simple config from " << url;
#if TD_EMSCRIPTEN // FIXME
return ActorOwn<>();
#else
@ -118,12 +118,21 @@ ActorOwn<> get_simple_config_google_app(Promise<SimpleConfig> promise, bool is_t
return decode_config(http_query->content_);
}());
}),
PSTRING() << "https://www.google.com/" << (is_test ? "test/" : ""),
std::vector<std::pair<string, string>>({{"Host", "dns-telegram.appspot.com"}}), 10 /*timeout*/, 3 /*ttl*/,
std::move(url), std::vector<std::pair<string, string>>({{"Host", std::move(host)}}), 10 /*timeout*/, 3 /*ttl*/,
SslFd::VerifyPeer::Off));
#endif
}
ActorOwn<> get_simple_config_azure(Promise<SimpleConfig> promise, bool is_test, int32 scheduler_id) {
string url = PSTRING() << "https://software-download.microsoft.com/" << (is_test ? "test" : "prod") << "/config.txt";
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "tcdnb.azureedge.net");
}
ActorOwn<> get_simple_config_google_app(Promise<SimpleConfig> promise, bool is_test, int32 scheduler_id) {
string url = PSTRING() << "https://www.google.com/" << (is_test ? "test/" : "");
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "dns-telegram.appspot.com");
}
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfig> promise, bool is_test, int32 scheduler_id) {
VLOG(config_recoverer) << "Request simple config from Google DNS";
#if TD_EMSCRIPTEN // FIXME
@ -468,13 +477,18 @@ class ConfigRecoverer : public Actor {
auto promise = PromiseCreator::lambda([actor_id = actor_shared(this)](Result<SimpleConfig> r_simple_config) {
send_closure(actor_id, &ConfigRecoverer::on_simple_config, std::move(r_simple_config), false);
});
if (simple_config_turn_ % 2 == 0) {
simple_config_query_ =
get_simple_config_google_app(std::move(promise), G()->is_test_dc(), G()->get_gc_scheduler_id());
} else {
simple_config_query_ =
get_simple_config_google_dns(std::move(promise), G()->is_test_dc(), G()->get_gc_scheduler_id());
}
auto get_dimple_config = [&]() {
switch (simple_config_turn_ % 3) {
case 0:
return get_simple_config_azure;
case 1:
return get_simple_config_google_app;
case 2:
default:
return get_simple_config_google_dns;
}
}();
simple_config_query_ = get_dimple_config(std::move(promise), G()->is_test_dc(), G()->get_gc_scheduler_id());
simple_config_turn_++;
}

View File

@ -24,6 +24,8 @@ using SimpleConfig = tl_object_ptr<telegram_api::help_configSimple>;
Result<SimpleConfig> decode_config(Slice input);
ActorOwn<> get_simple_config_azure(Promise<SimpleConfig> promise, bool is_test = false, int32 scheduler_id = -1);
ActorOwn<> get_simple_config_google_app(Promise<SimpleConfig> promise, bool is_test = false, int32 scheduler_id = -1);
ActorOwn<> get_simple_config_google_dns(Promise<SimpleConfig> promise, bool is_test = false, int32 scheduler_id = -1);

View File

@ -37,9 +37,17 @@ TEST(Mtproto, config) {
int threads_n = 0;
sched.init(threads_n);
int cnt = 2;
int cnt = 3;
{
auto guard = sched.get_current_guard();
get_simple_config_azure(PromiseCreator::lambda([&](Result<SimpleConfig> r_simple_config) {
LOG(ERROR) << to_string(r_simple_config.ok());
if (--cnt == 0) {
Scheduler::instance()->finish();
}
}))
.release();
get_simple_config_google_app(PromiseCreator::lambda([&](Result<SimpleConfig> r_simple_config) {
LOG(ERROR) << to_string(r_simple_config.ok());
if (--cnt == 0) {