iroh/net_report/
options.rs1pub(crate) use imp::Options;
4
5#[cfg(not(wasm_browser))]
6mod imp {
7 use std::collections::BTreeSet;
8
9 use url::Url;
10
11 use crate::net_report::{NetReportConfig, QuicConfig, probes::Probe};
12
13 #[derive(Debug, Clone)]
19 pub(crate) struct Options {
20 pub(crate) quic_config: Option<QuicConfig>,
24 pub(crate) tls_config: rustls::ClientConfig,
26 pub(crate) proxy_url: Option<Url>,
30 pub(crate) user_config: NetReportConfig,
32 }
33
34 impl Options {
35 pub(crate) fn new(tls_config: rustls::ClientConfig) -> Self {
36 Self {
37 quic_config: None,
38 tls_config,
39 proxy_url: None,
40 user_config: NetReportConfig::default(),
41 }
42 }
43 pub(crate) fn quic_config(mut self, quic_config: Option<QuicConfig>) -> Self {
45 self.quic_config = quic_config;
46 self
47 }
48
49 pub(crate) fn proxy_url(mut self, proxy_url: Option<Url>) -> Self {
51 self.proxy_url = proxy_url;
52 self
53 }
54
55 pub(crate) fn net_report_config(mut self, config: NetReportConfig) -> Self {
57 self.user_config = config;
58 self
59 }
60
61 pub(crate) fn as_protocols(&self) -> BTreeSet<Probe> {
63 let mut protocols = BTreeSet::new();
64 if let Some(ref quic) = self.quic_config {
65 if quic.ipv4 {
66 protocols.insert(Probe::QadIpv4);
67 }
68 if quic.ipv6 {
69 protocols.insert(Probe::QadIpv6);
70 }
71 }
72 if self.user_config.https_probes {
73 protocols.insert(Probe::Https);
74 }
75 protocols
76 }
77 }
78}
79
80#[cfg(wasm_browser)]
81mod imp {
82 use std::collections::BTreeSet;
83
84 use crate::net_report::{NetReportConfig, Probe};
85
86 #[derive(Debug, Clone)]
91 pub(crate) struct Options {
92 pub(crate) user_config: NetReportConfig,
94 }
95
96 impl Default for Options {
97 fn default() -> Self {
98 Self {
99 user_config: NetReportConfig::default(),
100 }
101 }
102 }
103
104 impl Options {
105 pub(crate) fn net_report_config(mut self, config: NetReportConfig) -> Self {
107 self.user_config = config;
108 self
109 }
110
111 pub(crate) fn as_protocols(&self) -> BTreeSet<Probe> {
113 let mut protocols = BTreeSet::new();
114 if self.user_config.https_probes {
115 protocols.insert(Probe::Https);
116 }
117 protocols
118 }
119 }
120}