From 15a62a5e2aa69f5961738af116bfcccc0c6fc3d3 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sat, 31 Oct 2020 20:21:53 -0500 Subject: [PATCH] :construction: Trying to fix the issue where clients don't wait on servers --- src/bin/server.rs | 1 + src/lib.rs | 14 +++++++++++--- src/server/mod.rs | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 2a2a338..4220f91 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -4,6 +4,7 @@ use std::error::Error; async fn main () -> Result <(), Box > { let opt = ptth::server::Opt { relay_url: "http://127.0.0.1:4000".into (), + server_name: "alien_wildlands".into (), file_server_root: "/home/user".into (), }; diff --git a/src/lib.rs b/src/lib.rs index 745eeac..a11e1f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,9 +41,15 @@ mod tests { let relay_url_2 = relay_url.into (); + let server_name = "alien_wildlands"; + + let server_name_2 = server_name.into (); spawn (async move { + tokio::time::delay_for (std::time::Duration::from_secs (5)).await; + let opt = server::Opt { relay_url: relay_url_2, + server_name: server_name_2, file_server_root: "./".into (), }; @@ -57,10 +63,10 @@ mod tests { assert_eq! (resp, "Relay is up\n"); - let resp = client.get (&format! ("{}/servers/alien_wildlands/COPYING", relay_url)) + let resp = client.get (&format! ("{}/servers/{}/COPYING", relay_url, server_name)) .send ().await.unwrap ().bytes ().await.unwrap (); - assert_eq! (blake3::hash (&resp), blake3::Hash::from ([ + if blake3::hash (&resp) != blake3::Hash::from ([ 0xca, 0x02, 0x92, 0x78, 0x9c, 0x0a, 0x0e, 0xcb, 0xa7, 0x06, 0xf4, 0xb3, @@ -70,7 +76,9 @@ mod tests { 0xc1, 0xd4, 0x32, 0xc5, 0x2c, 0x4a, 0xac, 0x1f, 0x1a, 0xbb, 0xa8, 0xef, - ])); + ]) { + panic! ("{}", String::from_utf8 (resp.to_vec ()).unwrap ()); + } }); } } diff --git a/src/server/mod.rs b/src/server/mod.rs index c710fc7..4b38ce7 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -18,8 +18,6 @@ use crate::http_serde; pub mod file_server; -const SERVER_NAME: &str = "alien_wildlands"; - async fn handle_req_resp <'a> ( opt: &'a Opt, handlebars: Arc >, @@ -60,6 +58,7 @@ async fn handle_req_resp <'a> ( pub struct Opt { pub relay_url: String, + pub server_name: String, pub file_server_root: PathBuf, } @@ -76,7 +75,7 @@ pub async fn main (opt: Opt) -> Result <(), Box > { delay_for (Duration::from_millis (backoff_delay)).await; } - let req_req = client.get (&format! ("{}/7ZSFUKGV_http_listen/{}", opt.relay_url, SERVER_NAME)); + let req_req = client.get (&format! ("{}/7ZSFUKGV_http_listen/{}", opt.relay_url, opt.server_name)); let req_resp = match req_req.send ().await { Err (e) => {