[Fix] Calls, Spelling

This commit is contained in:
Alex Emmet 2026-05-03 15:02:15 +02:00
commit fc85e9377e
10 changed files with 246 additions and 177 deletions

72
Cargo.lock generated
View file

@ -2,40 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "Omikron"
version = "0.1.0"
dependencies = [
"aes-gcm",
"ansi_term",
"base64 0.22.1",
"dashmap",
"dotenv",
"futures",
"hex",
"hickory-resolver",
"hkdf 0.13.0",
"json",
"livekit-api",
"livekit-protocol",
"log",
"once_cell",
"rand 0.8.6",
"rand_core 0.6.4",
"rustls",
"serde",
"serde_json",
"sha2 0.11.0",
"strum",
"strum_macros",
"thiserror 2.0.18",
"tokio",
"ttp-core",
"ttp-native",
"uuid",
"x448",
]
[[package]] [[package]]
name = "aead" name = "aead"
version = "0.5.2" version = "0.5.2"
@ -2152,6 +2118,40 @@ dependencies = [
"asn1-rs", "asn1-rs",
] ]
[[package]]
name = "omikron"
version = "0.1.0"
dependencies = [
"aes-gcm",
"ansi_term",
"base64 0.22.1",
"dashmap",
"dotenv",
"futures",
"hex",
"hickory-resolver",
"hkdf 0.13.0",
"json",
"livekit-api",
"livekit-protocol",
"log",
"once_cell",
"rand 0.8.6",
"rand_core 0.6.4",
"rustls",
"serde",
"serde_json",
"sha2 0.11.0",
"strum",
"strum_macros",
"thiserror 2.0.18",
"tokio",
"ttp-core",
"ttp-native",
"uuid",
"x448",
]
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.4" version = "1.21.4"
@ -3461,7 +3461,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "ttp-core" name = "ttp-core"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.methanium.net/Tensamin/TTP.git#9677eb6c6040e4e8d85ba8b6232aa954b5a9438d" source = "git+https://git.methanium.net/Tensamin/TTP.git#0cc917d75562953b49a83804f9f37e89aca6fd88"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"byteorder", "byteorder",
@ -3474,7 +3474,7 @@ dependencies = [
[[package]] [[package]]
name = "ttp-native" name = "ttp-native"
version = "0.1.0" version = "0.1.0"
source = "git+https://git.methanium.net/Tensamin/TTP.git#9677eb6c6040e4e8d85ba8b6232aa954b5a9438d" source = "git+https://git.methanium.net/Tensamin/TTP.git#0cc917d75562953b49a83804f9f37e89aca6fd88"
dependencies = [ dependencies = [
"quinn", "quinn",
"rustls", "rustls",

View file

@ -1,5 +1,5 @@
[package] [package]
name = "Omikron" name = "omikron"
version = "0.1.0" version = "0.1.0"
edition = "2024" edition = "2024"
@ -31,8 +31,8 @@ dotenv = "0.15.0"
hkdf = "0.13" hkdf = "0.13"
strum = "0.28.0" strum = "0.28.0"
strum_macros = "0.28.0" strum_macros = "0.28.0"
livekit-api = { version = "0.4.14", features = ["native-tls"] } livekit-api = { version = "0.4.19", features = ["native-tls"] }
livekit-protocol = "0.7.1" livekit-protocol = "0.7.5"
thiserror = "2.0.18" thiserror = "2.0.18"
hickory-resolver = "0.25.2" hickory-resolver = "0.25.2"
serde = "1.0.228" serde = "1.0.228"

View file

@ -344,7 +344,12 @@ impl AnonymousClientConnection {
} }
}; };
let invited = call_manager::add_invite(call_id, self.user_id, receiver_id as u64).await; let secret = cv
.get_data(DataTypes::call_secret)
.as_str()
.map(|s| s.to_string());
let invited =
call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret).await;
if !invited { if !invited {
self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_call_id) self.send_error_response(&cv.get_id(), CommunicationType::error_invalid_call_id)
.await; .await;
@ -459,6 +464,7 @@ impl AnonymousClientConnection {
self.send_message(&error).await; self.send_message(&error).await;
} }
/// Close the connection /// Close the connection
#[allow(unused)]
pub async fn close(&self) { pub async fn close(&self) {
let mut is_open_guard = self.is_open.write().await; let mut is_open_guard = self.is_open.write().await;
if !*is_open_guard { if !*is_open_guard {

View file

@ -3,7 +3,7 @@ use once_cell::sync::Lazy;
use std::sync::Arc; use std::sync::Arc;
use uuid::Uuid; use uuid::Uuid;
use crate::calls::{call_group::CallGroup, caller::Caller}; use crate::calls::{call_group::CallGroup, call_util, caller::Caller};
pub static CALL_GROUPS: Lazy<DashMap<Uuid, Arc<CallGroup>>> = Lazy::new(|| DashMap::new()); pub static CALL_GROUPS: Lazy<DashMap<Uuid, Arc<CallGroup>>> = Lazy::new(|| DashMap::new());
#[allow(dead_code)] #[allow(dead_code)]
@ -59,29 +59,23 @@ pub async fn get_call_token(user_id: u64, call_id: Uuid) -> Option<String> {
return Some(token); return Some(token);
} }
if let Some(cg) = CALL_GROUPS.get(&call_id) {
let cg_clone = cg.clone();
let mut members = cg_clone.members.write().await;
if let Some(member) = members.iter().find(|m| m.user_id == user_id) {
return Some(member.create_token());
}
let new_caller = Arc::new(Caller::new(user_id, call_id, false));
let token = new_caller.create_token();
members.push(new_caller);
return Some(token);
}
let caller = Arc::new(Caller::new(user_id, call_id, true)); let caller = Arc::new(Caller::new(user_id, call_id, true));
let call_group = CallGroup::new(call_id, caller.clone()); let call_group = Arc::new(CallGroup::new(call_id, caller.clone()));
call_group.update_admins().await;
CALL_GROUPS.insert(call_id, Arc::new(call_group)); CALL_GROUPS.insert(call_id, call_group.clone());
let _ = call_util::create_room(call_id).await;
call_group.update_admins().await;
Some(caller.create_token()) Some(caller.create_token())
} }
pub async fn add_invite(call_id: Uuid, inviter_id: u64, invitee_id: u64) -> bool { pub async fn add_invite(
call_id: Uuid,
inviter_id: u64,
invitee_id: u64,
secret: Option<String>,
) -> bool {
if let Some(cg) = CALL_GROUPS.get(&call_id) { if let Some(cg) = CALL_GROUPS.get(&call_id) {
let mut members = cg.members.write().await; let mut members = cg.members.write().await;
@ -91,6 +85,13 @@ pub async fn add_invite(call_id: Uuid, inviter_id: u64, invitee_id: u64) -> bool
if !members.iter().any(|m| m.user_id == invitee_id) { if !members.iter().any(|m| m.user_id == invitee_id) {
members.push(Arc::new(Caller::new(invitee_id, call_id, false))); members.push(Arc::new(Caller::new(invitee_id, call_id, false)));
} }
if let Some(secret) = secret {
let mut secrets = cg.secrets.write().await;
secrets.insert((inviter_id, invitee_id), secret.clone());
secrets.insert((invitee_id, inviter_id), secret);
}
return true; return true;
} }
} }

View file

@ -1,3 +1,4 @@
use livekit_api::services::room::CreateRoomOptions;
use livekit_api::{ use livekit_api::{
access_token::{self}, access_token::{self},
services::room::RoomClient, services::room::RoomClient,
@ -35,6 +36,20 @@ pub fn get_livekit() -> Result<(String, String, String), ()> {
Ok((hostname, api_key, api_secret)) Ok((hostname, api_key, api_secret))
} }
pub async fn create_room(call_id: Uuid) -> Result<(), ()> {
let (hostname, api_key, api_secret) = get_livekit()?;
let room_service = RoomClient::with_api_key(&hostname, &api_key, &api_secret);
let options = CreateRoomOptions::default();
room_service
.create_room(&call_id.to_string(), options)
.await
.map_err(|_| ())?;
Ok(())
}
pub fn create_token(user_id: u64, call_id: Uuid, has_admin: bool) -> Result<String, ()> { pub fn create_token(user_id: u64, call_id: Uuid, has_admin: bool) -> Result<String, ()> {
let (_, api_key, api_secret) = get_livekit()?; let (_, api_key, api_secret) = get_livekit()?;

View file

@ -64,6 +64,7 @@ impl AppConnection {
} }
/// Get current ping /// Get current ping
#[allow(unused)]
pub async fn get_ping(&self) -> i64 { pub async fn get_ping(&self) -> i64 {
*self.ping.read().await *self.ping.read().await
} }
@ -304,6 +305,7 @@ impl AppConnection {
} }
/// Close the connection /// Close the connection
#[allow(unused)]
pub async fn close(&self) { pub async fn close(&self) {
let mut is_open_guard = self.is_open.write().await; let mut is_open_guard = self.is_open.write().await;
if !*is_open_guard { if !*is_open_guard {

View file

@ -274,7 +274,12 @@ impl ClientConnection {
} }
}; };
let invited = call_manager::add_invite(call_id, self.user_id, receiver_id as u64).await; let secret = cv
.get_data(DataTypes::call_secret)
.as_str()
.map(|s| s.to_string());
let invited =
call_manager::add_invite(call_id, self.user_id, receiver_id as u64, secret).await;
if !invited { if !invited {
self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id) self.send_error_response(cv.get_id(), CommunicationType::error_invalid_call_id)
.await; .await;

View file

@ -1,5 +1,5 @@
use rand::{Rng, distributions::Alphanumeric}; use rand::{Rng, distributions::Alphanumeric};
use std::{sync::Arc, time::Duration}; use std::{collections::BTreeMap, collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::RwLock; use tokio::sync::RwLock;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use ttp_native::{Receiver, Sender}; use ttp_native::{Receiver, Sender};
@ -7,7 +7,7 @@ use uuid::Uuid;
use crate::{ use crate::{
anonymous_clients::anonymous_client_connection::AnonymousClientConnection, anonymous_clients::anonymous_client_connection::AnonymousClientConnection,
calls::{call_group::CallGroup, call_manager, caller::Caller}, calls::call_manager,
get_private_key, get_public_key, log_cv_in, log_cv_out, log_err, log_in, log_out, get_private_key, get_public_key, log_cv_in, log_cv_out, log_err, log_in, log_out,
omega::omega_connection::get_omega_connection, omega::omega_connection::get_omega_connection,
rho::{ rho::{
@ -163,7 +163,7 @@ impl GeneralConnection {
.unwrap() .unwrap()
.export(DataFormat::Base64); .export(DataFormat::Base64);
let response = CommunicationValue::new(CommunicationType::app_challange) let response = CommunicationValue::new(CommunicationType::app_challenge)
.with_id(cv.get_id()) .with_id(cv.get_id())
.add_data( .add_data(
DataTypes::public_key, DataTypes::public_key,
@ -315,7 +315,7 @@ impl GeneralConnection {
.export(DataFormat::Base64); .export(DataFormat::Base64);
let challenge_type = if cv.is_type(CommunicationType::app_identification) { let challenge_type = if cv.is_type(CommunicationType::app_identification) {
CommunicationType::app_challange CommunicationType::app_challenge
} else { } else {
CommunicationType::challenge CommunicationType::challenge
}; };
@ -337,7 +337,7 @@ impl GeneralConnection {
let id = *self.id.read().await as i64; let id = *self.id.read().await as i64;
if !cv.is_type(CommunicationType::challenge_response) if !cv.is_type(CommunicationType::challenge_response)
&& !cv.is_type(CommunicationType::app_challange_response) && !cv.is_type(CommunicationType::app_challenge_response)
{ {
return; return;
} }
@ -433,107 +433,108 @@ impl GeneralConnection {
if let Some(contacts) = v.as_array() { if let Some(contacts) = v.as_array() {
let call_groups = let call_groups =
call_manager::get_call_groups(user_id as u64).await; call_manager::get_call_groups(user_id as u64).await;
let callers = let mut invites: HashMap<i64, Vec<DataValue>> = HashMap::new();
call_manager::get_call_invites(user_id as u64).await; let mut global_calls: Vec<DataValue> = Vec::new();
let mapped: Vec<(Arc<Caller>, &Arc<CallGroup>)> = {
callers for call in call_groups {
.iter() let members = call.members.read().await;
.map(|caller| {
( let call_self =
Arc::clone(caller), members.iter().find(|m| m.user_id == user_id as u64);
call_groups.iter().find(|call_group| {
call_group.call_id == caller.call_id if let Some(call_self) = call_self {
}), let timeout = *call_self.timeout.read().await;
) let admin = call_self.has_admin();
})
.filter(|(_, call_group)| call_group.is_some()) // List of all members in the call
.map(|(caller, call_group)| { let member_ids: Vec<DataValue> = members
(caller, call_group.unwrap()) .iter()
}) .map(|m| DataValue::Number(m.user_id as i64))
.collect() .collect();
};
if mapped.is_empty() { let mut base_call_map: BTreeMap<DataTypes, DataValue> =
DataValue::Array(contacts) BTreeMap::new();
} else { base_call_map.insert(
let mut new_contacts: Vec<DataValue> = Vec::new(); DataTypes::call_id,
for contact in contacts { DataValue::Str(call.call_id.to_string()),
if let Some(mut contact_map) = contact.as_map() { );
let filtered_mapped: Vec<( base_call_map.insert(
Arc<Caller>, DataTypes::call_members,
&Arc<CallGroup>, DataValue::Array(member_ids),
)> = mapped );
.clone()
.into_iter() if timeout > 0 {
.filter(|(caller, _)| { base_call_map.insert(
caller.user_id DataTypes::timeout,
== contact_map DataValue::Number(timeout as i64),
.get(&DataTypes::user_id) );
.unwrap_or(&DataValue::Null) }
.as_number()
.unwrap_or(0) if admin {
as u64 base_call_map.insert(
}) DataTypes::has_admin,
.collect(); DataValue::Bool(true),
if filtered_mapped.is_empty() { );
new_contacts.push( }
DataValue::container_from_map(&contact_map),
); // Add to global calls (without contact-specific secret)
global_calls.push(DataValue::container_from_map(
&base_call_map,
));
for member in members.iter() {
let member_id = member.user_id;
if member_id == user_id as u64 {
continue; continue;
} }
let mut vec_of_filtered_calls: Vec<DataValue> = let mut contact_call_map = base_call_map.clone();
Vec::new();
for (caller, call_group) in filtered_mapped { if let Some(secret) = call
vec_of_filtered_calls.push( .secrets
DataValue::Container(vec![ .read()
( .await
DataTypes::call_id, .get(&(member_id, user_id as u64))
DataValue::Str( {
caller.call_id.to_string(), contact_call_map.insert(
), DataTypes::call_secret,
), DataValue::Str(secret.clone()),
(
DataTypes::call_secret,
DataValue::Str(
call_group
.secrets
.read()
.await
.get(&(
contact_map
.get(
&DataTypes::user_id,
)
.unwrap_or(
&DataValue::Null,
)
.as_number()
.unwrap_or(0)
as u64,
user_id as u64,
))
.unwrap_or(&"".to_string())
.clone(),
),
),
]),
); );
} }
if !vec_of_filtered_calls.is_empty() {
contact_map.insert( invites
DataTypes::calls, .entry(member_id as i64)
DataValue::Array(vec_of_filtered_calls), .or_insert_with(Vec::new)
); .push(DataValue::container_from_map(
} &contact_call_map,
new_contacts.push(DataValue::container_from_map( ));
&contact_map,
));
} else {
new_contacts.push(contact.clone());
} }
} }
DataValue::Array(new_contacts)
} }
let mut new_contacts: Vec<DataValue> = Vec::new();
for contact in contacts {
if let Some(mut contact_map) = contact.as_map() {
if let Some(DataValue::Number(id)) =
contact_map.get(&DataTypes::user_id)
{
if let Some(call_list) = invites.get(id) {
contact_map.insert(
DataTypes::calls,
DataValue::Array(call_list.clone()),
);
}
}
new_contacts
.push(DataValue::container_from_map(&contact_map));
} else {
new_contacts.push(contact.clone());
}
}
ident_resp = ident_resp
.add_data(DataTypes::calls, DataValue::Array(global_calls));
DataValue::Array(new_contacts)
} else { } else {
v.clone() v.clone()
} }

View file

@ -316,44 +316,82 @@ impl IotaConnection {
/// Handle GET_CHATS message /// Handle GET_CHATS message
async fn handle_get_chats(&self, cv: CommunicationValue) { async fn handle_get_chats(&self, cv: CommunicationValue) {
let receiver_id = cv.get_receiver(); let user_id = cv.get_sender();
// Authority check: user must be linked to this Iota
if !self.get_user_ids().await.contains(&user_id) {
log_err!(
self.iota_id as i64,
PrintType::Iota,
"Rejected get_chats: sender_id={} is not authorized for this iota.",
user_id
);
return;
}
let mut interested_ids: Vec<i64> = Vec::new(); let mut interested_ids: Vec<i64> = Vec::new();
// ============================ // ============================
// Load Calls // Load Calls
// ============================ // ============================
let calls: Vec<Arc<CallGroup>> = call_manager::get_call_groups(receiver_id).await; let calls: Vec<Arc<CallGroup>> = call_manager::get_call_groups(user_id).await;
let mut invites: HashMap<i64, Vec<DataValue>> = HashMap::new(); let mut invites: HashMap<i64, Vec<DataValue>> = HashMap::new();
let mut global_calls: Vec<DataValue> = Vec::new();
let empty = calls.is_empty(); let empty = calls.is_empty();
for call in calls { for call in calls {
for inviter in call.members.read().await.iter() { let members = call.members.read().await;
let call_self = call.get_caller(receiver_id).await.unwrap();
let inviter_id = inviter.user_id; // Find ourselves in the call to get our specific status
let call_self = members.iter().find(|m| m.user_id == user_id).cloned();
if let Some(call_self) = call_self {
let timeout = *call_self.timeout.read().await; let timeout = *call_self.timeout.read().await;
let admin = call_self.has_admin(); let admin = call_self.has_admin();
// Build call container // List of all members in the call
let mut call_map: BTreeMap<DataTypes, DataValue> = BTreeMap::new(); let member_ids: Vec<DataValue> = members
.iter()
.map(|m| DataValue::Number(m.user_id as i64))
.collect();
call_map.insert(DataTypes::call_id, DataValue::Str(call.call_id.to_string())); // Build base call container
let mut base_call_map: BTreeMap<DataTypes, DataValue> = BTreeMap::new();
base_call_map.insert(DataTypes::call_id, DataValue::Str(call.call_id.to_string()));
base_call_map.insert(DataTypes::call_members, DataValue::Array(member_ids));
if timeout > 0 { if timeout > 0 {
call_map.insert(DataTypes::timeout, DataValue::Number(timeout as i64)); base_call_map.insert(DataTypes::timeout, DataValue::Number(timeout as i64));
} }
if admin { if admin {
call_map.insert(DataTypes::has_admin, DataValue::Bool(true)); base_call_map.insert(DataTypes::has_admin, DataValue::Bool(true));
} }
let call_container = DataValue::container_from_map(&call_map); // Add to global calls (without contact-specific secret)
global_calls.push(DataValue::container_from_map(&base_call_map));
invites // Attach this call to EVERY member of the call (other than ourselves)
.entry(inviter_id as i64) for member in members.iter() {
.or_insert_with(Vec::new) let member_id = member.user_id;
.push(call_container); if member_id == user_id {
continue;
}
let mut contact_call_map = base_call_map.clone();
// Add secret if it exists for this pairing
if let Some(secret) = call.secrets.read().await.get(&(member_id, user_id)) {
contact_call_map
.insert(DataTypes::call_secret, DataValue::Str(secret.clone()));
}
invites
.entry(member_id as i64)
.or_insert_with(Vec::new)
.push(DataValue::container_from_map(&contact_call_map));
}
} }
} }
@ -374,13 +412,10 @@ impl IotaConnection {
let mut user_map: BTreeMap<DataTypes, DataValue> = let mut user_map: BTreeMap<DataTypes, DataValue> =
entries.iter().cloned().collect(); entries.iter().cloned().collect();
// extract user_id if let Some(DataValue::Number(id)) = user_map.get(&DataTypes::user_id) {
if let Some(DataValue::Number(user_id)) = user_map.get(&DataTypes::user_id) interested_ids.push(*id);
{
interested_ids.push(*user_id);
// attach calls if exists if let Some(call_list) = invites.get(id)
if let Some(call_list) = invites.get(user_id)
&& !call_list.is_empty() && !call_list.is_empty()
{ {
user_map user_map
@ -399,22 +434,25 @@ impl IotaConnection {
// ============================ // ============================
// Notify Omega // Notify Omega
// ============================ // ============================
OmegaConnection::user_states(receiver_id as i64, interested_ids.clone()).await; OmegaConnection::user_states(user_id as i64, interested_ids.clone()).await;
// ============================ // ============================
// Notify Rho // Notify Rho
// ============================ // ============================
if let Some(rho_conn) = self.get_rho_connection().await { if let Some(rho_conn) = self.get_rho_connection().await {
rho_conn rho_conn
.set_interested(receiver_id as i64, interested_ids) .set_interested(user_id as i64, interested_ids)
.await; .await;
} }
// ============================ // ============================
// Forward to client // Forward to client
// ============================ // ============================
self.forward_to_client(cv.add_data(DataTypes::user_ids, enriched_contacts)) self.forward_to_client(
.await; cv.add_data(DataTypes::user_ids, enriched_contacts)
.add_data(DataTypes::calls, DataValue::Array(global_calls)),
)
.await;
} }
/// Forward message to client /// Forward message to client

View file

@ -77,6 +77,7 @@ impl RhoConnection {
collections collections
} }
#[allow(unused)]
pub async fn get_app_connections( pub async fn get_app_connections(
&self, &self,
userid: Option<i64>, userid: Option<i64>,