Skip to content

Commit 48d5831

Browse files
committed
Fix all unused warnings
1 parent 471ad93 commit 48d5831

File tree

4 files changed

+121
-96
lines changed

4 files changed

+121
-96
lines changed

iroh-relay/src/client.rs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
//!
33
//! Based on tailscale/derp/derphttp/derphttp_client.go
44
5+
#[cfg(not(wasm_browser))]
6+
use std::{future::Future, net::IpAddr};
57
use std::{
6-
future::Future,
7-
net::{IpAddr, SocketAddr},
8+
net::SocketAddr,
89
pin::Pin,
910
sync::Arc,
1011
task::{self, Poll},
1112
};
1213

13-
use anyhow::{anyhow, bail, Context, Result};
14+
#[cfg(not(wasm_browser))]
15+
use anyhow::Context;
16+
use anyhow::{anyhow, bail, Result};
17+
#[cfg(not(wasm_browser))]
1418
use bytes::Bytes;
1519
use conn::Conn;
20+
#[cfg(not(wasm_browser))]
1621
use data_encoding::BASE64URL;
1722
use futures_lite::Stream;
1823
use futures_util::{
@@ -21,33 +26,41 @@ use futures_util::{
2126
};
2227
#[cfg(not(wasm_browser))]
2328
use hickory_resolver::TokioResolver as DnsResolver;
29+
#[cfg(not(wasm_browser))]
2430
use http_body_util::Empty;
31+
#[cfg(not(wasm_browser))]
2532
use hyper::{
2633
body::Incoming,
2734
header::{HOST, UPGRADE},
2835
upgrade::Parts,
2936
Request,
3037
};
3138
use iroh_base::{RelayUrl, SecretKey};
39+
#[cfg(not(wasm_browser))]
3240
use rustls::client::Resumption;
3341
#[cfg(not(wasm_browser))]
3442
use streams::{downcast_upgrade, MaybeTlsStream, ProxyStream};
43+
#[cfg(not(wasm_browser))]
3544
use tokio::io::{AsyncRead, AsyncWrite};
3645
#[cfg(any(test, feature = "test-utils"))]
3746
use tracing::warn;
38-
use tracing::{debug, error, event, info_span, trace, Instrument, Level};
47+
use tracing::{debug, event, trace, Level};
48+
#[cfg(not(wasm_browser))]
49+
use tracing::{error, info_span, Instrument};
3950
use url::Url;
4051

4152
pub use self::conn::{ConnSendError, ReceivedMessage, SendMessage};
53+
#[cfg(not(wasm_browser))]
54+
use crate::defaults::timeouts::*;
4255
use crate::{
43-
defaults::timeouts::*,
4456
http::{Protocol, RELAY_PATH},
4557
KeyCache,
4658
};
4759

4860
pub(crate) mod conn;
4961
#[cfg(not(wasm_browser))]
5062
pub(crate) mod streams;
63+
#[cfg(not(wasm_browser))]
5164
mod util;
5265

5366
#[cfg(wasm_browser)]
@@ -73,6 +86,7 @@ pub struct ClientBuilder {
7386
/// The secret key of this client.
7487
secret_key: SecretKey,
7588
/// The DNS resolver to use.
89+
#[cfg_attr(wasm_browser, allow(unused))]
7690
dns_resolver: DnsResolver,
7791
/// Cache for public keys of remote nodes.
7892
key_cache: KeyCache,
@@ -152,35 +166,6 @@ impl ClientBuilder {
152166

153167
/// Establishes a new connection to the relay server.
154168
pub async fn connect(&self) -> Result<Client> {
155-
let roots = rustls::RootCertStore {
156-
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
157-
};
158-
let mut config = rustls::client::ClientConfig::builder_with_provider(Arc::new(
159-
rustls::crypto::ring::default_provider(),
160-
))
161-
.with_safe_default_protocol_versions()
162-
.expect("protocols supported by ring")
163-
.with_root_certificates(roots)
164-
.with_no_client_auth();
165-
#[cfg(any(test, feature = "test-utils"))]
166-
if self.insecure_skip_cert_verify {
167-
warn!("Insecure config: SSL certificates from relay servers not verified");
168-
config
169-
.dangerous()
170-
.set_certificate_verifier(Arc::new(NoCertVerifier));
171-
}
172-
config.resumption = Resumption::default();
173-
let tls_connector: tokio_rustls::TlsConnector = Arc::new(config).into();
174-
175-
let (conn, local_addr) = self.connect_0(tls_connector).await?;
176-
177-
Ok(Client { conn, local_addr })
178-
}
179-
180-
async fn connect_0(
181-
&self,
182-
tls_connector: tokio_rustls::TlsConnector,
183-
) -> Result<(Conn, Option<SocketAddr>)> {
184169
let (conn, local_addr) = match self.protocol {
185170
Protocol::Websocket => {
186171
let conn = self.connect_ws().await?;
@@ -189,7 +174,7 @@ impl ClientBuilder {
189174
}
190175
#[cfg(not(wasm_browser))]
191176
Protocol::Relay => {
192-
let (conn, local_addr) = self.connect_relay(tls_connector).await?;
177+
let (conn, local_addr) = self.connect_relay().await?;
193178
(conn, Some(local_addr))
194179
}
195180
#[cfg(wasm_browser)]
@@ -205,8 +190,8 @@ impl ClientBuilder {
205190
protocol = ?self.protocol,
206191
);
207192

208-
trace!("connect_0 done");
209-
Ok((conn, local_addr))
193+
trace!("connect done");
194+
Ok(Client { conn, local_addr })
210195
}
211196

212197
async fn connect_ws(&self) -> Result<Conn> {
@@ -239,10 +224,27 @@ impl ClientBuilder {
239224
// Non-browser code
240225
#[cfg(not(wasm_browser))]
241226
impl ClientBuilder {
242-
async fn connect_relay(
243-
&self,
244-
tls_connector: tokio_rustls::TlsConnector,
245-
) -> Result<(Conn, SocketAddr)> {
227+
async fn connect_relay(&self) -> Result<(Conn, SocketAddr)> {
228+
let roots = rustls::RootCertStore {
229+
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
230+
};
231+
let mut config = rustls::client::ClientConfig::builder_with_provider(Arc::new(
232+
rustls::crypto::ring::default_provider(),
233+
))
234+
.with_safe_default_protocol_versions()
235+
.expect("protocols supported by ring")
236+
.with_root_certificates(roots)
237+
.with_no_client_auth();
238+
#[cfg(any(test, feature = "test-utils"))]
239+
if self.insecure_skip_cert_verify {
240+
warn!("Insecure config: SSL certificates from relay servers not verified");
241+
config
242+
.dangerous()
243+
.set_certificate_verifier(Arc::new(NoCertVerifier));
244+
}
245+
config.resumption = Resumption::default();
246+
let tls_connector: tokio_rustls::TlsConnector = Arc::new(config).into();
247+
246248
let url = self.url.clone();
247249
let tcp_stream = self.dial_url(&tls_connector).await?;
248250

@@ -605,6 +607,7 @@ pub fn make_dangerous_client_config() -> rustls::ClientConfig {
605607
.with_no_client_auth()
606608
}
607609

610+
#[cfg(not(wasm_browser))]
608611
fn host_header_value(relay_url: RelayUrl) -> Result<String> {
609612
// grab the host, turns e.g. https://example.com:8080/xyz -> example.com.
610613
let relay_url_host = relay_url.host_str().context("Invalid URL")?;
@@ -711,6 +714,7 @@ impl rustls::client::danger::ServerCertVerifier for NoCertVerifier {
711714
}
712715
}
713716

717+
#[cfg(not(wasm_browser))]
714718
fn url_port(url: &Url) -> Option<u16> {
715719
if let Some(port) = url.port() {
716720
return Some(port);

iroh-relay/src/client/conn.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ use futures_lite::Stream;
1515
use futures_util::Sink;
1616
use iroh_base::{NodeId, SecretKey};
1717
use tokio_tungstenite_wasm::WebSocketStream;
18+
#[cfg(not(wasm_browser))]
1819
use tokio_util::codec::Framed;
1920
use tracing::debug;
2021

2122
use super::KeyCache;
23+
use crate::protos::relay::{ClientInfo, Frame, MAX_PACKET_SIZE, PROTOCOL_VERSION};
2224
#[cfg(not(wasm_browser))]
23-
use crate::client::streams::MaybeTlsStreamChained;
24-
use crate::protos::relay::{ClientInfo, Frame, RelayCodec, MAX_PACKET_SIZE, PROTOCOL_VERSION};
25+
use crate::{client::streams::MaybeTlsStreamChained, protos::relay::RelayCodec};
2526

2627
/// Error for sending messages to the relay server.
2728
#[derive(Debug, thiserror::Error)]

iroh-relay/src/defaults.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ pub const DEFAULT_KEY_CACHE_CAPACITY: usize = 1024 * 1024;
2929

3030
/// Contains all timeouts that we use in `iroh`.
3131
pub(crate) mod timeouts {
32+
#[cfg(any(not(wasm_browser), feature = "server"))]
3233
use std::time::Duration;
3334

3435
/// Timeout used by the relay client while connecting to the relay server,
3536
/// using `TcpStream::connect`
37+
#[cfg(not(wasm_browser))]
3638
pub(crate) const DIAL_NODE_TIMEOUT: Duration = Duration::from_millis(1500);
3739
/// Timeout for our async dns resolver
40+
#[cfg(not(wasm_browser))]
3841
pub(crate) const DNS_TIMEOUT: Duration = Duration::from_secs(1);
3942

4043
/// Maximum time the server will attempt to get a successful write to the connection.

0 commit comments

Comments
 (0)