Auth Paths fixed

OUTLINE of calls Rho: Iota & Clients. Works Correct File handeling

TODO: Omega Connection
This commit is contained in:
Alex Emmet 2025-10-19 02:14:20 +02:00
commit ba81f3651e
18 changed files with 488 additions and 477 deletions

View file

@ -5,19 +5,103 @@ mod omega;
mod rho;
mod util;
use crate::rho::client_connection;
use crate::rho::iota_connection;
use crate::util::config_util::Config;
use crate::util::file_util;
use tokio_websocket_server::socket::{WebSocketMessage, WebsocketServer};
use tracing::info;
use tracing_subscriber::fmt;
use futures::StreamExt;
use std::sync::Arc;
use tokio::net::TcpListener;
use tokio_tungstenite::accept_hdr_async;
use tungstenite::handshake::server::{Request, Response};
use crate::{
omega::omega_connection::OmegaConnection,
rho::{client_connection::ClientConnection, iota_connection::IotaConnection},
};
#[tokio::main]
async fn main() {
fmt::init();
OmegaConnection::new().connect().await;
loop {
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
let listener = TcpListener::bind("0.0.0.0:959").await.unwrap();
println!("WebSocket server listening on 0.0.0.0:959");
while let Ok((stream, _)) = listener.accept().await {
tokio::spawn(async move {
let mut path: String = "/".to_string();
let callback = |req: &Request, response: Response| {
path = format!("{}", &req.uri().path());
Ok(response)
};
let ws_stream = match accept_hdr_async(stream, callback).await {
Ok(ws) => ws,
Err(e) => {
eprintln!("WebSocket upgrade failed: {}", e);
return;
}
};
println!("New {} connection", path);
if path == "/ws/client/" {
let client_conn: Arc<ClientConnection> =
Arc::from(ClientConnection::new(ws_stream));
loop {
let msg_result = {
let mut session_lock = client_conn.session.lock().await;
session_lock.next().await
};
match msg_result {
Some(Ok(msg)) => {
if msg.is_text() {
let text = msg.into_text().unwrap();
client_conn.clone().handle_message(text).await;
} else if msg.is_close() {
println!("Client disconnected");
client_conn.handle_close().await;
return;
}
}
Some(Err(e)) => {
eprintln!("WebSocket error: {}", e);
client_conn.handle_close().await;
return;
}
None => {
println!("Client stream ended");
client_conn.handle_close().await;
return;
}
}
}
} else if path == "/ws/iota/" {
let iota_conn: Arc<IotaConnection> = Arc::from(IotaConnection::new(ws_stream));
loop {
let msg_result = {
let mut session_lock = iota_conn.session.lock().await;
session_lock.next().await
};
match msg_result {
Some(Ok(msg)) => {
if msg.is_text() {
let text = msg.into_text().unwrap();
iota_conn.clone().handle_message(text).await;
} else if msg.is_close() {
println!("Iota disconnected");
iota_conn.handle_close().await;
return;
}
}
Some(Err(e)) => {
eprintln!("WebSocket error: {}", e);
iota_conn.handle_close().await;
return;
}
None => {
// Stream ended
println!("Iota stream ended");
iota_conn.handle_close().await;
return;
}
}
}
}
});
}
}