Lazy GetHostByNameActor creation.

GitOrigin-RevId: 423a126e40a77d47cfa8d16889729f3102194724
This commit is contained in:
levlam 2019-02-05 01:32:37 +03:00
parent 0defd8c927
commit d6474dc83d
2 changed files with 21 additions and 12 deletions

View File

@ -457,10 +457,27 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise<string> promise)
promise.set_value(std::move(url));
}
ActorId<GetHostByNameActor> ConnectionCreator::get_resolver() const {
ActorId<GetHostByNameActor> ConnectionCreator::get_dns_resolver() {
if (G()->shared_config().get_option_boolean("expect_blocking", true)) {
if (block_get_host_by_name_actor_.empty()) {
VLOG(connections) << "Init block bypass DNS resolver";
GetHostByNameActor::Options options;
options.scheduler_id = G()->get_gc_scheduler_id();
options.resolver_types = {GetHostByNameActor::ResolverType::Google, GetHostByNameActor::ResolverType::Native};
options.ok_timeout = 60;
options.error_timeout = 0;
block_get_host_by_name_actor_ = create_actor<GetHostByNameActor>("BlockDnsResolverActor", std::move(options));
}
return block_get_host_by_name_actor_.get();
} else {
if (get_host_by_name_actor_.empty()) {
VLOG(connections) << "Init DNS resolver";
GetHostByNameActor::Options options;
options.scheduler_id = G()->get_gc_scheduler_id();
options.ok_timeout = 5 * 60 - 1;
options.error_timeout = 0;
get_host_by_name_actor_ = create_actor<GetHostByNameActor>("DnsResolverActor", std::move(options));
}
return get_host_by_name_actor_.get();
}
}
@ -515,7 +532,7 @@ void ConnectionCreator::ping_proxy(int32 proxy_id, Promise<double> promise) {
}
const Proxy &proxy = it->second;
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6");
send_closure(get_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
send_closure(get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
PromiseCreator::lambda([actor_id = actor_id(this), promise = std::move(promise),
proxy_id](Result<IPAddress> result) mutable {
if (result.is_error()) {
@ -1249,14 +1266,6 @@ void ConnectionCreator::start_up() {
on_proxy_changed(true);
}
GetHostByNameActor::Options options;
options.scheduler_id = G()->get_gc_scheduler_id();
options.ok_timeout = 5 * 60 - 1;
options.error_timeout = 0;
get_host_by_name_actor_ = create_actor<GetHostByNameActor>("GetHostByNameActor", options);
options.resolver_types = {GetHostByNameActor::ResolverType::Google, GetHostByNameActor::ResolverType::Native};
block_get_host_by_name_actor_ = create_actor<GetHostByNameActor>("GetHostByNameActor", options);
ref_cnt_guard_ = create_reference(-1);
is_inited_ = true;
@ -1382,7 +1391,7 @@ void ConnectionCreator::loop() {
bool prefer_ipv6 = G()->shared_config().get_option_boolean("prefer_ipv6");
VLOG(connections) << "Resolve IP address " << resolve_proxy_query_token_ << " of " << proxy.server();
send_closure(
get_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
get_dns_resolver(), &GetHostByNameActor::run, proxy.server().str(), proxy.port(), prefer_ipv6,
PromiseCreator::lambda([actor_id = create_reference(resolve_proxy_query_token_)](Result<IPAddress> result) {
send_closure(std::move(actor_id), &ConnectionCreator::on_proxy_resolved, std::move(result), false);
}));

View File

@ -323,7 +323,7 @@ class ConnectionCreator : public NetQueryCallback {
Result<SocketFd> find_connection(const ProxyInfo &proxy, DcId dc_id, bool allow_media_only,
FindConnectionExtra &extra);
ActorId<GetHostByNameActor> get_resolver() const;
ActorId<GetHostByNameActor> get_dns_resolver();
void ping_proxy_resolved(int32 proxy_id, IPAddress ip_address, Promise<double> promise);