1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_NET_NETWORK_DIAGNOSTICS_NETWORK_DIAGNOSTICS_UTIL_H_
#define CHROME_BROWSER_ASH_NET_NETWORK_DIAGNOSTICS_NETWORK_DIAGNOSTICS_UTIL_H_
#include <array>
#include <cstdint>
#include <string>
#include <vector>
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "url/gurl.h"
class Profile;
namespace ash {
namespace network_diagnostics {
namespace util {
// DNS queries taking longer than 400 ms are potentially problematic.
inline constexpr int kDnsPotentialProblemLatencyMs = 400;
// DNS queries taking longer than 500 ms are problematic.
inline constexpr int kDnsProblemLatencyMs = 500;
// Generate 204 path.
extern const char kGenerate204Path[];
// STUN packet header size.
inline constexpr int kStunHeaderSize = 20;
// Returns the Gstatic host suffix. Network diagnostic routines attach a random
// prefix to |kGstaticHostSuffix| to get a complete hostname.
const char* GetGstaticHostSuffix();
// Returns the list representing a fixed set of hostnames used by routines.
const std::vector<std::string>& GetFixedHosts();
// Returns a string of length |length|. Contains characters 'a'-'z', inclusive.
std::string GetRandomString(int length);
// Returns |num_hosts| random hosts, each suffixed with |kGstaticHostSuffix| and
// prefixed with a random string of length |prefix_length|.
std::vector<std::string> GetRandomHosts(int num_hosts, int prefix_length);
// Similar to GetRandomHosts(), but the fixed hosts are prepended to the list.
// The total number of hosts in this list is GetFixedHosts().size() +
// num_random_hosts.
std::vector<std::string> GetRandomHostsWithFixedHosts(int num_random_hosts,
int prefix_length);
// Similar to GetRandomHosts, but with a |scheme| prepended to the hosts.
std::vector<std::string> GetRandomHostsWithScheme(int num_hosts,
int prefix_length,
std::string scheme);
// Similar to GetRandomHostsWithFixedHosts, but with a |scheme| prepended to the
// hosts.
std::vector<std::string> GetRandomAndFixedHostsWithScheme(int num_random_hosts,
int prefix_length,
std::string scheme);
// Similar to GetRandomAndFixedHostsWithSchemeAndPort, but with |port|, followed
// by "/", appended to the hosts. E.g. A host will look like:
// "https://www.google.com:443/".
std::vector<std::string> GetRandomAndFixedHostsWithSchemeAndPort(
int num_random_hosts,
int prefix_length,
std::string scheme,
int port_number);
// Similar to GetRandomHostsWithScheme, but with the 204 path appended to hosts.
std::vector<std::string> GetRandomHostsWithSchemeAndGenerate204Path(
int num_hosts,
int prefix_length,
std::string scheme);
// Similar to GetRandomAndFixedHostsWithSchemeAndPort, but with |port_number|
// and 204 path appended to the hosts. E.g. A host will look like:
// "https://www.google.com:443/generate_204/".
std::vector<GURL> GetRandomHostsWithSchemeAndPortAndGenerate204Path(
int num_hosts,
int prefix_length,
std::string scheme,
int port_number);
// Returns the profile associated with this account.
Profile* GetUserProfile();
// Returns a STUN packet with a header defined in RFC 5389.
const std::array<uint8_t, kStunHeaderSize>& GetStunHeader();
// Returns the traffic annotation tag for STUN traffic.
net::NetworkTrafficAnnotationTag GetStunNetworkAnnotationTag();
// Returns the ports used to speak to Google's STUN server over UDP.
std::vector<int> GetUdpPortsForGoogleStunServer();
// Returns the ports used to speak to a custom STUN server over UDP.
std::vector<int> GetUdpPortsForCustomStunServer();
// Returns the ports used to speak to Google's STUN server over TCP.
std::vector<int> GetTcpPortsForGoogleStunServer();
// Returns the ports used to speak to a custom STUN server over TCP.
std::vector<int> GetTcpPortsForCustomStunServer();
// Returns the list of urls related to Google media.
std::vector<GURL> GetDefaultMediaUrls();
} // namespace util
} // namespace network_diagnostics
} // namespace ash
#endif // CHROME_BROWSER_ASH_NET_NETWORK_DIAGNOSTICS_NETWORK_DIAGNOSTICS_UTIL_H_
|