From d37d9495132652fbb87b41cf697a343c1f1043e7 Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Thu, 13 Nov 2025 23:14:23 +0000 Subject: [PATCH] Fixing --- src/communities/community_connection.rs | 28 ++++------------------ src/communities/interactables/category.rs | 1 - src/communities/interactables/text_chat.rs | 4 +--- src/data/communication.rs | 6 +++++ src/main.rs | 1 - src/server/server.rs | 5 ++-- src/server/socket.rs | 10 ++++---- 7 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/communities/community_connection.rs b/src/communities/community_connection.rs index dc94fe8..55e9bd8 100644 --- a/src/communities/community_connection.rs +++ b/src/communities/community_connection.rs @@ -15,10 +15,8 @@ use json::JsonValue; use rand::{Rng, distributions::Alphanumeric}; use sha2::Sha256; use std::sync::Arc; -use tokio::sync::Mutex; use tokio::sync::RwLock; use tokio_tungstenite::WebSocketStream; -use tokio_util::compat::Compat; use tungstenite::Message; use tungstenite::Utf8Bytes; use uuid::Uuid; @@ -68,8 +66,10 @@ impl CommunityConnection { } pub async fn handle_message(self: Arc, message: String) { - let cv = - CommunicationValue::from_json(&message).with_sender(self.get_user_id().await.unwrap()); + let mut cv = CommunicationValue::from_json(&message); + if let Some(user_id) = self.get_user_id().await { + cv = cv.with_sender(user_id); + } if cv.is_type(CommunicationType::identification) && !self.is_identified().await { self.handle_identification(cv).await; @@ -101,26 +101,6 @@ impl CommunityConnection { } } async fn handle_function(&self, cv: CommunicationValue) { - /* - * { - * "type": "function", - * "id": "", - * "log": { - * "log_level": 0, - * "message": "running function" - * }, - * "data": { - * "codec": "", // optional - * "name": "", - * "path": "/...", - * "function": "", - * "payload": { - * "": "", - * ... - * } - * } - * } - */ let name = cv.get_data(DataTypes::name).unwrap().as_str().unwrap(); let path = cv.get_data(DataTypes::path).unwrap().as_str().unwrap(); let function = cv.get_data(DataTypes::function).unwrap().as_str().unwrap(); diff --git a/src/communities/interactables/category.rs b/src/communities/interactables/category.rs index 92ef3d1..9fac8b6 100644 --- a/src/communities/interactables/category.rs +++ b/src/communities/interactables/category.rs @@ -3,7 +3,6 @@ use crate::{ data::communication::{CommunicationType, CommunicationValue}, }; use async_trait::async_trait; -use axum::Json; use json::JsonValue; use std::any::Any; use std::sync::Arc; diff --git a/src/communities/interactables/text_chat.rs b/src/communities/interactables/text_chat.rs index dfe5526..b61b9c0 100644 --- a/src/communities/interactables/text_chat.rs +++ b/src/communities/interactables/text_chat.rs @@ -7,13 +7,11 @@ use crate::{ gui::log_panel::log_message, util::file_util::{get_children, load_file, save_file}, }; -use aes_gcm::aead::Payload; use async_trait::async_trait; -use axum::Json; use json::{JsonValue, array, object}; +use std::fs; use std::sync::Arc; use std::{any::Any, collections::HashMap}; -use std::{fs, pin::Pin}; use uuid::Uuid; pub struct TextChat { name: String, diff --git a/src/data/communication.rs b/src/data/communication.rs index 63d7ea6..386895a 100644 --- a/src/data/communication.rs +++ b/src/data/communication.rs @@ -6,6 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use uuid::Uuid; #[derive(Eq, Hash, PartialEq, Clone, Debug)] +#[allow(non_camel_case_types, dead_code)] pub enum DataTypes { error_type, accepted_ids, @@ -152,11 +153,15 @@ impl DataTypes { } #[derive(PartialEq, Clone, Debug)] +#[allow(non_camel_case_types, dead_code)] pub enum CommunicationType { error, error_invalid_user_id, error_not_found, + error_no_iota, error_invalid_challenge, + error_invalid_secret, + error_invalid_private_key, success, message, message_send, @@ -264,6 +269,7 @@ pub struct CommunicationValue { pub data: HashMap, } +#[allow(dead_code)] impl CommunicationValue { pub fn new(comm_type: CommunicationType) -> Self { Self { diff --git a/src/main.rs b/src/main.rs index abcac06..fc5b744 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,6 @@ mod server; mod users; mod util; -use crate::communities::community::Community; use crate::communities::community_manager; use crate::communities::interactables::registry; use crate::data::communication::{CommunicationType, CommunicationValue, DataTypes}; diff --git a/src/server/server.rs b/src/server/server.rs index 6b32663..ff0b7cd 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -1,4 +1,5 @@ -use base64::encode; +use base64::Engine; +use base64::engine::general_purpose::STANDARD; use futures::{StreamExt, TryFutureExt}; use http_body_util::Full; use hyper::body::Bytes; @@ -206,7 +207,7 @@ fn calculate_accept_key(key: &str) -> String { sha1.update(key.as_bytes()); sha1.update(websocket_guid.as_bytes()); let result = sha1.finalize(); - encode(result) // Base64 encode the result + STANDARD.encode(result) // Base64 encode the result } fn load_tls_config() -> Result, Box> { // Load certificate file diff --git a/src/server/socket.rs b/src/server/socket.rs index 8386f4a..c81f743 100644 --- a/src/server/socket.rs +++ b/src/server/socket.rs @@ -7,12 +7,7 @@ use futures::stream::SplitStream; use hyper::upgrade::Upgraded; use hyper_util::rt::TokioIo; use std::sync::Arc; -use tokio::net::TcpListener; -use tokio_util::compat::{Compat, TokioAsyncReadCompatExt}; -use tungstenite::{ - Message, Utf8Bytes, - handshake::server::{Request, Response}, -}; +use tungstenite::Message; pub fn handle( path: String, @@ -22,7 +17,9 @@ pub fn handle( tokio::spawn(async move { if path.starts_with("/ws/community/") { let community_id = path.split("/").nth(3).unwrap(); + log_message(format!("Community: {}", community_id)); if let Some(community) = community_manager::get_community(community_id).await { + log_message("Connected"); let community_conn: Arc = Arc::from(CommunityConnection::new(writer, reader, community)); loop { @@ -51,6 +48,7 @@ pub fn handle( return; } None => { + log_message("Closed Session me!"); community_conn.handle_close().await; return; }