[code] remove server struct
This commit is contained in:
parent
a2a630893f
commit
c00b7dbe9c
@ -27,8 +27,6 @@ mod assets;
|
|||||||
static KEY_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../key.pem"));
|
static KEY_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../key.pem"));
|
||||||
static CERT_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../cert.pem"));
|
static CERT_PEM: &str = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../cert.pem"));
|
||||||
|
|
||||||
struct Server;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct ServerCtx {
|
struct ServerCtx {
|
||||||
handler: RequestHandler,
|
handler: RequestHandler,
|
||||||
@ -40,8 +38,7 @@ struct ConnectionCtx {
|
|||||||
remote_addr: String,
|
remote_addr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Server {
|
async fn run(addr: SocketAddr, db: GameDB) -> eyre::Result<()> {
|
||||||
async fn run(addr: SocketAddr, db: GameDB) -> eyre::Result<()> {
|
|
||||||
let mut server = QuicServer::builder()
|
let mut server = QuicServer::builder()
|
||||||
.with_tls((CERT_PEM, KEY_PEM))?
|
.with_tls((CERT_PEM, KEY_PEM))?
|
||||||
.with_io(addr)?
|
.with_io(addr)?
|
||||||
@ -78,13 +75,8 @@ impl Server {
|
|||||||
|
|
||||||
let request = Request::decode(data);
|
let request = Request::decode(data);
|
||||||
tracing::debug!("{} msg: {:?}", conn_ctx.remote_addr, request);
|
tracing::debug!("{} msg: {:?}", conn_ctx.remote_addr, request);
|
||||||
let response =
|
let response = conn_ctx.server_ctx.handler.handle_request(request).await;
|
||||||
conn_ctx.server_ctx.handler.handle_request(request).await;
|
tracing::trace!("{} server response: {:?}", conn_ctx.remote_addr, response);
|
||||||
tracing::trace!(
|
|
||||||
"{} server response: {:?}",
|
|
||||||
conn_ctx.remote_addr,
|
|
||||||
response
|
|
||||||
);
|
|
||||||
let raw_response = response.encode();
|
let raw_response = response.encode();
|
||||||
tracing::trace!(
|
tracing::trace!(
|
||||||
"{} server response (raw): {}",
|
"{} server response (raw): {}",
|
||||||
@ -108,7 +100,6 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -225,5 +216,5 @@ async fn main() -> eyre::Result<()> {
|
|||||||
|
|
||||||
tracing::info!("Server listening on {}:{}", cli.ip, cli.port);
|
tracing::info!("Server listening on {}:{}", cli.ip, cli.port);
|
||||||
|
|
||||||
Server::run(SocketAddr::from((cli.ip, cli.port)), game_db).await
|
run(SocketAddr::from((cli.ip, cli.port)), game_db).await
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user