Split up the prefixes for frontend and servers so we can separate auth easier
parent
b352f459c7
commit
16984ddcd3
|
@ -130,12 +130,12 @@ mod tests {
|
||||||
.timeout (std::time::Duration::from_secs (2))
|
.timeout (std::time::Duration::from_secs (2))
|
||||||
.build ().unwrap ();
|
.build ().unwrap ();
|
||||||
|
|
||||||
let resp = client.get (&format! ("{}/relay_up_check", relay_url))
|
let resp = client.get (&format! ("{}/frontend/relay_up_check", relay_url))
|
||||||
.send ().await.unwrap ().bytes ().await.unwrap ();
|
.send ().await.unwrap ().bytes ().await.unwrap ();
|
||||||
|
|
||||||
assert_eq! (resp, "Relay is up\n");
|
assert_eq! (resp, "Relay is up\n");
|
||||||
|
|
||||||
let resp = client.get (&format! ("{}/servers/{}/files/COPYING", relay_url, server_name))
|
let resp = client.get (&format! ("{}/frontend/servers/{}/files/COPYING", relay_url, server_name))
|
||||||
.send ().await.unwrap ().bytes ().await.unwrap ();
|
.send ().await.unwrap ().bytes ().await.unwrap ();
|
||||||
|
|
||||||
if blake3::hash (&resp) != blake3::Hash::from ([
|
if blake3::hash (&resp) != blake3::Hash::from ([
|
||||||
|
@ -155,7 +155,7 @@ mod tests {
|
||||||
// Requesting a file from a server that isn't registered
|
// Requesting a file from a server that isn't registered
|
||||||
// will error out
|
// will error out
|
||||||
|
|
||||||
let resp = client.get (&format! ("{}/servers/obviously_this_server_does_not_exist/files/COPYING", relay_url))
|
let resp = client.get (&format! ("{}/frontend/servers/obviously_this_server_does_not_exist/files/COPYING", relay_url))
|
||||||
.send ().await.unwrap ();
|
.send ().await.unwrap ();
|
||||||
|
|
||||||
assert_eq! (resp.status (), reqwest::StatusCode::NOT_FOUND);
|
assert_eq! (resp.status (), reqwest::StatusCode::NOT_FOUND);
|
||||||
|
|
|
@ -308,7 +308,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
|
||||||
// This is stuff the server can use. Clients can't
|
// This is stuff the server can use. Clients can't
|
||||||
// POST right now
|
// POST right now
|
||||||
|
|
||||||
return Ok (if let Some (request_code) = prefix_match (path, "/7ZSFUKGV_http_response/") {
|
return Ok (if let Some (request_code) = prefix_match (path, "/7ZSFUKGV/http_response/") {
|
||||||
let request_code = request_code.into ();
|
let request_code = request_code.into ();
|
||||||
handle_http_response (req, state, request_code).await
|
handle_http_response (req, state, request_code).await
|
||||||
}
|
}
|
||||||
|
@ -317,14 +317,14 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok (if let Some (listen_code) = prefix_match (path, "/7ZSFUKGV_http_listen/") {
|
Ok (if let Some (listen_code) = prefix_match (path, "/7ZSFUKGV/http_listen/") {
|
||||||
let api_key = match api_key {
|
let api_key = match api_key {
|
||||||
None => return Ok (status_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
|
None => return Ok (status_reply (StatusCode::UNAUTHORIZED, "Can't register as server without an API key")),
|
||||||
Some (x) => x,
|
Some (x) => x,
|
||||||
};
|
};
|
||||||
handle_http_listen (state, listen_code.into (), api_key.as_bytes ()).await
|
handle_http_listen (state, listen_code.into (), api_key.as_bytes ()).await
|
||||||
}
|
}
|
||||||
else if let Some (rest) = prefix_match (path, "/servers/") {
|
else if let Some (rest) = prefix_match (path, "/frontend/servers/") {
|
||||||
if rest == "" {
|
if rest == "" {
|
||||||
#[derive (Serialize)]
|
#[derive (Serialize)]
|
||||||
struct ServerEntry <'a> {
|
struct ServerEntry <'a> {
|
||||||
|
@ -364,7 +364,7 @@ async fn handle_all (req: Request <Body>, state: Arc <RelayState>)
|
||||||
status_reply (StatusCode::BAD_REQUEST, "Bad URI format")
|
status_reply (StatusCode::BAD_REQUEST, "Bad URI format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if path == "/relay_up_check" {
|
else if path == "/frontend/relay_up_check" {
|
||||||
status_reply (StatusCode::OK, "Relay is up\n")
|
status_reply (StatusCode::OK, "Relay is up\n")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -80,7 +80,7 @@ async fn handle_req_resp <'a> (
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut resp_req = state.client
|
let mut resp_req = state.client
|
||||||
.post (&format! ("{}/7ZSFUKGV_http_response/{}", state.config.relay_url, req_id))
|
.post (&format! ("{}/7ZSFUKGV/http_response/{}", state.config.relay_url, req_id))
|
||||||
.header (crate::PTTH_MAGIC_HEADER, base64::encode (rmp_serde::to_vec (&response.parts).unwrap ()));
|
.header (crate::PTTH_MAGIC_HEADER, base64::encode (rmp_serde::to_vec (&response.parts).unwrap ()));
|
||||||
|
|
||||||
if let Some (body) = response.body {
|
if let Some (body) = response.body {
|
||||||
|
@ -152,7 +152,7 @@ pub async fn main (config_file: ConfigFile, opt: Opt)
|
||||||
delay_for (Duration::from_millis (backoff_delay)).await;
|
delay_for (Duration::from_millis (backoff_delay)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
let req_req = state.client.get (&format! ("{}/7ZSFUKGV_http_listen/{}", state.config.relay_url, config_file.name));
|
let req_req = state.client.get (&format! ("{}/7ZSFUKGV/http_listen/{}", state.config.relay_url, config_file.name));
|
||||||
|
|
||||||
let err_backoff_delay = std::cmp::min (30_000, backoff_delay * 2 + 500);
|
let err_backoff_delay = std::cmp::min (30_000, backoff_delay * 2 + 500);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue