[Fix] Omikron & Omega Connection
This commit is contained in:
parent
7532235ab0
commit
41d4014ca5
8 changed files with 30 additions and 47 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -1090,7 +1090,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epsilon-core"
|
name = "epsilon-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/Tensamin/Epsilon.git#44e3a3ec0ee6ac4c00f8cfb7c20c3299c7ae89c5"
|
source = "git+https://github.com/Tensamin/Epsilon.git#a175705a731a124bca7507ea897d29f536bb15dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"quinn",
|
"quinn",
|
||||||
|
|
@ -1102,7 +1102,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epsilon-native"
|
name = "epsilon-native"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/Tensamin/Epsilon.git#44e3a3ec0ee6ac4c00f8cfb7c20c3299c7ae89c5"
|
source = "git+https://github.com/Tensamin/Epsilon.git#a175705a731a124bca7507ea897d29f536bb15dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,9 @@ impl AnonymousClientConnection {
|
||||||
pub fn start(self: Arc<Self>) {
|
pub fn start(self: Arc<Self>) {
|
||||||
let self_clone = self.clone();
|
let self_clone = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Ok(cv) = self_clone.receiver.receive().await {
|
/*while let Ok(cv) = self_clone.receiver.receive().await {
|
||||||
self_clone.clone().handle_message(cv).await;
|
self_clone.clone().handle_message(cv).await;
|
||||||
}
|
}*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ impl OmegaConnection {
|
||||||
|
|
||||||
let addr_str = format!("https://{}:{}", self.host, self.port);
|
let addr_str = format!("https://{}:{}", self.host, self.port);
|
||||||
|
|
||||||
let (sender, receiver) = epsilon_native::client::connect(&addr_str, None)
|
let (sender, mut receiver) = epsilon_native::client::connect(&addr_str, None)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Connection failed: {}", e))?;
|
.map_err(|e| format!("Connection failed: {}", e))?;
|
||||||
|
|
||||||
|
|
@ -231,7 +231,7 @@ impl OmegaConnection {
|
||||||
// Start read loop
|
// Start read loop
|
||||||
let read_self = self.clone();
|
let read_self = self.clone();
|
||||||
let read_handle = tokio::spawn(async move {
|
let read_handle = tokio::spawn(async move {
|
||||||
read_self.read_loop(receiver).await;
|
read_self.read_loop(&mut receiver).await;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send identification
|
// Send identification
|
||||||
|
|
@ -275,7 +275,7 @@ impl OmegaConnection {
|
||||||
|
|
||||||
let identify_msg = CommunicationValue::new(CommunicationType::identification)
|
let identify_msg = CommunicationValue::new(CommunicationType::identification)
|
||||||
.with_id(id)
|
.with_id(id)
|
||||||
.add_data(DataTypes::omikron, DataValue::Number(omikron_id));
|
.add_data(DataTypes::omikron_id, DataValue::Number(omikron_id));
|
||||||
|
|
||||||
WAITING_TASKS.insert(
|
WAITING_TASKS.insert(
|
||||||
id,
|
id,
|
||||||
|
|
@ -404,17 +404,17 @@ impl OmegaConnection {
|
||||||
// Read Loop & Heartbeat
|
// Read Loop & Heartbeat
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
async fn read_loop(self: Arc<Self>, receiver: Receiver) {
|
async fn read_loop(self: Arc<Self>, receiver: &mut Receiver) {
|
||||||
loop {
|
loop {
|
||||||
match receiver.receive().await {
|
match receiver.receive().await {
|
||||||
Ok(cv) => {
|
Ok(cv) => {
|
||||||
|
log_cv_in!(&cv);
|
||||||
|
|
||||||
if cv.is_type(CommunicationType::pong) || cv.is_type(CommunicationType::ping) {
|
if cv.is_type(CommunicationType::pong) || cv.is_type(CommunicationType::ping) {
|
||||||
self.handle_pong(&cv).await;
|
self.handle_pong(&cv).await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_cv_in!(&cv);
|
|
||||||
|
|
||||||
let msg_id = cv.get_id();
|
let msg_id = cv.get_id();
|
||||||
if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) {
|
if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) {
|
||||||
if (task.task)(self.clone(), cv) {
|
if (task.task)(self.clone(), cv) {
|
||||||
|
|
@ -474,9 +474,7 @@ impl OmegaConnection {
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
pub async fn send_message(&self, cv: &CommunicationValue) {
|
pub async fn send_message(&self, cv: &CommunicationValue) {
|
||||||
if !cv.is_type(CommunicationType::ping) {
|
log_cv_out!(cv);
|
||||||
log_cv_out!(cv);
|
|
||||||
}
|
|
||||||
|
|
||||||
let sender_guard = self.sender.read().await;
|
let sender_guard = self.sender.read().await;
|
||||||
if let Some(sender) = sender_guard.as_ref() {
|
if let Some(sender) = sender_guard.as_ref() {
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,9 @@ impl ClientConnection {
|
||||||
pub fn start(self: Arc<Self>) {
|
pub fn start(self: Arc<Self>) {
|
||||||
let self_clone = self.clone();
|
let self_clone = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Ok(cv) = self_clone.receiver.receive().await {
|
/*while let Ok(cv) = self_clone.receiver.receive().await {
|
||||||
self_clone.clone().handle_message(cv).await;
|
self_clone.clone().handle_message(cv).await;
|
||||||
}
|
}*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ impl GeneralConnection {
|
||||||
impl GeneralConnection {
|
impl GeneralConnection {
|
||||||
pub async fn handle(self: Arc<Self>) {
|
pub async fn handle(self: Arc<Self>) {
|
||||||
loop {
|
loop {
|
||||||
let cv = match self.receiver.receive().await {
|
/*let cv = match self.receiver.receive().await {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => break,
|
Err(_) => break,
|
||||||
};
|
};
|
||||||
|
|
@ -70,7 +70,7 @@ impl GeneralConnection {
|
||||||
|
|
||||||
if self.migrate().await {
|
if self.migrate().await {
|
||||||
break;
|
break;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async fn handle_identification(self: &Arc<Self>, cv: CommunicationValue) {
|
async fn handle_identification(self: &Arc<Self>, cv: CommunicationValue) {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ use epsilon_core::DataTypes;
|
||||||
use epsilon_core::DataValue;
|
use epsilon_core::DataValue;
|
||||||
use epsilon_native::Receiver;
|
use epsilon_native::Receiver;
|
||||||
use epsilon_native::Sender;
|
use epsilon_native::Sender;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
sync::{Arc, Weak},
|
sync::{Arc, Weak},
|
||||||
|
|
@ -53,9 +54,9 @@ impl IotaConnection {
|
||||||
pub fn start(self: Arc<Self>) {
|
pub fn start(self: Arc<Self>) {
|
||||||
let self_clone = self.clone();
|
let self_clone = self.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Ok(cv) = self_clone.receiver.receive().await {
|
/*while let Ok(cv) = self_clone.receiver.receive().await {
|
||||||
self_clone.clone().handle_message(cv).await;
|
self_clone.clone().handle_message(cv).await;
|
||||||
}
|
}*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,7 +244,7 @@ impl IotaConnection {
|
||||||
let admin = call_self.has_admin();
|
let admin = call_self.has_admin();
|
||||||
|
|
||||||
// Build call container
|
// Build call container
|
||||||
let mut call_map: HashMap<DataTypes, DataValue> = HashMap::new();
|
let mut call_map: BTreeMap<DataTypes, DataValue> = BTreeMap::new();
|
||||||
|
|
||||||
call_map.insert(DataTypes::call_id, DataValue::Str(call.call_id.to_string()));
|
call_map.insert(DataTypes::call_id, DataValue::Str(call.call_id.to_string()));
|
||||||
|
|
||||||
|
|
@ -278,7 +279,7 @@ impl IotaConnection {
|
||||||
if let DataValue::Array(users) = cv.get_data(DataTypes::user_ids) {
|
if let DataValue::Array(users) = cv.get_data(DataTypes::user_ids) {
|
||||||
for user_val in users {
|
for user_val in users {
|
||||||
if let DataValue::Container(entries) = user_val {
|
if let DataValue::Container(entries) = user_val {
|
||||||
let mut user_map: HashMap<DataTypes, DataValue> =
|
let mut user_map: BTreeMap<DataTypes, DataValue> =
|
||||||
entries.iter().cloned().collect();
|
entries.iter().cloned().collect();
|
||||||
|
|
||||||
// extract user_id
|
// extract user_id
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,17 @@
|
||||||
use crate::{log, rho::connection::GeneralConnection, util::file_util::load_file_vec};
|
use crate::{
|
||||||
|
log,
|
||||||
|
rho::connection::GeneralConnection,
|
||||||
|
util::{file_util::load_file_vec, logger::PrintType},
|
||||||
|
};
|
||||||
use epsilon_native::Host;
|
use epsilon_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")
|
let cert_pem = load_file_vec("certs", "cert.pem").expect("Error loading Pemfile");
|
||||||
.map_err(|e| format!("Failed to load certificate: {}", e))?;
|
|
||||||
let key_pem = load_file_vec("certs", "key.pem")
|
|
||||||
.map_err(|e| format!("Failed to load private key: {}", e))?;
|
|
||||||
|
|
||||||
<<<<<<< HEAD
|
let key_pem = load_file_vec("certs", "key.pem").expect("Error loading Keyfile");
|
||||||
let key_pem = load_file_vec("certs", "key.pem").unwrap();
|
|
||||||
let cert_pem = load_file_vec("certs", "cert.pem").unwrap();
|
|
||||||
|
|
||||||
let mut host: Host = epsilon_native::host(port, cert_pem, key_pem).await.unwrap();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
while let Some((sender, receiver)) = host.next().await {
|
|
||||||
tokio::spawn(async move {
|
|
||||||
GeneralConnection::new(sender, receiver).handle().await;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
=======
|
|
||||||
let mut host: Host = epsilon_native::host(port, cert_pem, key_pem).await?;
|
let mut host: Host = epsilon_native::host(port, cert_pem, key_pem).await?;
|
||||||
log!(
|
log!(0, PrintType::General, "Server listening on port {}", port);
|
||||||
0,
|
|
||||||
crate::util::logger::PrintType::Omikron,
|
|
||||||
"Webtransport Server listening on port {}",
|
|
||||||
port
|
|
||||||
);
|
|
||||||
|
|
||||||
while let Some((sender, receiver)) = host.next().await {
|
while let Some((sender, receiver)) = host.next().await {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
|
@ -36,5 +21,4 @@ pub async fn start(port: u16) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
>>>>>>> b2e6e903f789a81dd3629c21c08f03bbb430280b
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::BTreeMap,
|
||||||
fs::{self, OpenOptions},
|
fs::{self, OpenOptions},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::Path,
|
path::Path,
|
||||||
|
|
@ -175,7 +175,7 @@ pub fn format_cv(cv: &CommunicationValue) -> String {
|
||||||
let comm_type = cv.get_type().to_string();
|
let comm_type = cv.get_type().to_string();
|
||||||
parts.push(format!("{}", comm_type));
|
parts.push(format!("{}", comm_type));
|
||||||
|
|
||||||
let data: &HashMap<DataTypes, DataValue> = cv.get_data_container();
|
let data: &BTreeMap<DataTypes, DataValue> = cv.get_data_container();
|
||||||
|
|
||||||
let formated_data =
|
let formated_data =
|
||||||
format_data_container(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
|
format_data_container(data.iter().map(|(k, v)| (k.clone(), v.clone())).collect());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue