Merge branch 'main' of ssh://git.methanium.net/tensamin/omikron
This commit is contained in:
commit
4b371463ea
4 changed files with 44 additions and 13 deletions
|
|
@ -1 +1,6 @@
|
||||||
# ⚠️ Moved to [git.methanium.net](https://git.methanium.net/tensamin/omikron) ⚠️
|
# Omikron
|
||||||
|
The Omikron is a reverse proxy and relay server for Tensamin.
|
||||||
|
It's primary purpose is to connect you're client to your Iota & hide your IP and service usage.
|
||||||
|
The Omikron also host Voice-Calls.
|
||||||
|
|
||||||
|
The Omikron is only used when the Iota is in Centralized and Hybrid mode, or when the Client uses the Tensamin Client with default configuration.
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,12 @@ pub async fn get_anonymous_user(user_id: u64) -> Option<Arc<AnonymousClientConne
|
||||||
pub async fn get_anonymous_user_by_name(
|
pub async fn get_anonymous_user_by_name(
|
||||||
username: String,
|
username: String,
|
||||||
) -> Option<Arc<AnonymousClientConnection>> {
|
) -> Option<Arc<AnonymousClientConnection>> {
|
||||||
for user_conn in ANONYMOUS_USERS
|
let users: Vec<_> = ANONYMOUS_USERS
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ref_multi| ref_multi.value().clone())
|
.map(|ref_multi| ref_multi.value().clone())
|
||||||
{
|
.collect();
|
||||||
|
|
||||||
|
for user_conn in users {
|
||||||
if user_conn.get_user_name().await == username {
|
if user_conn.get_user_name().await == username {
|
||||||
return Some(user_conn);
|
return Some(user_conn);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use uuid::Uuid;
|
||||||
|
|
||||||
pub struct ClientConnection {
|
pub struct ClientConnection {
|
||||||
pub user_id: u64,
|
pub user_id: u64,
|
||||||
|
pub session_id: u64,
|
||||||
|
|
||||||
pub sender: Arc<Sender>,
|
pub sender: Arc<Sender>,
|
||||||
pub receiver: Arc<Receiver>,
|
pub receiver: Arc<Receiver>,
|
||||||
|
|
@ -37,6 +38,7 @@ impl ClientConnection {
|
||||||
sender: general.sender.clone(),
|
sender: general.sender.clone(),
|
||||||
receiver: general.receiver.clone(),
|
receiver: general.receiver.clone(),
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
|
session_id: general.session_id.read().await.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn start(self: Arc<Self>) {
|
pub fn start(self: Arc<Self>) {
|
||||||
|
|
@ -573,6 +575,7 @@ impl Clone for ClientConnection {
|
||||||
sender: Arc::clone(&self.sender),
|
sender: Arc::clone(&self.sender),
|
||||||
receiver: Arc::clone(&self.receiver),
|
receiver: Arc::clone(&self.receiver),
|
||||||
user_id: self.user_id,
|
user_id: self.user_id,
|
||||||
|
session_id: self.session_id,
|
||||||
ping: Arc::clone(&self.ping),
|
ping: Arc::clone(&self.ping),
|
||||||
pub_key: Arc::clone(&self.pub_key),
|
pub_key: Arc::clone(&self.pub_key),
|
||||||
rho_connection: Arc::clone(&self.rho_connection),
|
rho_connection: Arc::clone(&self.rho_connection),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
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_core::{CommunicationType, CommunicationValue, DataTypes, DataValue, util::rand_u64};
|
||||||
use ttp_native::{Receiver, Sender};
|
use ttp_native::{Receiver, Sender};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -35,10 +35,12 @@ pub struct GeneralConnection {
|
||||||
identified: Arc<RwLock<bool>>,
|
identified: Arc<RwLock<bool>>,
|
||||||
challenged: Arc<RwLock<bool>>,
|
challenged: Arc<RwLock<bool>>,
|
||||||
challenge: Arc<RwLock<String>>,
|
challenge: Arc<RwLock<String>>,
|
||||||
|
challenge_cv_id: Arc<RwLock<u32>>,
|
||||||
|
|
||||||
connection_kind: Arc<RwLock<Option<ConnectionKind>>>,
|
connection_kind: Arc<RwLock<Option<ConnectionKind>>>,
|
||||||
pub rho_connection: Arc<RwLock<Option<Arc<RhoConnection>>>>,
|
pub rho_connection: Arc<RwLock<Option<Arc<RhoConnection>>>>,
|
||||||
id: Arc<RwLock<u64>>,
|
id: Arc<RwLock<u64>>,
|
||||||
|
pub session_id: Arc<RwLock<u64>>,
|
||||||
|
|
||||||
pub_key: Arc<RwLock<Option<Vec<u8>>>>,
|
pub_key: Arc<RwLock<Option<Vec<u8>>>>,
|
||||||
}
|
}
|
||||||
|
|
@ -50,9 +52,11 @@ impl GeneralConnection {
|
||||||
identified: Arc::new(RwLock::new(false)),
|
identified: Arc::new(RwLock::new(false)),
|
||||||
challenged: Arc::new(RwLock::new(false)),
|
challenged: Arc::new(RwLock::new(false)),
|
||||||
challenge: Arc::new(RwLock::new(String::new())),
|
challenge: Arc::new(RwLock::new(String::new())),
|
||||||
|
challenge_cv_id: Arc::new(RwLock::new(0)),
|
||||||
connection_kind: Arc::new(RwLock::new(None)),
|
connection_kind: Arc::new(RwLock::new(None)),
|
||||||
rho_connection: Arc::new(RwLock::new(None)),
|
rho_connection: Arc::new(RwLock::new(None)),
|
||||||
id: Arc::new(RwLock::new(0)),
|
id: Arc::new(RwLock::new(0)),
|
||||||
|
session_id: Arc::new(RwLock::new(0)),
|
||||||
pub_key: Arc::new(RwLock::new(None)),
|
pub_key: Arc::new(RwLock::new(None)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -183,6 +187,10 @@ impl GeneralConnection {
|
||||||
let _ = self.sender.send(&response).await;
|
let _ = self.sender.send(&response).await;
|
||||||
} else if let DataValue::Number(user_id) = cv.get_data(DataTypes::user_id) {
|
} else if let DataValue::Number(user_id) = cv.get_data(DataTypes::user_id) {
|
||||||
*self.id.write().await = *user_id as u64;
|
*self.id.write().await = *user_id as u64;
|
||||||
|
*self.session_id.write().await = match cv.get_data(DataTypes::session_id) {
|
||||||
|
DataValue::Number(s) => *s as u64,
|
||||||
|
_ => rand_u64(),
|
||||||
|
};
|
||||||
*self.connection_kind.write().await = Some(ConnectionKind::Client);
|
*self.connection_kind.write().await = Some(ConnectionKind::Client);
|
||||||
|
|
||||||
let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_user_data)
|
let get_pub_key_msg = CommunicationValue::new(CommunicationType::get_user_data)
|
||||||
|
|
@ -253,15 +261,7 @@ impl GeneralConnection {
|
||||||
|
|
||||||
if *response == expected {
|
if *response == expected {
|
||||||
*self.challenged.write().await = true;
|
*self.challenged.write().await = true;
|
||||||
|
*self.challenge_cv_id.write().await = cv.get_id();
|
||||||
let response = CommunicationValue::new(CommunicationType::identification_response)
|
|
||||||
.with_id(cv.get_id())
|
|
||||||
.add_data(DataTypes::accepted, DataValue::Bool(true));
|
|
||||||
|
|
||||||
log_cv_out!(response);
|
|
||||||
if let Err(_) = self.sender.send(&response).await {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log_err!(
|
log_err!(
|
||||||
id,
|
id,
|
||||||
|
|
@ -327,6 +327,27 @@ impl GeneralConnection {
|
||||||
if let Some(rho_conn) = rho {
|
if let Some(rho_conn) = rho {
|
||||||
rho_conn.bind_user_id(user_id).await;
|
rho_conn.bind_user_id(user_id).await;
|
||||||
rho_conn.add_client_connection(client.clone()).await;
|
rho_conn.add_client_connection(client.clone()).await;
|
||||||
|
|
||||||
|
let session_id = *self.session_id.read().await as i64;
|
||||||
|
let iota_msg = CommunicationValue::new(CommunicationType::client_connected)
|
||||||
|
.add_data(DataTypes::user_id, DataValue::Number(user_id))
|
||||||
|
.add_data(DataTypes::session_id, DataValue::Number(session_id));
|
||||||
|
|
||||||
|
if let Ok(resp) = rho_conn
|
||||||
|
.get_iota_connection()
|
||||||
|
.clone()
|
||||||
|
.await_response(&iota_msg, Some(Duration::from_secs(20)))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
let mut ident_resp =
|
||||||
|
CommunicationValue::new(CommunicationType::identification_response)
|
||||||
|
.with_id(*self.challenge_cv_id.read().await);
|
||||||
|
for (k, v) in resp.get_data_container() {
|
||||||
|
ident_resp = ident_resp.add_data(k.clone(), v.clone());
|
||||||
|
}
|
||||||
|
log_cv_out!(ident_resp);
|
||||||
|
let _ = self.sender.send(&ident_resp).await;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log_err!(
|
log_err!(
|
||||||
user_id,
|
user_id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue