🚧 Trying to fix the issue where clients don't wait on servers
parent
41e5f99688
commit
15a62a5e2a
|
@ -4,6 +4,7 @@ use std::error::Error;
|
||||||
async fn main () -> Result <(), Box <dyn Error>> {
|
async fn main () -> Result <(), Box <dyn Error>> {
|
||||||
let opt = ptth::server::Opt {
|
let opt = ptth::server::Opt {
|
||||||
relay_url: "http://127.0.0.1:4000".into (),
|
relay_url: "http://127.0.0.1:4000".into (),
|
||||||
|
server_name: "alien_wildlands".into (),
|
||||||
file_server_root: "/home/user".into (),
|
file_server_root: "/home/user".into (),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -41,9 +41,15 @@ mod tests {
|
||||||
|
|
||||||
let relay_url_2 = relay_url.into ();
|
let relay_url_2 = relay_url.into ();
|
||||||
|
|
||||||
|
let server_name = "alien_wildlands";
|
||||||
|
|
||||||
|
let server_name_2 = server_name.into ();
|
||||||
spawn (async move {
|
spawn (async move {
|
||||||
|
tokio::time::delay_for (std::time::Duration::from_secs (5)).await;
|
||||||
|
|
||||||
let opt = server::Opt {
|
let opt = server::Opt {
|
||||||
relay_url: relay_url_2,
|
relay_url: relay_url_2,
|
||||||
|
server_name: server_name_2,
|
||||||
file_server_root: "./".into (),
|
file_server_root: "./".into (),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,10 +63,10 @@ mod tests {
|
||||||
|
|
||||||
assert_eq! (resp, "Relay is up\n");
|
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 ();
|
.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,
|
0xca, 0x02, 0x92, 0x78,
|
||||||
0x9c, 0x0a, 0x0e, 0xcb,
|
0x9c, 0x0a, 0x0e, 0xcb,
|
||||||
0xa7, 0x06, 0xf4, 0xb3,
|
0xa7, 0x06, 0xf4, 0xb3,
|
||||||
|
@ -70,7 +76,9 @@ mod tests {
|
||||||
0xc1, 0xd4, 0x32, 0xc5,
|
0xc1, 0xd4, 0x32, 0xc5,
|
||||||
0x2c, 0x4a, 0xac, 0x1f,
|
0x2c, 0x4a, 0xac, 0x1f,
|
||||||
0x1a, 0xbb, 0xa8, 0xef,
|
0x1a, 0xbb, 0xa8, 0xef,
|
||||||
]));
|
]) {
|
||||||
|
panic! ("{}", String::from_utf8 (resp.to_vec ()).unwrap ());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ use crate::http_serde;
|
||||||
|
|
||||||
pub mod file_server;
|
pub mod file_server;
|
||||||
|
|
||||||
const SERVER_NAME: &str = "alien_wildlands";
|
|
||||||
|
|
||||||
async fn handle_req_resp <'a> (
|
async fn handle_req_resp <'a> (
|
||||||
opt: &'a Opt,
|
opt: &'a Opt,
|
||||||
handlebars: Arc <Handlebars <'static>>,
|
handlebars: Arc <Handlebars <'static>>,
|
||||||
|
@ -60,6 +58,7 @@ async fn handle_req_resp <'a> (
|
||||||
|
|
||||||
pub struct Opt {
|
pub struct Opt {
|
||||||
pub relay_url: String,
|
pub relay_url: String,
|
||||||
|
pub server_name: String,
|
||||||
pub file_server_root: PathBuf,
|
pub file_server_root: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +75,7 @@ pub async fn main (opt: Opt) -> Result <(), Box <dyn Error>> {
|
||||||
delay_for (Duration::from_millis (backoff_delay)).await;
|
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 {
|
let req_resp = match req_req.send ().await {
|
||||||
Err (e) => {
|
Err (e) => {
|
||||||
|
|
Loading…
Reference in New Issue