the HTTP server now lists which end servers are connected

main
_ 2021-09-10 12:30:12 -05:00
parent 5ffdb5800d
commit f26748035f
1 changed files with 24 additions and 15 deletions

View File

@ -31,20 +31,22 @@ async fn main () -> anyhow::Result <()> {
println! ("Base64 cert: {}", base64::encode (&server_cert)); println! ("Base64 cert: {}", base64::encode (&server_cert));
tokio::fs::write ("quic_server.crt", &server_cert).await?; tokio::fs::write ("quic_server.crt", &server_cert).await?;
let relay_state = RelayState::default (); let relay_state = Arc::new (RelayState::default ());
let relay_state = Arc::new (relay_state);
let make_svc = make_service_fn (|_conn| { let make_svc = {
let relay_state = Arc::clone (&relay_state);
make_service_fn (move |_conn| {
let relay_state = Arc::clone (&relay_state);
async move {
Ok::<_, String> (service_fn (move |req| {
let relay_state = Arc::clone (&relay_state);
async { handle_http (req, relay_state)
Ok::<_, String> (service_fn (move |req| { }))
}
})
handle_http (req, ()) };
}))
}
});
let http_addr = SocketAddr::from (([0, 0, 0, 0], 4004)); let http_addr = SocketAddr::from (([0, 0, 0, 0], 4004));
@ -75,13 +77,20 @@ async fn main () -> anyhow::Result <()> {
Ok (()) Ok (())
} }
async fn handle_http (req: Request <Body>, _state: ()) async fn handle_http (req: Request <Body>, relay_state: Arc <RelayState>)
-> anyhow::Result <Response <Body>> -> anyhow::Result <Response <Body>>
{ {
let debug_string;
{
let p4_server_proxies = relay_state.p4_server_proxies.lock ().await;
debug_string = format! ("{:#?}\n", p4_server_proxies.keys ().collect::<Vec<_>> ());
}
let resp = Response::builder () let resp = Response::builder ()
.status (StatusCode::OK) .status (StatusCode::OK)
.header ("content-type", "text/plain") .header ("content-type", "text/plain")
.body (Body::from ("pong\n"))?; .body (Body::from (debug_string))?;
Ok (resp) Ok (resp)
} }