File: network_diagnostics_util.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,459 bytes parent folder | download | duplicates (4)
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_