Connection With Omega

This commit is contained in:
Alex Emmet 2026-01-05 02:17:12 +01:00
commit 504e5ff015
20 changed files with 880 additions and 320 deletions

View file

@ -9,9 +9,7 @@ use uuid::Uuid;
use super::{rho_connection::RhoConnection, rho_manager};
use crate::calls::call_manager;
use crate::util::print::PrintType;
use crate::util::print::line;
use crate::util::print::line_err;
use crate::util::logger::PrintType;
use crate::{
auth::auth_connector,
// calls::call_manager::CallManager,
@ -21,6 +19,7 @@ use crate::{
},
omega::omega_connection::OmegaConnection,
};
use crate::{log_in, log_out};
/// ClientConnection represents a WebSocket connection from a client device
pub struct ClientConnection {
@ -94,17 +93,14 @@ impl ClientConnection {
.send(Message::Text(Utf8Bytes::from(message.to_string())))
.await
{
line_err(
PrintType::ClientOut,
&format!("Failed to send message to client: {}", e),
);
log_out!(PrintType::Client, "Failed to send message to client: {}", e,);
}
}
/// Send a CommunicationValue to the client
pub async fn send_message(&self, cv: &CommunicationValue) {
if !cv.is_type(CommunicationType::pong) {
line(PrintType::ClientOut, &cv.to_json().to_string());
log_out!(PrintType::Client, "{}", &cv.to_json().to_string());
}
self.send_message_str(&cv.to_json().to_string()).await;
}
@ -129,7 +125,7 @@ impl ClientConnection {
self.handle_ping(cv).await;
return;
}
line(PrintType::ClientIn, &cv.to_json().to_string());
log_in!(PrintType::Client, "{}", &cv.to_json().to_string());
// Handle client status changes
if cv.is_type(CommunicationType::client_changed) {
self.handle_client_changed(cv).await;
@ -181,7 +177,7 @@ impl ClientConnection {
return;
}
} else {
line(PrintType::ClientIn, "Missing private key");
log_in!(PrintType::Client, "Missing private key");
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_private_key)
.await;
return;
@ -246,8 +242,7 @@ impl ClientConnection {
async fn handle_client_changed(&self, cv: CommunicationValue) {
let user_id = self.get_user_id().await;
if let Some(_status_str) = cv.get_data(DataTypes::user_state) {
// Parse user status - this would need to be implemented properly
let user_status = UserStatus::online; // placeholder
let user_status = UserStatus::online;
if let Some(rho_conn) = self.get_rho_connection().await {
OmegaConnection::client_changed(rho_conn.get_iota_id().await, user_id, user_status)
.await;
@ -354,6 +349,19 @@ impl ClientConnection {
return;
}
}
async fn handle_call_timeout_user(&self, cv: CommunicationValue) {
let user_id = cv.get_data(DataTypes::call_id).unwrap();
let call_id = cv.get_data(DataTypes::user_id).unwrap(); // JA man braucht CALL_ID
}
async fn handle_call_disconnect_user(&self, cv: CommunicationValue) {
let user_id = cv.get_data(DataTypes::call_id).unwrap();
let call_id = cv.get_data(DataTypes::user_id).unwrap(); // JA man braucht CALL_ID
let untill = cv.get_data(DataTypes::untill).unwrap();
}
async fn handle_call_set_anonymous_joining(&self, cv: CommunicationValue) {
let call_id = cv.get_data(DataTypes::user_id).unwrap();
let enable = cv.get_data(DataTypes::enable).unwrap();
}
/// Forward message to Iota
async fn forward_to_iota(&self, cv: CommunicationValue) {

View file

@ -1,8 +1,9 @@
use crate::calls::call_group::CallGroup;
use crate::calls::call_manager;
use crate::util::print::PrintType;
use crate::util::print::line;
use crate::util::print::line_err;
use crate::log_err;
use crate::log_in;
use crate::log_out;
use crate::util::logger::PrintType;
use async_tungstenite::WebSocketReceiver;
use async_tungstenite::WebSocketSender;
use async_tungstenite::tungstenite::Message;
@ -94,17 +95,14 @@ impl IotaConnection {
.send(Message::Text(Utf8Bytes::from(message.to_string())))
.await
{
line_err(
PrintType::IotaOut,
&format!("Failed to send WebSocket message: {:?}", e),
);
log_err!(PrintType::Iota, "Failed to send WebSocket message: {:?}", e,);
}
}
/// Send a CommunicationValue to the Iota
pub async fn send_message(&self, cv: CommunicationValue) {
if !cv.is_type(CommunicationType::pong) {
line(PrintType::IotaOut, &cv.to_json().to_string());
log_out!(PrintType::Iota, "{}", cv.to_json().to_string());
}
self.send_message_str(&cv.to_json().to_string()).await;
}
@ -115,7 +113,7 @@ impl IotaConnection {
// Handle identification
if cv.is_type(CommunicationType::identification) && !self.is_identified().await {
line(PrintType::IotaIn, &cv.to_json().to_string());
log_in!(PrintType::Iota, "{}", &cv.to_json().to_string());
self.handle_identification(cv).await;
return;
}
@ -129,7 +127,7 @@ impl IotaConnection {
self.handle_ping(cv).await;
return;
}
line(PrintType::IotaIn, &cv.to_json().to_string());
log_in!(PrintType::Iota, "{}", &cv.to_json().to_string());
// Handle forwarding to other Iotas or clients
let receiver_id = cv.get_receiver();
if !self.get_user_ids().await.contains(&receiver_id)
@ -171,27 +169,26 @@ impl IotaConnection {
match id_str.parse::<i64>() {
Ok(user_id) => {
if let Some(auth_iota_id) = auth_connector::get_iota_id(user_id).await {
line(
PrintType::IotaIn,
&format!(
"auth for {} should be {} is {}",
user_id, iota_id, auth_iota_id
),
log_in!(
PrintType::Iota,
"auth for {} should be {} is {}",
user_id,
iota_id,
auth_iota_id
);
if auth_iota_id == iota_id {
validated_user_ids.push(user_id);
}
} else {
line(
PrintType::IotaIn,
&format!("User ID {} not parsed", id_str.trim()),
);
log_in!(PrintType::Iota, "User ID {} not parsed", user_id);
}
}
Err(e) => {
line(
PrintType::IotaIn,
&format!("Failed to parse '{}' as i64: {:?}", id_str, e),
log_in!(
PrintType::Iota,
"Failed to parse '{}' as i64: {:?}",
id_str,
e,
);
}
}
@ -273,16 +270,7 @@ impl IotaConnection {
let receiver_id = cv.get_receiver();
let sender_id = cv.get_sender();
if self.get_user_ids().await.contains(&receiver_id) {
if let Some(target_rho) = self.get_rho_connection().await {
target_rho.message_to_iota(cv).await;
} else {
let error = CommunicationValue::new(CommunicationType::error)
.with_id(cv.get_id())
.with_sender(cv.get_sender());
self.send_message(error).await;
}
} else if self.get_user_ids().await.contains(&sender_id) {
if self.get_user_ids().await.contains(&sender_id) {
if let Some(target_rho) = rho_manager::get_rho_con_for_user(receiver_id).await {
target_rho.message_to_iota(cv).await;
} else {
@ -329,10 +317,10 @@ impl IotaConnection {
// Process contacts and add call information
let enriched_contacts = if *empty {
if let Some(contacts_data) = cv.get_data(DataTypes::user_ids) {
line(PrintType::CallIn, "Call empty");
log_in!(PrintType::Call, "Call empty");
contacts_data.clone()
} else {
line(PrintType::CallIn, "Call empty No Data");
log_in!(PrintType::Call, "Call empty No Data");
JsonValue::new_array()
}
} else {

View file

@ -1,6 +1,7 @@
use super::rho_connection::RhoConnection;
use crate::util::print::PrintType;
use crate::util::print::line;
use crate::log_in;
use crate::log_out;
use crate::util::logger::PrintType;
use std::{
collections::HashMap,
sync::{Arc, LazyLock},
@ -12,17 +13,12 @@ pub static RHO_CONNECTIONS: LazyLock<Arc<RwLock<HashMap<i64, Arc<RhoConnection>>
pub async fn get_rho_con_for_user(user_id: i64) -> Option<Arc<RhoConnection>> {
let connections = RHO_CONNECTIONS.read().await;
line(
PrintType::ClientIn,
&format!("Checking user ID: {:?}", user_id),
);
log_in!(PrintType::Client, "Checking user ID: {:?}", user_id,);
for rho_connection in connections.values() {
line(
PrintType::ClientIn,
&format!(
"Comparing user IDs: {:?}",
rho_connection.get_user_ids().to_vec()
),
log_in!(
PrintType::Client,
"Comparing user IDs: {:?}",
rho_connection.get_user_ids().to_vec()
);
if rho_connection.get_user_ids().contains(&user_id) {
return Some(Arc::clone(rho_connection));