Fixing
This commit is contained in:
parent
04356f991a
commit
d37d949513
7 changed files with 18 additions and 37 deletions
|
|
@ -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<Self>, 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": "<uuid>",
|
||||
* "log": {
|
||||
* "log_level": 0,
|
||||
* "message": "running function"
|
||||
* },
|
||||
* "data": {
|
||||
* "codec": "<channel_codec>", // optional
|
||||
* "name": "<channel_name>",
|
||||
* "path": "<overlord_category_name>/<overlord_category_name>...",
|
||||
* "function": "<function_to_execute>",
|
||||
* "payload": {
|
||||
* "<ARG_1>": "<VAL_1>",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<DataTypes, JsonValue>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl CommunicationValue {
|
||||
pub fn new(comm_type: CommunicationType) -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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<Arc<ServerConfig>, Box<dyn Error>> {
|
||||
// Load certificate file
|
||||
|
|
|
|||
|
|
@ -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<CommunityConnection> =
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue