Merge pull request #2 from t3kkm0tt/main

Fixed warnings and migrated to TTP
This commit is contained in:
Alex Emmet 2026-03-24 20:31:21 +00:00 committed by GitHub
commit 59ff644468
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 107 additions and 55 deletions

56
Cargo.lock generated
View file

@ -11,8 +11,6 @@ dependencies = [
"base64 0.22.1",
"dashmap",
"dotenv",
"epsilon-core",
"epsilon-native",
"futures",
"hex",
"hkdf",
@ -28,6 +26,8 @@ dependencies = [
"strum_macros",
"thiserror 2.0.18",
"tokio",
"ttp-core",
"ttp-native",
"uuid",
"x448",
]
@ -697,32 +697,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "epsilon-core"
version = "0.1.0"
source = "git+https://github.com/Tensamin/Epsilon.git#bafbf13f43a9f7092341ec102621e234438be163"
dependencies = [
"base64 0.22.1",
"byteorder",
"rand 0.8.5",
"strum",
"strum_macros",
]
[[package]]
name = "epsilon-native"
version = "0.1.0"
source = "git+https://github.com/Tensamin/Epsilon.git#bafbf13f43a9f7092341ec102621e234438be163"
dependencies = [
"epsilon-core",
"quinn",
"rustls",
"rustls-native-certs",
"thiserror 2.0.18",
"tokio",
"wtransport",
]
[[package]]
name = "equivalent"
version = "1.0.2"
@ -2938,6 +2912,32 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "ttp-core"
version = "0.1.0"
source = "git+https://github.com/t3kkm0tt/TTP.git#8a3cd5cea756d62e7f85824ebfa1e64c7594c7de"
dependencies = [
"base64 0.22.1",
"byteorder",
"rand 0.8.5",
"strum",
"strum_macros",
]
[[package]]
name = "ttp-native"
version = "0.1.0"
source = "git+https://github.com/t3kkm0tt/TTP.git#8a3cd5cea756d62e7f85824ebfa1e64c7594c7de"
dependencies = [
"quinn",
"rustls",
"rustls-native-certs",
"thiserror 2.0.18",
"tokio",
"ttp-core",
"wtransport",
]
[[package]]
name = "tungstenite"
version = "0.20.1"

View file

@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2024"
[dependencies]
epsilon-core = { git = "https://github.com/Tensamin/Epsilon.git", package = "epsilon-core" }
epsilon-native = { git = "https://github.com/Tensamin/Epsilon.git", package = "epsilon-native" }
ttp-core = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-core" }
ttp-native = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-native" }
ansi_term = "*"
uuid = { version = "*", features = ["v4"] }

View file

@ -1,9 +1,9 @@
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use epsilon_native::{Receiver, Sender};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use ttp_native::{Receiver, Sender};
use uuid::Uuid;
use crate::anonymous_clients::anonymous_manager::{self, generate_username};
@ -457,7 +457,7 @@ impl AnonymousClientConnection {
let error = CommunicationValue::new(error_type).with_id(*message_id);
self.send_message(&error).await;
}
#[allow(dead_code)]
/// Close the connection
pub async fn close(&self) {
let mut is_open_guard = self.is_open.write().await;
@ -469,16 +469,19 @@ impl AnonymousClientConnection {
let _ = self.sender.close();
}
#[allow(dead_code)]
/// Set interested users list
pub async fn set_interested_users(self: Arc<Self>, interested_ids: Vec<i64>) {
let mut interested_guard = self.interested_users.write().await;
*interested_guard = interested_ids;
}
#[allow(dead_code)]
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
let interested_guard = self.interested_users.read().await;
interested_guard.clone()
}
#[allow(dead_code)]
/// Check if interested in a user and send notification
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
let interested_guard = self.clone().get_interested_users().await;
@ -491,6 +494,7 @@ impl AnonymousClientConnection {
}
}
#[allow(dead_code)]
/// Handle connection close
pub async fn handle_close(&self) {

View file

@ -9,10 +9,12 @@ use crate::anonymous_clients::anonymous_client_connection::AnonymousClientConnec
static ANONYMOUS_USERS: Lazy<DashMap<u64, Arc<AnonymousClientConnection>>> =
Lazy::new(|| DashMap::new());
#[allow(dead_code)]
pub async fn add_anonymous_user(connection: Arc<AnonymousClientConnection>) {
ANONYMOUS_USERS.insert(connection.get_user_id(), connection);
}
#[allow(dead_code)]
pub async fn remove_anonymous_user(user_id: u64) {
ANONYMOUS_USERS.remove(&user_id);
}

View file

@ -1,4 +1,4 @@
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use std::{env, sync::Arc, time::Duration};
use tokio::sync::RwLock;

View file

@ -6,7 +6,7 @@ use uuid::Uuid;
use crate::calls::{call_group::CallGroup, caller::Caller};
pub static CALL_GROUPS: Lazy<DashMap<Uuid, Arc<CallGroup>>> = Lazy::new(|| DashMap::new());
#[allow(dead_code)]
pub async fn get_call_invites(user_id: u64) -> Vec<Arc<Caller>> {
let mut callers = Vec::new();
for (_, cg) in CALL_GROUPS.clone().into_iter() {

View file

@ -54,6 +54,7 @@ pub fn create_token(user_id: u64, call_id: Uuid, has_admin: bool) -> Result<Stri
Err(())
}
}
#[allow(dead_code)]
pub async fn get_room(call_id: Uuid) -> Result<(RoomClient, Room), ()> {
if let Ok((hostname, api_key, api_secret)) = get_livekit() {
let room_service = RoomClient::with_api_key(&hostname, &api_key, &api_secret);
@ -82,6 +83,7 @@ pub async fn remove_participant(call_id: Uuid, user_id: u64) -> Result<(), ()> {
return Err(());
}
#[allow(dead_code)]
pub async fn get_room_metadata(call_id: Uuid) -> Result<String, ()> {
if let Ok((_, room)) = get_room(call_id).await {
Ok(room.metadata)

View file

@ -21,12 +21,14 @@ impl Caller {
timeout: RwLock::new(0),
}
}
#[allow(dead_code)]
pub fn set_admin(&mut self, has_admin: bool) {
self.has_admin = has_admin;
}
pub fn has_admin(&self) -> bool {
self.has_admin
}
#[allow(dead_code)]
pub async fn is_timeouted(&self) -> bool {
*self.timeout.read().await
> SystemTime::now()

View file

@ -9,8 +9,6 @@ use crate::{
},
};
use dashmap::DashMap;
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
use epsilon_native::{Receiver, Sender};
use once_cell::sync::Lazy;
use std::{collections::HashMap, env, sync::Arc, time::Duration};
use tokio::{
@ -18,6 +16,8 @@ use tokio::{
task::JoinHandle,
time::{Instant, sleep},
};
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
use ttp_native::{Receiver, Sender};
use uuid::Uuid;
// ============================================================================
@ -64,6 +64,7 @@ pub enum ConnectionState {
Connected { identified: bool },
}
#[allow(unused_variables)]
impl ConnectionState {
pub fn is_connected(&self) -> bool {
match self {
@ -72,6 +73,7 @@ impl ConnectionState {
}
}
#[allow(dead_code)]
pub fn is_identified(&self) -> bool {
match self {
ConnectionState::Connected { identified: true } => true,
@ -83,6 +85,7 @@ impl ConnectionState {
// ============================================================================
// Omega Connection (Client-side with auto-reconnect)
// ============================================================================
#[allow(dead_code)]
pub struct OmegaConnection {
state: Arc<RwLock<ConnectionState>>,
sender: Arc<RwLock<Option<Arc<Sender>>>>,
@ -153,6 +156,7 @@ impl OmegaConnection {
*self.connection_loop_handle.lock().await = Some(handle);
}
#[allow(dead_code)]
pub async fn stop(&self) {
// Disable reconnection
*self.reconnect_on_close.write().await = false;
@ -239,7 +243,7 @@ impl OmegaConnection {
let addr_str = format!("https://{}:{}", self.host, self.port);
let (sender, mut receiver) = epsilon_native::client::connect(&addr_str, None)
let (sender, mut receiver) = ttp_native::client::connect(&addr_str, None)
.await
.map_err(|e| format!("Connection failed: {}", e))?;
@ -444,7 +448,7 @@ impl OmegaConnection {
async fn read_loop(
self: Arc<Self>,
receiver: &mut Receiver,
sender_handle: Arc<epsilon_native::ConnectionHandle>,
sender_handle: Arc<ttp_native::ConnectionHandle>,
) {
// Monitor both receiver and sender handle for close
let mut close_rx = sender_handle.subscribe_close();
@ -634,14 +638,16 @@ impl OmegaConnection {
}
}
#[allow(dead_code)]
pub async fn is_connected(&self) -> bool {
self.state.read().await.is_connected()
}
#[allow(dead_code)]
pub async fn is_identified(&self) -> bool {
self.state.read().await.is_identified()
}
#[allow(dead_code)]
pub async fn close_iota(iota_id: i64) {
let cv = CommunicationValue::new(CommunicationType::iota_disconnected)
.add_data(DataTypes::iota_id, DataValue::Number(iota_id));

View file

@ -1,6 +1,6 @@
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
use std::time::Duration;
use tokio::time::Instant;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
use crate::omega::omega_connection::OmegaConnection;

View file

@ -6,12 +6,12 @@ use crate::rho::{rho_connection::RhoConnection, rho_manager};
use crate::util::logger::PrintType;
use crate::{data::user::UserStatus, omega::omega_connection::OmegaConnection};
use crate::{log_cv_in, log_cv_out, log_out};
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use epsilon_native::{Receiver, Sender};
use std::str::FromStr;
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::sync::RwLock;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use ttp_native::{Receiver, Sender};
use uuid::Uuid;
pub struct ClientConnection {
@ -455,6 +455,7 @@ impl ClientConnection {
}
/// Close the connection
#[allow(dead_code)]
pub async fn close(&self) {
let mut is_open_guard = self.is_open.write().await;
if *is_open_guard {
@ -470,12 +471,14 @@ impl ClientConnection {
let mut interested_guard = self.interested_users.write().await;
*interested_guard = interested_ids;
}
#[allow(dead_code)]
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
let interested_guard = self.interested_users.read().await;
interested_guard.clone()
}
/// Check if interested in a user and send notification
#[allow(dead_code)]
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
let interested_guard = self.clone().get_interested_users().await;
if interested_guard.contains(&user_id) {
@ -488,6 +491,7 @@ impl ClientConnection {
}
/// Handle connection close
#[allow(dead_code)]
pub async fn handle_close(&self) {
let user_id = self.get_user_id().await;
if let Some(rho_conn) = rho_manager::get_rho_con_for_user(user_id as i64).await {

View file

@ -1,8 +1,8 @@
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use epsilon_native::{Receiver, Sender};
use rand::{Rng, distributions::Alphanumeric};
use std::{sync::Arc, time::Duration};
use tokio::sync::RwLock;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use ttp_native::{Receiver, Sender};
use crate::{
anonymous_clients::anonymous_client_connection::AnonymousClientConnection,
@ -20,6 +20,7 @@ use crate::{
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub enum ConnectionKind {
Client,
Iota,

View file

@ -7,12 +7,6 @@ use crate::omega::omega_connection::get_omega_connection;
use crate::rho::connection::GeneralConnection;
use crate::util::logger::PrintType;
use dashmap::DashMap;
use epsilon_core::CommunicationType;
use epsilon_core::CommunicationValue;
use epsilon_core::DataTypes;
use epsilon_core::DataValue;
use epsilon_native::Receiver;
use epsilon_native::Sender;
use std::collections::BTreeMap;
use std::{
collections::HashMap,
@ -21,11 +15,18 @@ use std::{
};
use tokio::sync::RwLock;
use tokio::sync::mpsc;
use ttp_core::CommunicationType;
use ttp_core::CommunicationValue;
use ttp_core::DataTypes;
use ttp_core::DataValue;
use ttp_native::Receiver;
use ttp_native::Sender;
use x448::PublicKey;
use super::{rho_connection::RhoConnection, rho_manager};
use crate::omega::omega_connection::OmegaConnection;
#[allow(dead_code)]
pub struct IotaConnection {
pub iota_id: u64,
pub sender: Arc<Sender>,
@ -72,6 +73,7 @@ impl IotaConnection {
self.iota_id
}
#[allow(dead_code)]
pub async fn get_public_key(&self) -> Option<PublicKey> {
if let Some(public_key) = self.pub_key.read().await.clone() {
PublicKey::from_bytes(&public_key)
@ -163,11 +165,13 @@ impl IotaConnection {
self.forward_to_client(cv).await;
}
#[allow(dead_code)]
async fn send_error_response(&self, message_id: u32, error_type: CommunicationType) {
let error = CommunicationValue::new(error_type).with_id(message_id);
self.send_message(&error).await;
}
#[allow(dead_code)]
async fn close(&self) {
let _ = self.sender.close();
}
@ -346,12 +350,14 @@ impl IotaConnection {
}
}
#[allow(dead_code)]
pub async fn handle_close(&self) {
if let Some(rho_conn) = self.get_rho_connection().await {
rho_conn.close_iota_connection().await;
}
}
#[allow(dead_code)]
pub async fn await_response(
self: Arc<IotaConnection>,
cv: &CommunicationValue,

View file

@ -2,10 +2,10 @@ use super::{client_connection::ClientConnection, iota_connection::IotaConnection
use crate::data::user::UserStatus;
use crate::omega::omega_connection::OmegaConnection;
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
pub struct RhoConnection {
iota_connection: Arc<IotaConnection>,
@ -58,6 +58,7 @@ impl RhoConnection {
}
/// Add a client connection
#[allow(dead_code)]
pub async fn add_client_connection(&self, connection: Arc<ClientConnection>) {
let notification = CommunicationValue::new(CommunicationType::client_connected).add_data(
DataTypes::user_id,
@ -145,6 +146,7 @@ impl RhoConnection {
}
/// Check if clients are interested in a user
#[allow(dead_code)]
pub async fn are_they_interested(&self, user_id: i64) {
let connections = self.client_connections.read().await;
for connection in connections.iter() {
@ -166,11 +168,13 @@ impl RhoConnection {
}
/// Check if this RhoConnection contains a specific user ID
#[allow(dead_code)]
pub fn contains_user(&self, user_id: &i64) -> bool {
self.user_ids.contains(user_id)
}
/// Get count of active client connections
#[allow(dead_code)]
pub async fn client_count(&self) -> usize {
let connections = self.client_connections.read().await;
connections.len()

View file

@ -26,6 +26,7 @@ pub async fn get_rho_con_for_user(user_id: i64) -> Option<Arc<RhoConnection>> {
None
}
#[allow(dead_code)]
pub async fn contains_iota(iota_id: i64) -> bool {
let connections = RHO_CONNECTIONS.read().await;
connections.contains_key(&iota_id)
@ -45,6 +46,7 @@ pub async fn add_rho(rho_connection: Arc<RhoConnection>) {
}
/// Get a RhoConnection by Iota ID directly
#[allow(dead_code)]
pub async fn get_rho_by_iota(iota_id: i64) -> Option<Arc<RhoConnection>> {
let connections = RHO_CONNECTIONS.read().await;
connections.get(&iota_id).map(Arc::clone)

View file

@ -3,14 +3,14 @@ use crate::{
rho::connection::GeneralConnection,
util::{file_util::load_file_vec, logger::PrintType},
};
use epsilon_native::Host;
use ttp_native::Host;
pub async fn start(port: u16) -> Result<(), Box<dyn std::error::Error>> {
let cert_pem = load_file_vec("certs", "cert.pem").expect("Error loading Pemfile");
let key_pem = load_file_vec("certs", "key.pem").expect("Error loading Keyfile");
let mut host: Host = epsilon_native::host(port, cert_pem, key_pem).await?;
let mut host: Host = ttp_native::host(port, cert_pem, key_pem).await?;
log!(0, PrintType::General, "Server listening on port {}", port);
while let Some((sender, receiver)) = host.next().await {

View file

@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
use x448::{PublicKey, Secret, SharedSecret};
/// Errors for crypto operations
#[allow(dead_code)]
#[derive(Debug)]
pub enum CryptoError {
Base64Decode(base64::DecodeError),
@ -23,11 +24,13 @@ impl From<base64::DecodeError> for CryptoError {
}
}
#[allow(dead_code)]
pub struct KeyPair {
pub secret: Secret,
pub public: PublicKey,
}
#[allow(dead_code)]
pub fn generate_keypair() -> KeyPair {
let mut buf = [0u8; 56];
let mut rng = OsRng;
@ -64,6 +67,7 @@ fn derive_aes_key(shared: &SharedSecret) -> [u8; 32] {
key
}
#[allow(dead_code)]
pub fn encrypt_b64(
base64_secret: &str,
base64_peer_pub: &str,
@ -131,12 +135,14 @@ pub fn decrypt(
Ok(plaintext)
}
#[allow(dead_code)]
pub fn hash_it(input: &str) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.update(input.as_bytes());
hasher.finalize().to_vec()
}
#[allow(dead_code)]
pub fn hex_hash(input: &str) -> String {
let digest = hash_it(input);
digest.iter().map(|b| format!("{:02x}", b)).collect()

View file

@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
use x448::{PublicKey, Secret};
// --- Custom Errors ---
#[allow(dead_code)]
#[derive(Debug)]
pub enum SecurePayloadError {
InvalidBase64,
@ -18,6 +19,7 @@ pub enum SecurePayloadError {
}
// --- Data Format Enum ---
#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub enum DataFormat {
Raw,
@ -66,6 +68,7 @@ impl SecurePayload {
}
/// Helper to get the public key associated with this instance's private key.
#[allow(dead_code)]
pub fn get_public_key(&self) -> [u8; 56] {
*PublicKey::from(&self.private_key).as_bytes()
}
@ -80,11 +83,13 @@ impl SecurePayload {
}
/// Access raw bytes directly
#[allow(dead_code)]
pub fn get_bytes(&self) -> &[u8] {
&self.inner_data
}
/// Returns the SHA-256 Hash of the data in the requested format
#[allow(dead_code)]
pub fn get_hash(&self, format: DataFormat) -> String {
let mut hasher = Sha256::new();
hasher.update(&self.inner_data);
@ -134,6 +139,7 @@ impl SecurePayload {
}
/// Decrypts the held data providing the sender's public key manually.
#[allow(dead_code)]
pub fn decrypt_to_format(
&self,
peer_public_key_bytes: &[u8; 56],

View file

@ -37,6 +37,7 @@ pub fn delete_user_directory(user_id: i64) {
let _ = delete_dir_recursive(&user_dir);
}
#[allow(dead_code)]
pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -63,6 +64,7 @@ pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
let file = File::open(&file_path)?;
Ok(BufReader::new(file))
}
#[allow(dead_code)]
pub fn has_file(path: &str, name: &str) -> bool {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -77,6 +79,7 @@ pub fn has_file(path: &str, name: &str) -> bool {
true
}
#[allow(dead_code)]
pub fn has_dir(path: &str) -> bool {
let dir = Path::new(&get_directory()).join(path);
@ -87,6 +90,7 @@ pub fn has_dir(path: &str) -> bool {
true
}
#[allow(dead_code)]
pub fn load_file(path: &str, name: &str) -> String {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -130,6 +134,7 @@ pub fn load_file_vec(path: &str, name: &str) -> Result<Vec<u8>, std::io::Error>
std::fs::read(file_path)
}
#[allow(dead_code)]
pub fn save_file(path: &str, name: &str, value: &str) {
let dir = Path::new(&get_directory()).join(path);
let file_path = dir.join(name);
@ -157,6 +162,7 @@ pub fn save_file(path: &str, name: &str, value: &str) {
}
}
#[allow(dead_code)]
pub fn get_children(path: &str) -> Vec<String> {
let dir = Path::new(&get_directory()).join(path);
let mut children = Vec::new();

View file

@ -9,10 +9,11 @@ use std::{
};
use ansi_term::Color;
use epsilon_core::{CommunicationValue, DataTypes, DataValue};
use ttp_core::{CommunicationValue, DataTypes, DataValue};
static LOGGER: OnceLock<mpsc::Sender<LogMessage>> = OnceLock::new();
#[allow(dead_code)]
#[derive(Clone, Copy)]
pub enum PrintType {
Call,