Fix build errors.
This commit is contained in:
parent
9c0c400546
commit
614616193c
@ -12,7 +12,6 @@ hyper-tungstenite = "0.14.0"
|
||||
rustls = "0.23.5"
|
||||
rustls-pemfile = "2.1.2"
|
||||
webpki-roots = "0.26"
|
||||
opaque-ke = "2.0.0"
|
||||
hyper = { version = "1.4.1", features = ["full"] }
|
||||
hyper-util = { version = "0.1.7", features = ["tokio"] }
|
||||
http-body-util = "0.1.2"
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::path::Path;
|
||||
|
||||
use bus::Bus;
|
||||
|
||||
mod config;
|
||||
mod util;
|
||||
mod app;
|
||||
@ -24,19 +22,11 @@ use system::{
|
||||
};
|
||||
use protocol::QRPacket;
|
||||
|
||||
#[derive(Clone)]
|
||||
struct HttpServiceArgs {
|
||||
tx:Sender<QRPacket>,
|
||||
cache:WebCache,
|
||||
}
|
||||
impl HttpServiceArgs {
|
||||
pub async fn clone(&mut self) -> Self
|
||||
{
|
||||
Self {
|
||||
tx:self.tx.clone(),
|
||||
cache:self.cache.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn service_http(mut request:hyper::Request<hyper::body::Incoming>, args:HttpServiceArgs) -> Result<hyper::Response<http_body_util::Full<Bytes>>, std::convert::Infallible>
|
||||
// Serve cached files and upgrade websocket connections.
|
||||
@ -120,7 +110,7 @@ async fn service_http(mut request:hyper::Request<hyper::body::Incoming>, args:Ht
|
||||
}
|
||||
}
|
||||
|
||||
async fn handle_http<S>(stream:S, addr:SocketAddr, mut args:HttpServiceArgs) -> Result<(),()>
|
||||
async fn handle_http<S>(stream:S, addr:SocketAddr, args:HttpServiceArgs) -> Result<(),()>
|
||||
where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static
|
||||
// Hand off socket connection to Hyper server.
|
||||
//
|
||||
@ -132,10 +122,9 @@ where S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Unpin + Send + 'static
|
||||
|
||||
let io = TokioIo::new(stream);
|
||||
|
||||
let args = args.clone().await;
|
||||
let conn = http1::Builder::new()
|
||||
.serve_connection(io, service_fn(move |req| {
|
||||
service_http(req, args)
|
||||
service_http(req, args.clone())
|
||||
}));
|
||||
|
||||
conn.with_upgrades().await.ok();
|
||||
@ -207,9 +196,6 @@ async fn main()
|
||||
}
|
||||
js_asset_data += "}};";
|
||||
|
||||
match b_main.connect().await {
|
||||
Ok(mut bus) => {
|
||||
|
||||
/*
|
||||
** Cache source files.
|
||||
*/
|
||||
@ -279,12 +265,11 @@ async fn main()
|
||||
let mut tcp_server = TcpServer::new();
|
||||
match tcp_server.bind("127.0.0.1:38611").await {
|
||||
Ok(_) => {
|
||||
let mut b = bus.connect().await.unwrap();
|
||||
let c = cache.clone();
|
||||
let data_tx = data_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
while tcp_server.accept(handle_tcp, HttpServiceArgs {
|
||||
tx:data_tx,
|
||||
tx:data_tx.clone(),
|
||||
cache:c.clone(),
|
||||
}).await.is_ok() { }
|
||||
});
|
||||
@ -305,14 +290,11 @@ async fn main()
|
||||
}
|
||||
match tls_server.bind("0.0.0.0:38612").await {
|
||||
Ok(_) => {
|
||||
let (tx, rx) = tokio::sync::mpsc::channel::<>(24);
|
||||
let mut b = bus.connect().await.unwrap();
|
||||
let c = cache.clone();
|
||||
|
||||
let data_tx = data_tx.clone();
|
||||
tokio::spawn(async move {
|
||||
while tls_server.accept(handle_tls, HttpServiceArgs {
|
||||
tx:data_tx,
|
||||
tx:data_tx.clone(),
|
||||
cache:c.clone(),
|
||||
}).await.is_ok() { }
|
||||
});
|
||||
@ -321,11 +303,6 @@ async fn main()
|
||||
println!("error: failed to bind TLS port 38612.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
println!("error: failed to initialize HTTPS service.");
|
||||
}
|
||||
}
|
||||
|
||||
loop { tokio::time::sleep(tokio::time::Duration::from_secs(10)).await; }
|
||||
}
|
||||
|
@ -23,8 +23,7 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
||||
|
||||
let mut send_user_status = Vec::<u32>::new();
|
||||
|
||||
while let Some(packet) = rx.recv().await {
|
||||
let qr = packet.data;
|
||||
while let Some(qr) = rx.recv().await {
|
||||
|
||||
let mut user_id = None;
|
||||
let mut context = Context::None;
|
||||
@ -44,7 +43,7 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
||||
stream,
|
||||
} => {
|
||||
let id = app.connections.add(Connection {
|
||||
stream: request.stream,
|
||||
stream,
|
||||
auth: None,
|
||||
|
||||
context:Context::None,
|
||||
@ -1053,10 +1052,8 @@ pub async fn thread_system(mut app:App, mut rx:Receiver<QRPacket>)
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_game_state(app:&App, session:&Session) -> protocol::PacketGameStateResponse
|
||||
fn generate_game_state(app:&App, session:&Session) -> PacketGameStateResponse
|
||||
{
|
||||
use protocol::PacketGameStateResponse;
|
||||
|
||||
let mut response = PacketGameStateResponse::new();
|
||||
|
||||
response.token = session.token;
|
||||
|
@ -11,7 +11,7 @@ use crate::{
|
||||
HttpServiceArgs,
|
||||
};
|
||||
|
||||
pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServiceArgs) -> Result<(),()>
|
||||
pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, args:HttpServiceArgs) -> Result<(),()>
|
||||
// Handle websocket connection.
|
||||
//
|
||||
{
|
||||
@ -21,7 +21,7 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServi
|
||||
let conn_id :u32;
|
||||
|
||||
let (sink, mut stream) = ws.split();
|
||||
let (tx, rx) = mpsc::channel::<QRPacket>(1);
|
||||
let (tx, mut rx) = mpsc::channel::<QRPacket>(1);
|
||||
|
||||
// Perform connection handshake with data system.
|
||||
// - Provide system with connection/bus pairing.
|
||||
@ -30,11 +30,10 @@ pub async fn handle_ws(ws:WebSocketStream<TokioIo<Upgraded>>, mut args:HttpServi
|
||||
args.tx.send(QRPacket::new(0, QRPacketData::QConn {
|
||||
tx:tx.clone(),
|
||||
stream:Arc::new(RwLock::new(sink)),
|
||||
})).await?;
|
||||
})).await.map_err(|_| ())?;
|
||||
|
||||
if let Some(resp) = rx.blocking_recv() {
|
||||
let qr = &resp.data;
|
||||
match qr.data {
|
||||
if let Some(qr) = rx.recv().await {
|
||||
match &qr.data {
|
||||
QRPacketData::RConn => { conn_id = qr.id; }
|
||||
_ => { return Err(()); }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user