-
Notifications
You must be signed in to change notification settings - Fork 857
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat decentralized DNS servers as available before first probe is co…
…mpleted
- Loading branch information
Showing
7 changed files
with
157 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/net/dns/brave_resolve_context.h" | ||
#include "net/dns/context_host_resolver.h" | ||
|
||
#define ResolveContext BraveResolveContext | ||
#include "../../../../net/dns/host_resolver.cc" | ||
#undef ResolveContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_NET_DNS_RESOLVE_CONTEXT_H_ | ||
#define BRAVE_CHROMIUM_SRC_NET_DNS_RESOLVE_CONTEXT_H_ | ||
|
||
namespace net { | ||
class BraveResolveContext; | ||
} // namespace net | ||
|
||
#define GetDohServerAvailability virtual GetDohServerAvailability | ||
#define NumAvailableDohServers virtual NumAvailableDohServers | ||
#define BRAVE_RESOLVE_CONTEXT_H \ | ||
private: \ | ||
friend class BraveResolveContext; | ||
|
||
#include "../../../../net/dns/resolve_context.h" | ||
#undef GetDohServerAvailability | ||
#undef NumAvailableDohServers | ||
#undef BRAVE_RESOLVE_CONTEXT_H | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_NET_DNS_RESOLVE_CONTEXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/net/dns/brave_resolve_context.h" | ||
|
||
#include <string> | ||
|
||
#include "brave/net/decentralized_dns/constants.h" | ||
#include "net/dns/dns_session.h" | ||
|
||
namespace { | ||
|
||
bool IsDecentralizedDNSResolver(const std::string& server) { | ||
return server == decentralized_dns::kUnstoppableDomainsDoHResolver || | ||
server == decentralized_dns::kENSDoHResolver; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace net { | ||
|
||
BraveResolveContext::BraveResolveContext(URLRequestContext* url_request_context, | ||
bool enable_caching) | ||
: ResolveContext(url_request_context, enable_caching) {} | ||
|
||
BraveResolveContext::~BraveResolveContext() = default; | ||
|
||
bool BraveResolveContext::IsFirstProbeCompleted(const ServerStats& stat) const { | ||
return !(stat.last_failure_count == 0 && | ||
stat.current_connection_success == false); | ||
} | ||
|
||
bool BraveResolveContext::GetDohServerAvailability( | ||
size_t doh_server_index, | ||
const DnsSession* session) const { | ||
// Return decentralized DNS resolvers as available before the first probe is | ||
// completed. It is to avoid falling back to non-secure DNS servers before | ||
// the first probe is completed when users using automatic mode, which will | ||
// lead to an error page with HOSTNAME_NOT_RESOLVED error right after user | ||
// opt-in from the interstitial page. | ||
if (IsDecentralizedDNSResolver(session->config() | ||
.dns_over_https_servers[doh_server_index] | ||
.server_template) && | ||
!IsFirstProbeCompleted(doh_server_stats_[doh_server_index])) | ||
return true; | ||
|
||
return ResolveContext::GetDohServerAvailability(doh_server_index, session); | ||
} | ||
|
||
size_t BraveResolveContext::NumAvailableDohServers( | ||
const DnsSession* session) const { | ||
size_t num = 0; | ||
|
||
// Treat decentralized DNS resolvers as available before the first probe is | ||
// completed. | ||
for (size_t i = 0; i < doh_server_stats_.size(); i++) { | ||
if (IsDecentralizedDNSResolver( | ||
session->config().dns_over_https_servers[i].server_template) && | ||
!IsFirstProbeCompleted(doh_server_stats_[i])) | ||
num++; | ||
} | ||
|
||
return num + ResolveContext::NumAvailableDohServers(session); | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* Copyright (c) 2021 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_NET_DNS_BRAVE_RESOLVE_CONTEXT_H_ | ||
#define BRAVE_NET_DNS_BRAVE_RESOLVE_CONTEXT_H_ | ||
|
||
#include "net/base/net_export.h" | ||
#include "net/dns/resolve_context.h" | ||
|
||
namespace net { | ||
|
||
class DnsSession; | ||
class URLRequestContext; | ||
|
||
class NET_EXPORT_PRIVATE BraveResolveContext : public ResolveContext { | ||
public: | ||
BraveResolveContext(URLRequestContext* url_request_context, | ||
bool enable_caching); | ||
|
||
BraveResolveContext(const BraveResolveContext&) = delete; | ||
BraveResolveContext& operator=(const BraveResolveContext&) = delete; | ||
|
||
~BraveResolveContext() override; | ||
|
||
bool GetDohServerAvailability(size_t doh_server_index, | ||
const DnsSession* session) const override; | ||
size_t NumAvailableDohServers(const DnsSession* session) const override; | ||
|
||
private: | ||
bool IsFirstProbeCompleted(const ServerStats& stat) const; | ||
}; | ||
|
||
} // namespace net | ||
|
||
#endif // BRAVE_NET_DNS_BRAVE_RESOLVE_CONTEXT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/net/dns/resolve_context.h b/net/dns/resolve_context.h | ||
index fc43188340e54dd509aa58f93a84ca6b770e5a6f..81fa236a973ae31f6ac165b14ee0cc7754253f03 100644 | ||
--- a/net/dns/resolve_context.h | ||
+++ b/net/dns/resolve_context.h | ||
@@ -176,6 +176,7 @@ class NET_EXPORT_PRIVATE ResolveContext : public base::CheckedObserver { | ||
// (alternative service info if it supports QUIC, for instance). | ||
const IsolationInfo& isolation_info() const { return isolation_info_; } | ||
|
||
+ BRAVE_RESOLVE_CONTEXT_H | ||
private: | ||
friend DohDnsServerIterator; | ||
friend ClassicDnsServerIterator; |