diff --git a/src/data/communication.rs b/src/data/communication.rs index 2f8c689..7af1340 100644 --- a/src/data/communication.rs +++ b/src/data/communication.rs @@ -36,6 +36,8 @@ pub enum DataTypes { shared_secret, call_id, call_token, + untill, + enable, start_date, end_date, receiver_id, @@ -110,6 +112,8 @@ impl DataTypes { "sharedsecret" => DataTypes::shared_secret, "callid" => DataTypes::call_id, "calltoken" => DataTypes::call_token, + "untill" => DataTypes::untill, + "enable" => DataTypes::enable, "startdate" => DataTypes::start_date, "enddate" => DataTypes::end_date, "receiverid" => DataTypes::receiver_id, @@ -159,11 +163,14 @@ impl DataTypes { pub enum CommunicationType { error, error_invalid_user_id, + error_invalid_omikron_id, error_not_found, + error_not_authenticated, error_no_iota, error_invalid_challenge, error_invalid_secret, error_invalid_private_key, + error_invalid_public_key, error_no_user_id, error_no_call_id, error_invalid_call_id, @@ -210,6 +217,9 @@ pub enum CommunicationType { watch_stream, call_token, call_invite, + call_disconnect_user, + call_timeout_user, + call_set_anonymous_joining, end_call, function, update, @@ -223,14 +233,20 @@ impl CommunicationType { "watchstream" => CommunicationType::watch_stream, "calltoken" => CommunicationType::call_token, "callinvite" => CommunicationType::call_invite, + "calldisconnectuser" => CommunicationType::call_disconnect_user, + "calltimeoutuser" => CommunicationType::call_timeout_user, + "callsetanonymousjoining" => CommunicationType::call_set_anonymous_joining, "endcall" => CommunicationType::end_call, "function" => CommunicationType::function, "update" => CommunicationType::update, "createuser" => CommunicationType::create_user, "errorinvaliduserid" => CommunicationType::error_invalid_user_id, + "errorinvalidomikronid" => CommunicationType::error_invalid_omikron_id, "errornotfound" => CommunicationType::error_not_found, + "errornotauthenticated" => CommunicationType::error_not_authenticated, "errornoiota" => CommunicationType::error_no_iota, "errorinvalidchallenge" => CommunicationType::error_invalid_challenge, + "errorinvalidpublickey" => CommunicationType::error_invalid_public_key, "errorinvalidsecret" => CommunicationType::error_invalid_secret, "errorinvalidprivatekey" => CommunicationType::error_invalid_private_key, "errornouserid" => CommunicationType::error_no_user_id, @@ -243,7 +259,7 @@ impl CommunicationType { "message" => CommunicationType::message, "messagesend" => CommunicationType::message_send, "messagelive" => CommunicationType::message_live, - "messageother_iota" => CommunicationType::message_other_iota, + "messageotheriota" => CommunicationType::message_other_iota, "messagechunk" => CommunicationType::message_chunk, "messagesget" => CommunicationType::messages_get, "changeconfirm" => CommunicationType::change_confirm, diff --git a/src/main.rs b/src/main.rs index 815932d..795407d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ async fn main() { JsonValue::Number(Number::from( SystemTime::now() .duration_since(UNIX_EPOCH) - .unwrap() + .unwrap_or(Duration::from_millis(0)) .as_millis() as i64, )), ); @@ -126,7 +126,7 @@ async fn main() { let iface: NetworkInterface = iface; if iface.ips.len() > 0 { let ipsv = format!("{}", iface.ips[0]); - let ips: &str = ipsv.split('/').next().unwrap(); + let ips: &str = ipsv.split('/').next().unwrap_or(""); if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") { ip = ips.to_string(); } diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 4529155..5f95029 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -40,8 +40,8 @@ pub struct OmikronConnection { pub user_id: Arc>, pub(crate) writer: Arc + Send + Unpin>>>>, - waiting: Arc>>>, // waiting for responses - pingpong: Arc>>>, // ping-pong handler + waiting: Arc>>>, + pingpong: Arc>>>, pub last_ping: Arc>, pub message_send_times: Arc>>, pub is_connected: Arc>, @@ -346,17 +346,20 @@ impl OmikronConnection { .unwrap_or(&JsonValue::Null) .as_i64() .unwrap_or(0); + let now_ms = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() as u128; + chat_files::add_message( - SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as u128, + now_ms, true, my_id, other_id, &*cv.get_data(DataTypes::content).unwrap().to_string(), ); - let ack = CommunicationValue::new(CommunicationType::message) + + let ack = CommunicationValue::new(CommunicationType::success) .with_id(cv.get_id()) .with_receiver(my_id); Self::send_message_static( @@ -365,7 +368,30 @@ impl OmikronConnection { ack.to_json().to_string(), ) .await; - let forward = CommunicationValue::forward_to_other_iota(&mut cv); + + let forward = + CommunicationValue::new(CommunicationType::message_other_iota) + .with_id(cv.get_id()) + .with_receiver(other_id) + .add_data( + DataTypes::receiver_id, + JsonValue::Number(Number::from(other_id)), + ) + .with_sender(my_id) + .add_data( + DataTypes::send_time, + JsonValue::String(now_ms.to_string()), + ) + .add_data( + DataTypes::sender_id, + JsonValue::Number(Number::from(my_id)), + ) + .add_data( + DataTypes::content, + JsonValue::String( + cv.get_data(DataTypes::content).unwrap().to_string(), + ), + ); Self::send_message_static( &writer.clone(), is_connected,