Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: net/nqe/network_quality_estimator_util.cc

Issue 2936823002: NQE: Exclude network observations from private networks (Closed)
Patch Set: ps Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/nqe/network_quality_estimator_util.h"
6
7 #include "net/base/address_list.h"
8 #include "net/base/host_port_pair.h"
9 #include "net/base/ip_address.h"
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/net_errors.h"
12 #include "net/base/url_util.h"
13 #include "net/dns/host_resolver.h"
14
15 namespace net {
16
17 namespace nqe {
18
19 namespace internal {
20
21 bool IsPrivateHost(HostResolver* host_resolver,
bengr 2017/06/13 20:35:36 Maybe this should be in url_util?
tbansal1 2017/06/13 22:36:09 +mmenke: Do you think it will be useful to include
tbansal1 2017/06/14 17:27:04 I am in favor of keeping it in //net/nqe, and late
tbansal1 2017/06/16 00:57:42 Acknowledged.
22 const HostPortPair& host_port_pair,
23 const NetLogWithSource& net_log) {
24 if (IsLocalhost(host_port_pair.host()))
25 return true;
26
27 // Check if |host_port_pair.host()| is a reserved IP address.
28 net::IPAddress ip_address;
29 if (ip_address.AssignFromIPLiteral(host_port_pair.host()) &&
30 ip_address.IsReserved()) {
mmenke 2017/06/14 18:23:31 Is this right? RFC 1918 predates IPv6 reserved ad
tbansal1 2017/06/16 00:57:42 I added some more comments in the network_quality_
31 return true;
32 }
33
34 if (host_resolver) {
35 // Try resolving |host_port_pair.host()| synchronously.
36 HostResolver::RequestInfo resolve_info(host_port_pair);
37 resolve_info.set_allow_cached_response(true);
38 AddressList addresses;
39 // Resolve synchronously using the resolver's cache.
40 int rv = host_resolver->ResolveFromCache(resolve_info, &addresses, net_log);
bengr 2017/06/13 20:35:36 What happens if it isn't cached? How often does th
tbansal1 2017/06/16 00:57:42 Depends on when it is queried. Currently, for RTT,
41
42 DCHECK_NE(rv, ERR_IO_PENDING);
43 if (rv == OK && !addresses.empty()) {
44 // Checking only the first address should be sufficient.
45 IPEndPoint ip_end_point = addresses.front();
46 ip_address = ip_end_point.address();
47 if (ip_address.IsReserved()) {
48 return true;
49 }
50 }
51 }
52 return false;
53 }
54
55 } // namespace internal
56
57 } // namespace nqe
58
59 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698