diff --git a/src/routes/krist/ws.rs b/src/routes/krist/ws.rs index a405716..a0cc3c3 100644 --- a/src/routes/krist/ws.rs +++ b/src/routes/krist/ws.rs @@ -28,6 +28,7 @@ struct WsConnDetails { #[post("/start")] #[tracing::instrument(name = "setup_ws_route", level = "debug", skip_all)] pub async fn setup_ws( + req: HttpRequest, state: web::Data, server: web::Data, details: Option>, @@ -38,6 +39,12 @@ pub async fn setup_ws( // with fuck all in it, I would be so happy <3 let private_key = details.and_then(|d| d.into_inner().privatekey); + let computer_id = req + .headers() + .get("X-CC-ID") + .and_then(|id| id.to_str().ok()) + .and_then(|s| s.parse::().ok()); + let uuid = match private_key { Some(private_key) => { let wallet = Wallet::verify_address(pool, &private_key) @@ -45,12 +52,12 @@ pub async fn setup_ws( .map_err(|_| KristError::Address(AddressError::AuthFailed))?; let model = wallet.model; - let token_data = WebSocketTokenData::new(model.address, Some(private_key)); + let token_data = WebSocketTokenData::new(model.address, Some(private_key), computer_id); server.obtain_token(token_data) } None => { - let token_data = WebSocketTokenData::new("guest".into(), None); + let token_data = WebSocketTokenData::new("guest".into(), None, computer_id); server.obtain_token(token_data) } diff --git a/src/websockets/mod.rs b/src/websockets/mod.rs index eea9b88..d9bc156 100644 --- a/src/websockets/mod.rs +++ b/src/websockets/mod.rs @@ -58,6 +58,7 @@ impl WebSocketServer { private_key: data.private_key, session, subscriptions, + computer_id: data.computer_id, }; if self.sessions.insert_sync(uuid, session_data).is_err() { diff --git a/src/websockets/types/common.rs b/src/websockets/types/common.rs index a98d60c..3e4b870 100644 --- a/src/websockets/types/common.rs +++ b/src/websockets/types/common.rs @@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize}; pub struct WebSocketTokenData { pub address: String, pub private_key: Option, + pub computer_id: Option, } #[derive(Clone, Serialize)] @@ -14,6 +15,7 @@ pub struct WebSocketSessionData { #[serde(skip)] pub session: actix_ws::Session, pub subscriptions: HashSet, + pub computer_id: Option, } #[derive(Clone, Copy, Debug, Hash, Eq, Serialize, Deserialize, PartialEq, PartialOrd)] @@ -91,10 +93,11 @@ impl std::fmt::Display for WebSocketSubscriptionType { impl WebSocketTokenData { #[inline] - pub fn new(address: String, private_key: Option) -> Self { + pub fn new(address: String, private_key: Option, computer_id: Option) -> Self { Self { address, private_key, + computer_id, } } }