This commit should have been Iota Auth...
This commit is contained in:
parent
1f878b9314
commit
9b949f8c6b
3 changed files with 53 additions and 11 deletions
|
|
@ -36,6 +36,8 @@ pub enum DataTypes {
|
||||||
shared_secret,
|
shared_secret,
|
||||||
call_id,
|
call_id,
|
||||||
call_token,
|
call_token,
|
||||||
|
untill,
|
||||||
|
enable,
|
||||||
start_date,
|
start_date,
|
||||||
end_date,
|
end_date,
|
||||||
receiver_id,
|
receiver_id,
|
||||||
|
|
@ -110,6 +112,8 @@ impl DataTypes {
|
||||||
"sharedsecret" => DataTypes::shared_secret,
|
"sharedsecret" => DataTypes::shared_secret,
|
||||||
"callid" => DataTypes::call_id,
|
"callid" => DataTypes::call_id,
|
||||||
"calltoken" => DataTypes::call_token,
|
"calltoken" => DataTypes::call_token,
|
||||||
|
"untill" => DataTypes::untill,
|
||||||
|
"enable" => DataTypes::enable,
|
||||||
"startdate" => DataTypes::start_date,
|
"startdate" => DataTypes::start_date,
|
||||||
"enddate" => DataTypes::end_date,
|
"enddate" => DataTypes::end_date,
|
||||||
"receiverid" => DataTypes::receiver_id,
|
"receiverid" => DataTypes::receiver_id,
|
||||||
|
|
@ -159,11 +163,14 @@ impl DataTypes {
|
||||||
pub enum CommunicationType {
|
pub enum CommunicationType {
|
||||||
error,
|
error,
|
||||||
error_invalid_user_id,
|
error_invalid_user_id,
|
||||||
|
error_invalid_omikron_id,
|
||||||
error_not_found,
|
error_not_found,
|
||||||
|
error_not_authenticated,
|
||||||
error_no_iota,
|
error_no_iota,
|
||||||
error_invalid_challenge,
|
error_invalid_challenge,
|
||||||
error_invalid_secret,
|
error_invalid_secret,
|
||||||
error_invalid_private_key,
|
error_invalid_private_key,
|
||||||
|
error_invalid_public_key,
|
||||||
error_no_user_id,
|
error_no_user_id,
|
||||||
error_no_call_id,
|
error_no_call_id,
|
||||||
error_invalid_call_id,
|
error_invalid_call_id,
|
||||||
|
|
@ -210,6 +217,9 @@ pub enum CommunicationType {
|
||||||
watch_stream,
|
watch_stream,
|
||||||
call_token,
|
call_token,
|
||||||
call_invite,
|
call_invite,
|
||||||
|
call_disconnect_user,
|
||||||
|
call_timeout_user,
|
||||||
|
call_set_anonymous_joining,
|
||||||
end_call,
|
end_call,
|
||||||
function,
|
function,
|
||||||
update,
|
update,
|
||||||
|
|
@ -223,14 +233,20 @@ impl CommunicationType {
|
||||||
"watchstream" => CommunicationType::watch_stream,
|
"watchstream" => CommunicationType::watch_stream,
|
||||||
"calltoken" => CommunicationType::call_token,
|
"calltoken" => CommunicationType::call_token,
|
||||||
"callinvite" => CommunicationType::call_invite,
|
"callinvite" => CommunicationType::call_invite,
|
||||||
|
"calldisconnectuser" => CommunicationType::call_disconnect_user,
|
||||||
|
"calltimeoutuser" => CommunicationType::call_timeout_user,
|
||||||
|
"callsetanonymousjoining" => CommunicationType::call_set_anonymous_joining,
|
||||||
"endcall" => CommunicationType::end_call,
|
"endcall" => CommunicationType::end_call,
|
||||||
"function" => CommunicationType::function,
|
"function" => CommunicationType::function,
|
||||||
"update" => CommunicationType::update,
|
"update" => CommunicationType::update,
|
||||||
"createuser" => CommunicationType::create_user,
|
"createuser" => CommunicationType::create_user,
|
||||||
"errorinvaliduserid" => CommunicationType::error_invalid_user_id,
|
"errorinvaliduserid" => CommunicationType::error_invalid_user_id,
|
||||||
|
"errorinvalidomikronid" => CommunicationType::error_invalid_omikron_id,
|
||||||
"errornotfound" => CommunicationType::error_not_found,
|
"errornotfound" => CommunicationType::error_not_found,
|
||||||
|
"errornotauthenticated" => CommunicationType::error_not_authenticated,
|
||||||
"errornoiota" => CommunicationType::error_no_iota,
|
"errornoiota" => CommunicationType::error_no_iota,
|
||||||
"errorinvalidchallenge" => CommunicationType::error_invalid_challenge,
|
"errorinvalidchallenge" => CommunicationType::error_invalid_challenge,
|
||||||
|
"errorinvalidpublickey" => CommunicationType::error_invalid_public_key,
|
||||||
"errorinvalidsecret" => CommunicationType::error_invalid_secret,
|
"errorinvalidsecret" => CommunicationType::error_invalid_secret,
|
||||||
"errorinvalidprivatekey" => CommunicationType::error_invalid_private_key,
|
"errorinvalidprivatekey" => CommunicationType::error_invalid_private_key,
|
||||||
"errornouserid" => CommunicationType::error_no_user_id,
|
"errornouserid" => CommunicationType::error_no_user_id,
|
||||||
|
|
@ -243,7 +259,7 @@ impl CommunicationType {
|
||||||
"message" => CommunicationType::message,
|
"message" => CommunicationType::message,
|
||||||
"messagesend" => CommunicationType::message_send,
|
"messagesend" => CommunicationType::message_send,
|
||||||
"messagelive" => CommunicationType::message_live,
|
"messagelive" => CommunicationType::message_live,
|
||||||
"messageother_iota" => CommunicationType::message_other_iota,
|
"messageotheriota" => CommunicationType::message_other_iota,
|
||||||
"messagechunk" => CommunicationType::message_chunk,
|
"messagechunk" => CommunicationType::message_chunk,
|
||||||
"messagesget" => CommunicationType::messages_get,
|
"messagesget" => CommunicationType::messages_get,
|
||||||
"changeconfirm" => CommunicationType::change_confirm,
|
"changeconfirm" => CommunicationType::change_confirm,
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ async fn main() {
|
||||||
JsonValue::Number(Number::from(
|
JsonValue::Number(Number::from(
|
||||||
SystemTime::now()
|
SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap_or(Duration::from_millis(0))
|
||||||
.as_millis() as i64,
|
.as_millis() as i64,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
@ -126,7 +126,7 @@ async fn main() {
|
||||||
let iface: NetworkInterface = iface;
|
let iface: NetworkInterface = iface;
|
||||||
if iface.ips.len() > 0 {
|
if iface.ips.len() > 0 {
|
||||||
let ipsv = format!("{}", iface.ips[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.") {
|
if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") {
|
||||||
ip = ips.to_string();
|
ip = ips.to_string();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ pub struct OmikronConnection {
|
||||||
pub user_id: Arc<RwLock<i64>>,
|
pub user_id: Arc<RwLock<i64>>,
|
||||||
pub(crate) writer:
|
pub(crate) writer:
|
||||||
Arc<Mutex<Option<Box<dyn Sink<Message, Error = tungstenite::Error> + Send + Unpin>>>>,
|
Arc<Mutex<Option<Box<dyn Sink<Message, Error = tungstenite::Error> + Send + Unpin>>>>,
|
||||||
waiting: Arc<Mutex<HashMap<Uuid, Box<dyn Fn(CommunicationValue) + Send + Sync>>>>, // waiting for responses
|
waiting: Arc<Mutex<HashMap<Uuid, Box<dyn Fn(CommunicationValue) + Send + Sync>>>>,
|
||||||
pingpong: Arc<Mutex<Option<tokio::task::JoinHandle<()>>>>, // ping-pong handler
|
pingpong: Arc<Mutex<Option<tokio::task::JoinHandle<()>>>>,
|
||||||
pub last_ping: Arc<Mutex<i64>>,
|
pub last_ping: Arc<Mutex<i64>>,
|
||||||
pub message_send_times: Arc<Mutex<HashMap<Uuid, Instant>>>,
|
pub message_send_times: Arc<Mutex<HashMap<Uuid, Instant>>>,
|
||||||
pub is_connected: Arc<Mutex<bool>>,
|
pub is_connected: Arc<Mutex<bool>>,
|
||||||
|
|
@ -346,17 +346,20 @@ impl OmikronConnection {
|
||||||
.unwrap_or(&JsonValue::Null)
|
.unwrap_or(&JsonValue::Null)
|
||||||
.as_i64()
|
.as_i64()
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
let now_ms = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_millis() as u128;
|
||||||
|
|
||||||
chat_files::add_message(
|
chat_files::add_message(
|
||||||
SystemTime::now()
|
now_ms,
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_millis() as u128,
|
|
||||||
true,
|
true,
|
||||||
my_id,
|
my_id,
|
||||||
other_id,
|
other_id,
|
||||||
&*cv.get_data(DataTypes::content).unwrap().to_string(),
|
&*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_id(cv.get_id())
|
||||||
.with_receiver(my_id);
|
.with_receiver(my_id);
|
||||||
Self::send_message_static(
|
Self::send_message_static(
|
||||||
|
|
@ -365,7 +368,30 @@ impl OmikronConnection {
|
||||||
ack.to_json().to_string(),
|
ack.to_json().to_string(),
|
||||||
)
|
)
|
||||||
.await;
|
.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(
|
Self::send_message_static(
|
||||||
&writer.clone(),
|
&writer.clone(),
|
||||||
is_connected,
|
is_connected,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue