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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! Options for creating a report gen client.
pub use imp::Options;
#[cfg(not(wasm_browser))]
mod imp {
use std::collections::BTreeSet;
use crate::net_report::{QuicConfig, probes::Probe};
/// Options for running probes
///
/// By default, will run Https probes.
///
/// Use [`Options::quic_config`] to enable QUIC address discovery.
#[derive(Debug, Clone)]
pub struct Options {
/// The configuration needed to launch QUIC address discovery probes.
///
/// If not provided, will not run QUIC address discovery.
pub(crate) quic_config: Option<QuicConfig>,
/// Enable https probes
///
/// On by default
pub(crate) https: bool,
#[cfg(any(test, feature = "test-utils"))]
pub(crate) insecure_skip_relay_cert_verify: bool,
}
impl Default for Options {
fn default() -> Self {
Self {
quic_config: None,
https: true,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
}
}
}
impl Options {
/// Create an [`Options`] that disables all probes
pub fn disabled() -> Self {
Self {
quic_config: None,
https: false,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
}
}
/// Enable quic probes
pub fn quic_config(mut self, quic_config: Option<QuicConfig>) -> Self {
self.quic_config = quic_config;
self
}
/// Enable or disable https probe
pub fn https(mut self, enable: bool) -> Self {
self.https = enable;
self
}
/// Skip cert verification
#[cfg(any(test, feature = "test-utils"))]
pub fn insecure_skip_relay_cert_verify(mut self, skip: bool) -> Self {
self.insecure_skip_relay_cert_verify = skip;
self
}
/// Turn the options into set of valid protocols
pub fn as_protocols(&self) -> BTreeSet<Probe> {
let mut protocols = BTreeSet::new();
if let Some(ref quic) = self.quic_config {
if quic.ipv4 {
protocols.insert(Probe::QadIpv4);
}
if quic.ipv6 {
protocols.insert(Probe::QadIpv6);
}
}
if self.https {
protocols.insert(Probe::Https);
}
protocols
}
}
}
#[cfg(wasm_browser)]
mod imp {
use std::collections::BTreeSet;
use crate::net_report::Probe;
/// Options for running probes (in browsers).
///
/// Only HTTPS probes are supported in browsers.
/// These are run by default.
#[derive(Debug, Clone)]
pub struct Options {
/// Enable https probes
///
/// On by default
pub(crate) https: bool,
}
impl Default for Options {
fn default() -> Self {
Self { https: true }
}
}
impl Options {
/// Create an [`Options`] that disables all probes
pub fn disabled() -> Self {
Self { https: false }
}
/// Enable or disable https probe
pub fn https(mut self, enable: bool) -> Self {
self.https = enable;
self
}
/// Turn the options into set of valid protocols
pub(crate) fn as_protocols(&self) -> BTreeSet<Probe> {
let mut protocols = BTreeSet::new();
if self.https {
protocols.insert(Probe::Https);
}
protocols
}
}
}