add HTTP server to the relay server for debugging

main
_ 2021-09-10 12:08:15 -05:00
parent 584654a6b4
commit 5ffdb5800d
4 changed files with 45 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1328,6 +1328,7 @@ dependencies = [
"anyhow",
"base64",
"futures-util",
"hyper",
"quinn",
"rcgen",
"rmp-serde",

View File

@ -12,6 +12,7 @@ anyhow = "1.0.38"
base64 = "0.13.0"
# fltk = "1.1.1"
futures-util = "0.3.9"
hyper = { version = "0.14.4", features = ["http1", "server", "stream", "tcp"] }
quinn = "0.7.2"
rcgen = "0.8.11"
rmp-serde = "0.15.5"

View File

@ -1,3 +1,14 @@
use hyper::{
Body,
Request,
Response,
Server,
service::{
make_service_fn,
service_fn,
},
StatusCode,
};
use structopt::StructOpt;
use quic_demo::prelude::*;
@ -23,6 +34,26 @@ async fn main () -> anyhow::Result <()> {
let relay_state = RelayState::default ();
let relay_state = Arc::new (relay_state);
let make_svc = make_service_fn (|_conn| {
async {
Ok::<_, String> (service_fn (move |req| {
handle_http (req, ())
}))
}
});
let http_addr = SocketAddr::from (([0, 0, 0, 0], 4004));
let http_server = Server::bind (&http_addr);
tokio::spawn (async move {
http_server.serve (make_svc).await
});
while let Some (conn) = incoming.next ().await {
let relay_state = Arc::clone (&relay_state);
@ -44,6 +75,17 @@ async fn main () -> anyhow::Result <()> {
Ok (())
}
async fn handle_http (req: Request <Body>, _state: ())
-> anyhow::Result <Response <Body>>
{
let resp = Response::builder ()
.status (StatusCode::OK)
.header ("content-type", "text/plain")
.body (Body::from ("pong\n"))?;
Ok (resp)
}
#[derive (Default)]
struct RelayState {
p4_server_proxies: Mutex <HashMap <PeerId, P4State>>,

View File

@ -1,5 +1,6 @@
pub use std::{
collections::*,
net::SocketAddr,
sync::{
Arc,
atomic::{