Skip to content

Commit

Permalink
refactor: Remove relay_path and simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jul 1, 2024
1 parent d0de17f commit 9fb48a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
16 changes: 1 addition & 15 deletions iroh-net/src/relay/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ struct Actor {
ping_tasks: JoinSet<()>,
dns_resolver: DnsResolver,
proxy_url: Option<Url>,
relay_path: &'static str,
}

#[derive(Default, Debug)]
Expand Down Expand Up @@ -224,8 +223,6 @@ pub struct ClientBuilder {
insecure_skip_cert_verify: bool,
/// HTTP Proxy
proxy_url: Option<Url>,
/// Default is "/relay"
relay_path: &'static str,
}

impl ClientBuilder {
Expand All @@ -241,7 +238,6 @@ impl ClientBuilder {
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_cert_verify: false,
proxy_url: None,
relay_path: RELAY_HTTP_PATH,
}
}

Expand Down Expand Up @@ -299,15 +295,6 @@ impl ClientBuilder {
self
}

/// Set the relay endpoint path used for making connections.
///
/// Private for now, as it's only used in tests so far.
#[cfg(test)]
pub(crate) fn relay_path(mut self, relay_path: &'static str) -> Self {
self.relay_path = relay_path;
self
}

/// Build the [`Client`]
pub fn build(self, key: SecretKey, dns_resolver: DnsResolver) -> (Client, ClientReceiver) {
// TODO: review TLS config
Expand Down Expand Up @@ -350,7 +337,6 @@ impl ClientBuilder {
tls_connector,
dns_resolver,
proxy_url: self.proxy_url,
relay_path: self.relay_path,
};

let (msg_sender, inbox) = mpsc::channel(64);
Expand Down Expand Up @@ -627,7 +613,7 @@ impl Actor {

async fn connect_ws(&self) -> Result<(ConnReader, ConnWriter), ClientError> {
let mut dial_url = (*self.url).clone();
dial_url.set_path(self.relay_path);
dial_url.set_path(RELAY_HTTP_PATH);

debug!(%dial_url, "Dialing relay by websocket");

Expand Down
22 changes: 12 additions & 10 deletions iroh-net/src/relay/iroh_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,9 +703,10 @@ mod tests {
use std::time::Duration;

use bytes::Bytes;
use http::header::UPGRADE;
use iroh_base::node_addr::RelayUrl;

use crate::relay::http::ClientBuilder;
use crate::relay::http::{ClientBuilder, HTTP_UPGRADE_PROTOCOL};

use self::relay::ReceivedMessage;

Expand Down Expand Up @@ -797,17 +798,18 @@ mod tests {
async fn test_relay_client_legacy_route() {
let _guard = iroh_test::logging::setup();
let server = spawn_local_relay().await.unwrap();
let relay_url = format!("http://{}", server.http_addr().unwrap());
let relay_url: RelayUrl = relay_url.parse().unwrap();
// We're testing the legacy endpoint at `/derp`
let endpoint_url = format!("http://{}/derp", server.http_addr().unwrap());

// set up client a
let secret_key = SecretKey::generate();
let resolver = crate::dns::default_resolver().clone();
let (client, _) = ClientBuilder::new(relay_url)
.relay_path("/derp") // Try the legacy relay path for backwards compatibility
.build(secret_key, resolver);
let client = reqwest::Client::new();
let result = client
.get(endpoint_url)
.header(UPGRADE, HTTP_UPGRADE_PROTOCOL)
.send()
.await
.unwrap();

client.ping().await.unwrap();
assert_eq!(result.status(), StatusCode::SWITCHING_PROTOCOLS);
}

#[tokio::test]
Expand Down

0 comments on commit 9fb48a4

Please sign in to comment.