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));
tokio::fs::write ("quic_server.crt", &server_cert).await?;
let relay_state = RelayState::default ();
let relay_state = Arc::new (relay_state);
let relay_state = Arc::new (RelayState::default ());
let make_svc = make_service_fn (|_conn| {
async {
Ok::<_, String> (service_fn (move |req| {
handle_http (req, ())
}))
}
});
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);
handle_http (req, relay_state)
}))
}
})
};
let http_addr = SocketAddr::from (([0, 0, 0, 0], 4004));
@ -75,13 +77,20 @@ async fn main () -> anyhow::Result <()> {
Ok (())
}
async fn handle_http (req: Request <Body>, _state: ())
async fn handle_http (req: Request <Body>, relay_state: Arc <RelayState>)
-> 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 ()
.status (StatusCode::OK)
.header ("content-type", "text/plain")
.body (Body::from ("pong\n"))?;
.body (Body::from (debug_string))?;
Ok (resp)
}