Merge pull request #2 from t3kkm0tt/main
Fixed warnings and migrated to TTP
This commit is contained in:
commit
59ff644468
20 changed files with 107 additions and 55 deletions
56
Cargo.lock
generated
56
Cargo.lock
generated
|
|
@ -11,8 +11,6 @@ dependencies = [
|
||||||
"base64 0.22.1",
|
"base64 0.22.1",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"epsilon-core",
|
|
||||||
"epsilon-native",
|
|
||||||
"futures",
|
"futures",
|
||||||
"hex",
|
"hex",
|
||||||
"hkdf",
|
"hkdf",
|
||||||
|
|
@ -28,6 +26,8 @@ dependencies = [
|
||||||
"strum_macros",
|
"strum_macros",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"ttp-core",
|
||||||
|
"ttp-native",
|
||||||
"uuid",
|
"uuid",
|
||||||
"x448",
|
"x448",
|
||||||
]
|
]
|
||||||
|
|
@ -697,32 +697,6 @@ dependencies = [
|
||||||
"zeroize",
|
"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]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
|
|
@ -2938,6 +2912,32 @@ version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
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]]
|
[[package]]
|
||||||
name = "tungstenite"
|
name = "tungstenite"
|
||||||
version = "0.20.1"
|
version = "0.20.1"
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
epsilon-core = { git = "https://github.com/Tensamin/Epsilon.git", package = "epsilon-core" }
|
ttp-core = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-core" }
|
||||||
epsilon-native = { git = "https://github.com/Tensamin/Epsilon.git", package = "epsilon-native" }
|
ttp-native = { git = "https://github.com/Tensamin/TTP.git", package = "ttp-native" }
|
||||||
|
|
||||||
ansi_term = "*"
|
ansi_term = "*"
|
||||||
uuid = { version = "*", features = ["v4"] }
|
uuid = { version = "*", features = ["v4"] }
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
|
||||||
use epsilon_native::{Receiver, Sender};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
||||||
|
use ttp_native::{Receiver, Sender};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::anonymous_clients::anonymous_manager::{self, generate_username};
|
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);
|
let error = CommunicationValue::new(error_type).with_id(*message_id);
|
||||||
self.send_message(&error).await;
|
self.send_message(&error).await;
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Close the connection
|
/// Close the connection
|
||||||
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;
|
||||||
|
|
@ -469,16 +469,19 @@ impl AnonymousClientConnection {
|
||||||
let _ = self.sender.close();
|
let _ = self.sender.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Set interested users list
|
/// Set interested users list
|
||||||
pub async fn set_interested_users(self: Arc<Self>, interested_ids: Vec<i64>) {
|
pub async fn set_interested_users(self: Arc<Self>, interested_ids: Vec<i64>) {
|
||||||
let mut interested_guard = self.interested_users.write().await;
|
let mut interested_guard = self.interested_users.write().await;
|
||||||
*interested_guard = interested_ids;
|
*interested_guard = interested_ids;
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
|
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
|
||||||
let interested_guard = self.interested_users.read().await;
|
let interested_guard = self.interested_users.read().await;
|
||||||
interested_guard.clone()
|
interested_guard.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Check if interested in a user and send notification
|
/// Check if interested in a user and send notification
|
||||||
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
|
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
|
||||||
let interested_guard = self.clone().get_interested_users().await;
|
let interested_guard = self.clone().get_interested_users().await;
|
||||||
|
|
@ -491,6 +494,7 @@ impl AnonymousClientConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
/// Handle connection close
|
/// Handle connection close
|
||||||
pub async fn handle_close(&self) {
|
pub async fn handle_close(&self) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ use crate::anonymous_clients::anonymous_client_connection::AnonymousClientConnec
|
||||||
static ANONYMOUS_USERS: Lazy<DashMap<u64, Arc<AnonymousClientConnection>>> =
|
static ANONYMOUS_USERS: Lazy<DashMap<u64, Arc<AnonymousClientConnection>>> =
|
||||||
Lazy::new(|| DashMap::new());
|
Lazy::new(|| DashMap::new());
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn add_anonymous_user(connection: Arc<AnonymousClientConnection>) {
|
pub async fn add_anonymous_user(connection: Arc<AnonymousClientConnection>) {
|
||||||
ANONYMOUS_USERS.insert(connection.get_user_id(), connection);
|
ANONYMOUS_USERS.insert(connection.get_user_id(), connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn remove_anonymous_user(user_id: u64) {
|
pub async fn remove_anonymous_user(user_id: u64) {
|
||||||
ANONYMOUS_USERS.remove(&user_id);
|
ANONYMOUS_USERS.remove(&user_id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 std::{env, sync::Arc, time::Duration};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use uuid::Uuid;
|
||||||
use crate::calls::{call_group::CallGroup, caller::Caller};
|
use crate::calls::{call_group::CallGroup, 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)]
|
||||||
pub async fn get_call_invites(user_id: u64) -> Vec<Arc<Caller>> {
|
pub async fn get_call_invites(user_id: u64) -> Vec<Arc<Caller>> {
|
||||||
let mut callers = Vec::new();
|
let mut callers = Vec::new();
|
||||||
for (_, cg) in CALL_GROUPS.clone().into_iter() {
|
for (_, cg) in CALL_GROUPS.clone().into_iter() {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ pub fn create_token(user_id: u64, call_id: Uuid, has_admin: bool) -> Result<Stri
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_room(call_id: Uuid) -> Result<(RoomClient, Room), ()> {
|
pub async fn get_room(call_id: Uuid) -> Result<(RoomClient, Room), ()> {
|
||||||
if let Ok((hostname, api_key, api_secret)) = get_livekit() {
|
if let Ok((hostname, api_key, api_secret)) = get_livekit() {
|
||||||
let room_service = RoomClient::with_api_key(&hostname, &api_key, &api_secret);
|
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(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_room_metadata(call_id: Uuid) -> Result<String, ()> {
|
pub async fn get_room_metadata(call_id: Uuid) -> Result<String, ()> {
|
||||||
if let Ok((_, room)) = get_room(call_id).await {
|
if let Ok((_, room)) = get_room(call_id).await {
|
||||||
Ok(room.metadata)
|
Ok(room.metadata)
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,14 @@ impl Caller {
|
||||||
timeout: RwLock::new(0),
|
timeout: RwLock::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn set_admin(&mut self, has_admin: bool) {
|
pub fn set_admin(&mut self, has_admin: bool) {
|
||||||
self.has_admin = has_admin;
|
self.has_admin = has_admin;
|
||||||
}
|
}
|
||||||
pub fn has_admin(&self) -> bool {
|
pub fn has_admin(&self) -> bool {
|
||||||
self.has_admin
|
self.has_admin
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn is_timeouted(&self) -> bool {
|
pub async fn is_timeouted(&self) -> bool {
|
||||||
*self.timeout.read().await
|
*self.timeout.read().await
|
||||||
> SystemTime::now()
|
> SystemTime::now()
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ use crate::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
|
||||||
use epsilon_native::{Receiver, Sender};
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{collections::HashMap, env, sync::Arc, time::Duration};
|
use std::{collections::HashMap, env, sync::Arc, time::Duration};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
|
|
@ -18,6 +16,8 @@ use tokio::{
|
||||||
task::JoinHandle,
|
task::JoinHandle,
|
||||||
time::{Instant, sleep},
|
time::{Instant, sleep},
|
||||||
};
|
};
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
||||||
|
use ttp_native::{Receiver, Sender};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
@ -64,6 +64,7 @@ pub enum ConnectionState {
|
||||||
Connected { identified: bool },
|
Connected { identified: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
impl ConnectionState {
|
impl ConnectionState {
|
||||||
pub fn is_connected(&self) -> bool {
|
pub fn is_connected(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
|
|
@ -72,6 +73,7 @@ impl ConnectionState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn is_identified(&self) -> bool {
|
pub fn is_identified(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ConnectionState::Connected { identified: true } => true,
|
ConnectionState::Connected { identified: true } => true,
|
||||||
|
|
@ -83,6 +85,7 @@ impl ConnectionState {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Omega Connection (Client-side with auto-reconnect)
|
// Omega Connection (Client-side with auto-reconnect)
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct OmegaConnection {
|
pub struct OmegaConnection {
|
||||||
state: Arc<RwLock<ConnectionState>>,
|
state: Arc<RwLock<ConnectionState>>,
|
||||||
sender: Arc<RwLock<Option<Arc<Sender>>>>,
|
sender: Arc<RwLock<Option<Arc<Sender>>>>,
|
||||||
|
|
@ -153,6 +156,7 @@ impl OmegaConnection {
|
||||||
*self.connection_loop_handle.lock().await = Some(handle);
|
*self.connection_loop_handle.lock().await = Some(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn stop(&self) {
|
pub async fn stop(&self) {
|
||||||
// Disable reconnection
|
// Disable reconnection
|
||||||
*self.reconnect_on_close.write().await = false;
|
*self.reconnect_on_close.write().await = false;
|
||||||
|
|
@ -239,7 +243,7 @@ impl OmegaConnection {
|
||||||
|
|
||||||
let addr_str = format!("https://{}:{}", self.host, self.port);
|
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
|
.await
|
||||||
.map_err(|e| format!("Connection failed: {}", e))?;
|
.map_err(|e| format!("Connection failed: {}", e))?;
|
||||||
|
|
||||||
|
|
@ -444,7 +448,7 @@ impl OmegaConnection {
|
||||||
async fn read_loop(
|
async fn read_loop(
|
||||||
self: Arc<Self>,
|
self: Arc<Self>,
|
||||||
receiver: &mut Receiver,
|
receiver: &mut Receiver,
|
||||||
sender_handle: Arc<epsilon_native::ConnectionHandle>,
|
sender_handle: Arc<ttp_native::ConnectionHandle>,
|
||||||
) {
|
) {
|
||||||
// Monitor both receiver and sender handle for close
|
// Monitor both receiver and sender handle for close
|
||||||
let mut close_rx = sender_handle.subscribe_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 {
|
pub async fn is_connected(&self) -> bool {
|
||||||
self.state.read().await.is_connected()
|
self.state.read().await.is_connected()
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn is_identified(&self) -> bool {
|
pub async fn is_identified(&self) -> bool {
|
||||||
self.state.read().await.is_identified()
|
self.state.read().await.is_identified()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn close_iota(iota_id: i64) {
|
pub async fn close_iota(iota_id: i64) {
|
||||||
let cv = CommunicationValue::new(CommunicationType::iota_disconnected)
|
let cv = CommunicationValue::new(CommunicationType::iota_disconnected)
|
||||||
.add_data(DataTypes::iota_id, DataValue::Number(iota_id));
|
.add_data(DataTypes::iota_id, DataValue::Number(iota_id));
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, rand_u32};
|
||||||
|
|
||||||
use crate::omega::omega_connection::OmegaConnection;
|
use crate::omega::omega_connection::OmegaConnection;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ use crate::rho::{rho_connection::RhoConnection, rho_manager};
|
||||||
use crate::util::logger::PrintType;
|
use crate::util::logger::PrintType;
|
||||||
use crate::{data::user::UserStatus, omega::omega_connection::OmegaConnection};
|
use crate::{data::user::UserStatus, omega::omega_connection::OmegaConnection};
|
||||||
use crate::{log_cv_in, log_cv_out, log_out};
|
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::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
||||||
|
use ttp_native::{Receiver, Sender};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
pub struct ClientConnection {
|
pub struct ClientConnection {
|
||||||
|
|
@ -455,6 +455,7 @@ impl ClientConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the connection
|
/// Close the connection
|
||||||
|
#[allow(dead_code)]
|
||||||
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 {
|
||||||
|
|
@ -470,12 +471,14 @@ impl ClientConnection {
|
||||||
let mut interested_guard = self.interested_users.write().await;
|
let mut interested_guard = self.interested_users.write().await;
|
||||||
*interested_guard = interested_ids;
|
*interested_guard = interested_ids;
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
|
pub async fn get_interested_users(self: Arc<Self>) -> Vec<i64> {
|
||||||
let interested_guard = self.interested_users.read().await;
|
let interested_guard = self.interested_users.read().await;
|
||||||
interested_guard.clone()
|
interested_guard.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if interested in a user and send notification
|
/// Check if interested in a user and send notification
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
|
pub async fn are_you_interested(self: Arc<Self>, user_id: i64) {
|
||||||
let interested_guard = self.clone().get_interested_users().await;
|
let interested_guard = self.clone().get_interested_users().await;
|
||||||
if interested_guard.contains(&user_id) {
|
if interested_guard.contains(&user_id) {
|
||||||
|
|
@ -488,6 +491,7 @@ impl ClientConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle connection close
|
/// Handle connection close
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn handle_close(&self) {
|
pub async fn handle_close(&self) {
|
||||||
let user_id = self.get_user_id().await;
|
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 {
|
if let Some(rho_conn) = rho_manager::get_rho_con_for_user(user_id as i64).await {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
|
||||||
use epsilon_native::{Receiver, Sender};
|
|
||||||
use rand::{Rng, distributions::Alphanumeric};
|
use rand::{Rng, distributions::Alphanumeric};
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
||||||
|
use ttp_native::{Receiver, Sender};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
anonymous_clients::anonymous_client_connection::AnonymousClientConnection,
|
anonymous_clients::anonymous_client_connection::AnonymousClientConnection,
|
||||||
|
|
@ -20,6 +20,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub enum ConnectionKind {
|
pub enum ConnectionKind {
|
||||||
Client,
|
Client,
|
||||||
Iota,
|
Iota,
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,6 @@ use crate::omega::omega_connection::get_omega_connection;
|
||||||
use crate::rho::connection::GeneralConnection;
|
use crate::rho::connection::GeneralConnection;
|
||||||
use crate::util::logger::PrintType;
|
use crate::util::logger::PrintType;
|
||||||
use dashmap::DashMap;
|
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::BTreeMap;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
|
@ -21,11 +15,18 @@ use std::{
|
||||||
};
|
};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tokio::sync::mpsc;
|
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 x448::PublicKey;
|
||||||
|
|
||||||
use super::{rho_connection::RhoConnection, rho_manager};
|
use super::{rho_connection::RhoConnection, rho_manager};
|
||||||
use crate::omega::omega_connection::OmegaConnection;
|
use crate::omega::omega_connection::OmegaConnection;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct IotaConnection {
|
pub struct IotaConnection {
|
||||||
pub iota_id: u64,
|
pub iota_id: u64,
|
||||||
pub sender: Arc<Sender>,
|
pub sender: Arc<Sender>,
|
||||||
|
|
@ -72,6 +73,7 @@ impl IotaConnection {
|
||||||
self.iota_id
|
self.iota_id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_public_key(&self) -> Option<PublicKey> {
|
pub async fn get_public_key(&self) -> Option<PublicKey> {
|
||||||
if let Some(public_key) = self.pub_key.read().await.clone() {
|
if let Some(public_key) = self.pub_key.read().await.clone() {
|
||||||
PublicKey::from_bytes(&public_key)
|
PublicKey::from_bytes(&public_key)
|
||||||
|
|
@ -163,11 +165,13 @@ impl IotaConnection {
|
||||||
self.forward_to_client(cv).await;
|
self.forward_to_client(cv).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
async fn send_error_response(&self, message_id: u32, error_type: CommunicationType) {
|
async fn send_error_response(&self, message_id: u32, error_type: CommunicationType) {
|
||||||
let error = CommunicationValue::new(error_type).with_id(message_id);
|
let error = CommunicationValue::new(error_type).with_id(message_id);
|
||||||
self.send_message(&error).await;
|
self.send_message(&error).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
async fn close(&self) {
|
async fn close(&self) {
|
||||||
let _ = self.sender.close();
|
let _ = self.sender.close();
|
||||||
}
|
}
|
||||||
|
|
@ -346,12 +350,14 @@ impl IotaConnection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn handle_close(&self) {
|
pub async fn handle_close(&self) {
|
||||||
if let Some(rho_conn) = self.get_rho_connection().await {
|
if let Some(rho_conn) = self.get_rho_connection().await {
|
||||||
rho_conn.close_iota_connection().await;
|
rho_conn.close_iota_connection().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn await_response(
|
pub async fn await_response(
|
||||||
self: Arc<IotaConnection>,
|
self: Arc<IotaConnection>,
|
||||||
cv: &CommunicationValue,
|
cv: &CommunicationValue,
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ use super::{client_connection::ClientConnection, iota_connection::IotaConnection
|
||||||
|
|
||||||
use crate::data::user::UserStatus;
|
use crate::data::user::UserStatus;
|
||||||
use crate::omega::omega_connection::OmegaConnection;
|
use crate::omega::omega_connection::OmegaConnection;
|
||||||
use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
use ttp_core::{CommunicationType, CommunicationValue, DataTypes, DataValue};
|
||||||
|
|
||||||
pub struct RhoConnection {
|
pub struct RhoConnection {
|
||||||
iota_connection: Arc<IotaConnection>,
|
iota_connection: Arc<IotaConnection>,
|
||||||
|
|
@ -58,6 +58,7 @@ impl RhoConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a client connection
|
/// Add a client connection
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn add_client_connection(&self, connection: Arc<ClientConnection>) {
|
pub async fn add_client_connection(&self, connection: Arc<ClientConnection>) {
|
||||||
let notification = CommunicationValue::new(CommunicationType::client_connected).add_data(
|
let notification = CommunicationValue::new(CommunicationType::client_connected).add_data(
|
||||||
DataTypes::user_id,
|
DataTypes::user_id,
|
||||||
|
|
@ -145,6 +146,7 @@ impl RhoConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if clients are interested in a user
|
/// Check if clients are interested in a user
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn are_they_interested(&self, user_id: i64) {
|
pub async fn are_they_interested(&self, user_id: i64) {
|
||||||
let connections = self.client_connections.read().await;
|
let connections = self.client_connections.read().await;
|
||||||
for connection in connections.iter() {
|
for connection in connections.iter() {
|
||||||
|
|
@ -166,11 +168,13 @@ impl RhoConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this RhoConnection contains a specific user ID
|
/// Check if this RhoConnection contains a specific user ID
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn contains_user(&self, user_id: &i64) -> bool {
|
pub fn contains_user(&self, user_id: &i64) -> bool {
|
||||||
self.user_ids.contains(user_id)
|
self.user_ids.contains(user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get count of active client connections
|
/// Get count of active client connections
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn client_count(&self) -> usize {
|
pub async fn client_count(&self) -> usize {
|
||||||
let connections = self.client_connections.read().await;
|
let connections = self.client_connections.read().await;
|
||||||
connections.len()
|
connections.len()
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ pub async fn get_rho_con_for_user(user_id: i64) -> Option<Arc<RhoConnection>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn contains_iota(iota_id: i64) -> bool {
|
pub async fn contains_iota(iota_id: i64) -> bool {
|
||||||
let connections = RHO_CONNECTIONS.read().await;
|
let connections = RHO_CONNECTIONS.read().await;
|
||||||
connections.contains_key(&iota_id)
|
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
|
/// Get a RhoConnection by Iota ID directly
|
||||||
|
#[allow(dead_code)]
|
||||||
pub async fn get_rho_by_iota(iota_id: i64) -> Option<Arc<RhoConnection>> {
|
pub async fn get_rho_by_iota(iota_id: i64) -> Option<Arc<RhoConnection>> {
|
||||||
let connections = RHO_CONNECTIONS.read().await;
|
let connections = RHO_CONNECTIONS.read().await;
|
||||||
connections.get(&iota_id).map(Arc::clone)
|
connections.get(&iota_id).map(Arc::clone)
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@ use crate::{
|
||||||
rho::connection::GeneralConnection,
|
rho::connection::GeneralConnection,
|
||||||
util::{file_util::load_file_vec, logger::PrintType},
|
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>> {
|
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 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 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);
|
log!(0, PrintType::General, "Server listening on port {}", port);
|
||||||
|
|
||||||
while let Some((sender, receiver)) = host.next().await {
|
while let Some((sender, receiver)) = host.next().await {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
|
||||||
use x448::{PublicKey, Secret, SharedSecret};
|
use x448::{PublicKey, Secret, SharedSecret};
|
||||||
|
|
||||||
/// Errors for crypto operations
|
/// Errors for crypto operations
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CryptoError {
|
pub enum CryptoError {
|
||||||
Base64Decode(base64::DecodeError),
|
Base64Decode(base64::DecodeError),
|
||||||
|
|
@ -23,11 +24,13 @@ impl From<base64::DecodeError> for CryptoError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct KeyPair {
|
pub struct KeyPair {
|
||||||
pub secret: Secret,
|
pub secret: Secret,
|
||||||
pub public: PublicKey,
|
pub public: PublicKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn generate_keypair() -> KeyPair {
|
pub fn generate_keypair() -> KeyPair {
|
||||||
let mut buf = [0u8; 56];
|
let mut buf = [0u8; 56];
|
||||||
let mut rng = OsRng;
|
let mut rng = OsRng;
|
||||||
|
|
@ -64,6 +67,7 @@ fn derive_aes_key(shared: &SharedSecret) -> [u8; 32] {
|
||||||
key
|
key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn encrypt_b64(
|
pub fn encrypt_b64(
|
||||||
base64_secret: &str,
|
base64_secret: &str,
|
||||||
base64_peer_pub: &str,
|
base64_peer_pub: &str,
|
||||||
|
|
@ -131,12 +135,14 @@ pub fn decrypt(
|
||||||
Ok(plaintext)
|
Ok(plaintext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn hash_it(input: &str) -> Vec<u8> {
|
pub fn hash_it(input: &str) -> Vec<u8> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(input.as_bytes());
|
hasher.update(input.as_bytes());
|
||||||
hasher.finalize().to_vec()
|
hasher.finalize().to_vec()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn hex_hash(input: &str) -> String {
|
pub fn hex_hash(input: &str) -> String {
|
||||||
let digest = hash_it(input);
|
let digest = hash_it(input);
|
||||||
digest.iter().map(|b| format!("{:02x}", b)).collect()
|
digest.iter().map(|b| format!("{:02x}", b)).collect()
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use sha2::{Digest, Sha256};
|
||||||
use x448::{PublicKey, Secret};
|
use x448::{PublicKey, Secret};
|
||||||
|
|
||||||
// --- Custom Errors ---
|
// --- Custom Errors ---
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SecurePayloadError {
|
pub enum SecurePayloadError {
|
||||||
InvalidBase64,
|
InvalidBase64,
|
||||||
|
|
@ -18,6 +19,7 @@ pub enum SecurePayloadError {
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Data Format Enum ---
|
// --- Data Format Enum ---
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum DataFormat {
|
pub enum DataFormat {
|
||||||
Raw,
|
Raw,
|
||||||
|
|
@ -66,6 +68,7 @@ impl SecurePayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper to get the public key associated with this instance's private key.
|
/// Helper to get the public key associated with this instance's private key.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_public_key(&self) -> [u8; 56] {
|
pub fn get_public_key(&self) -> [u8; 56] {
|
||||||
*PublicKey::from(&self.private_key).as_bytes()
|
*PublicKey::from(&self.private_key).as_bytes()
|
||||||
}
|
}
|
||||||
|
|
@ -80,11 +83,13 @@ impl SecurePayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Access raw bytes directly
|
/// Access raw bytes directly
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_bytes(&self) -> &[u8] {
|
pub fn get_bytes(&self) -> &[u8] {
|
||||||
&self.inner_data
|
&self.inner_data
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the SHA-256 Hash of the data in the requested format
|
/// Returns the SHA-256 Hash of the data in the requested format
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn get_hash(&self, format: DataFormat) -> String {
|
pub fn get_hash(&self, format: DataFormat) -> String {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&self.inner_data);
|
hasher.update(&self.inner_data);
|
||||||
|
|
@ -134,6 +139,7 @@ impl SecurePayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decrypts the held data providing the sender's public key manually.
|
/// Decrypts the held data providing the sender's public key manually.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn decrypt_to_format(
|
pub fn decrypt_to_format(
|
||||||
&self,
|
&self,
|
||||||
peer_public_key_bytes: &[u8; 56],
|
peer_public_key_bytes: &[u8; 56],
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ pub fn delete_user_directory(user_id: i64) {
|
||||||
let _ = delete_dir_recursive(&user_dir);
|
let _ = delete_dir_recursive(&user_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
|
pub fn load_file_buf(path: &str, name: &str) -> io::Result<BufReader<File>> {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
let file_path = dir.join(name);
|
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)?;
|
let file = File::open(&file_path)?;
|
||||||
Ok(BufReader::new(file))
|
Ok(BufReader::new(file))
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn has_file(path: &str, name: &str) -> bool {
|
pub fn has_file(path: &str, name: &str) -> bool {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
let file_path = dir.join(name);
|
let file_path = dir.join(name);
|
||||||
|
|
@ -77,6 +79,7 @@ pub fn has_file(path: &str, name: &str) -> bool {
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn has_dir(path: &str) -> bool {
|
pub fn has_dir(path: &str) -> bool {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
|
|
||||||
|
|
@ -87,6 +90,7 @@ pub fn has_dir(path: &str) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn load_file(path: &str, name: &str) -> String {
|
pub fn load_file(path: &str, name: &str) -> String {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
let file_path = dir.join(name);
|
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)
|
std::fs::read(file_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn save_file(path: &str, name: &str, value: &str) {
|
pub fn save_file(path: &str, name: &str, value: &str) {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
let file_path = dir.join(name);
|
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> {
|
pub fn get_children(path: &str) -> Vec<String> {
|
||||||
let dir = Path::new(&get_directory()).join(path);
|
let dir = Path::new(&get_directory()).join(path);
|
||||||
let mut children = Vec::new();
|
let mut children = Vec::new();
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,11 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ansi_term::Color;
|
use ansi_term::Color;
|
||||||
use epsilon_core::{CommunicationValue, DataTypes, DataValue};
|
use ttp_core::{CommunicationValue, DataTypes, DataValue};
|
||||||
|
|
||||||
static LOGGER: OnceLock<mpsc::Sender<LogMessage>> = OnceLock::new();
|
static LOGGER: OnceLock<mpsc::Sender<LogMessage>> = OnceLock::new();
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum PrintType {
|
pub enum PrintType {
|
||||||
Call,
|
Call,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue