This commit is contained in:
2026-08-11 19:09:37 -04:00
parent cf45fdd2b3
commit 4fd4f96521
5 changed files with 65 additions and 4 deletions
Generated
+7
View File
@@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "anyhow"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]]
name = "atomic-waker"
version = "1.1.2"
@@ -129,6 +135,7 @@ dependencies = [
name = "enclave-server"
version = "0.1.0"
dependencies = [
"anyhow",
"axum",
"tokio",
]
+1
View File
@@ -4,5 +4,6 @@ version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.104"
axum = { version = "0.8.9", features = ["ws"] }
tokio = { version = "1.53.1", features = ["rt", "rt-multi-thread", "macros", "sync"] }
+24 -4
View File
@@ -1,11 +1,31 @@
use axum::{Router, routing::get};
pub mod protocol;
use axum::{
Router,
extract::{WebSocketUpgrade, ws::WebSocket},
response::Response,
routing::{any, get},
};
use crate::protocol::Client;
#[tokio::main]
async fn main() {
// build our application with a single route
let app = Router::new().route("/", get(|| async { "Hello, World!" }));
let app = Router::new()
.route("/meta", get(|| async { "Hello, World!" }))
.route("/", any(ws_handler));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn ws_handler(ws: WebSocketUpgrade) -> Response {
ws.on_upgrade(|socket: WebSocket| async {
match Client::initialize(socket).await {
Ok(client) => {}
Err(e) => {
eprintln!("Failed to initialize client {e}")
}
}
})
}
+11
View File
@@ -0,0 +1,11 @@
use axum::extract::ws::WebSocket;
impl super::Client {
pub async fn initialize(mut socket: WebSocket) -> anyhow::Result<Self> {
Ok(Self {
socket,
meta: super::ClientMeta {},
pub_key: String::new(),
})
}
}
+22
View File
@@ -0,0 +1,22 @@
use axum::extract::ws::WebSocket;
pub mod initialize;
pub struct Client {
pub socket: WebSocket,
pub meta: ClientMeta,
pub pub_key: String,
}
pub struct ClientMeta {}
pub enum ClientMessage {}
pub enum ServerMessage {}
impl Client {
pub async fn read_socket(mut socket: WebSocket) -> anyhow::Result<ClientMessage> {
unimplemented!()
// Ok(socket.recv().await?)
}
}