Skip to content

Commit

Permalink
todos
Browse files Browse the repository at this point in the history
  • Loading branch information
neonphog committed Dec 11, 2024
1 parent 281eecb commit ba66f4a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
50 changes: 33 additions & 17 deletions crates/bootstrap_srv/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl HttpReceiver {

pub struct ServerConfig {
pub addr: std::net::SocketAddr,
pub worker_thread_count: usize,
}

pub struct Server {
Expand Down Expand Up @@ -116,8 +117,8 @@ fn tokio_thread(
.build()
.unwrap()
.block_on(async move {
// actually use the worker thread count??
let (h_send, h_recv) = async_channel::bounded(1024);
let (h_send, h_recv) =
async_channel::bounded(config.worker_thread_count);

let app: Router = Router::new()
.route("/health", routing::get(handle_health_get))
Expand Down Expand Up @@ -210,12 +211,10 @@ async fn handle_boot_get(
extract::Path(space): extract::Path<String>,
extract::State(h_send): extract::State<HSend>,
) -> response::Response {
use base64::prelude::*;

// TODO FIX UNWRAP
let space = bytes::Bytes::copy_from_slice(
&BASE64_URL_SAFE_NO_PAD.decode(&space).unwrap(),
);
let space = match b64_to_bytes(&space) {
Ok(space) => space,
Err(err) => return err,
};
handle_dispatch(&h_send, HttpRequest::BootstrapGet { space }).await
}

Expand All @@ -224,15 +223,32 @@ async fn handle_boot_put(
extract::State(h_send): extract::State<HSend>,
body: bytes::Bytes,
) -> response::Response<body::Body> {
use base64::prelude::*;

// TODO FIX UNWRAP
let space = bytes::Bytes::copy_from_slice(
&BASE64_URL_SAFE_NO_PAD.decode(&space).unwrap(),
);
let agent = bytes::Bytes::copy_from_slice(
&BASE64_URL_SAFE_NO_PAD.decode(&agent).unwrap(),
);
let space = match b64_to_bytes(&space) {
Ok(space) => space,
Err(err) => return err,
};
let agent = match b64_to_bytes(&agent) {
Ok(agent) => agent,
Err(err) => return err,
};
handle_dispatch(&h_send, HttpRequest::BootstrapPut { space, agent, body })
.await
}

fn b64_to_bytes(
s: &str,
) -> std::result::Result<bytes::Bytes, response::Response<body::Body>> {
use base64::prelude::*;
Ok(bytes::Bytes::copy_from_slice(
&match BASE64_URL_SAFE_NO_PAD.decode(s) {
Ok(b) => b,
Err(err) => {
return Err(HttpResponse {
status: 400,
body: err.to_string().into_bytes(),
}
.respond())
}
},
))
}
1 change: 1 addition & 0 deletions crates/bootstrap_srv/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl BootstrapSrv {
// tiny_http configuration
let sconf = ServerConfig {
addr: config.listen_address,
worker_thread_count: config.worker_thread_count,
// TODO make the server able to accept TLS certificates
// ssl: None,
};
Expand Down

0 comments on commit ba66f4a

Please sign in to comment.