Merge branch 'main' of github.com:Tensamin/Omikron
This commit is contained in:
commit
7532235ab0
3 changed files with 46 additions and 25 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -9,7 +9,7 @@ use std::env;
|
||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use rustls::crypto::aws_lc_rs;
|
use rustls::crypto::aws_lc_rs::default_provider;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
calls::call_util::garbage_collect_calls,
|
calls::call_util::garbage_collect_calls,
|
||||||
|
|
@ -32,15 +32,18 @@ pub fn get_public_key() -> x448::PublicKey {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
aws_lc_rs::default_provider().install_default();
|
if let Err(_) = default_provider().install_default() {
|
||||||
|
println!("Error loading Provider");
|
||||||
|
return;
|
||||||
|
}
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
startup();
|
startup();
|
||||||
|
|
||||||
start(959).await;
|
|
||||||
|
|
||||||
garbage_collect_calls();
|
|
||||||
|
|
||||||
get_omega_connection();
|
get_omega_connection();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let _ = start(959).await;
|
||||||
|
});
|
||||||
|
garbage_collect_calls();
|
||||||
|
|
||||||
tokio::signal::ctrl_c().await.unwrap();
|
tokio::signal::ctrl_c().await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/omega/omega_connection.rs
Executable file → Normal file
14
src/omega/omega_connection.rs
Executable file → Normal file
|
|
@ -83,13 +83,13 @@ impl ConnectionState {
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Omega Connection (Client-side with auto-reconnect)
|
// Omega Connection (Client-side with auto-reconnect)
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
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>>>>,
|
||||||
connection_loop_handle: Arc<Mutex<Option<JoinHandle<()>>>>,
|
connection_loop_handle: Arc<Mutex<Option<JoinHandle<()>>>>,
|
||||||
host: String,
|
host: String,
|
||||||
port: u16,
|
port: u16,
|
||||||
|
server_cert: Vec<u8>,
|
||||||
last_ping: Arc<Mutex<i64>>,
|
last_ping: Arc<Mutex<i64>>,
|
||||||
heartbeat_handle: Arc<Mutex<Option<JoinHandle<()>>>>,
|
heartbeat_handle: Arc<Mutex<Option<JoinHandle<()>>>>,
|
||||||
message_send_times: Arc<Mutex<HashMap<Uuid, Instant>>>,
|
message_send_times: Arc<Mutex<HashMap<Uuid, Instant>>>,
|
||||||
|
|
@ -103,6 +103,15 @@ impl OmegaConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_host(host: &str, port: u16) -> Self {
|
pub fn with_host(host: &str, port: u16) -> Self {
|
||||||
|
// Load server certificate from default location
|
||||||
|
let server_cert =
|
||||||
|
load_file_vec("certs", "cert.pem").expect("Failed to load server certificate");
|
||||||
|
|
||||||
|
Self::with_host_and_cert(host, port, server_cert)
|
||||||
|
}
|
||||||
|
|
||||||
|
// New constructor that accepts certificate directly
|
||||||
|
pub fn with_host_and_cert(host: &str, port: u16, server_cert: Vec<u8>) -> Self {
|
||||||
let (shutdown_tx, _) = watch::channel(false);
|
let (shutdown_tx, _) = watch::channel(false);
|
||||||
|
|
||||||
OmegaConnection {
|
OmegaConnection {
|
||||||
|
|
@ -111,6 +120,7 @@ impl OmegaConnection {
|
||||||
connection_loop_handle: Arc::new(Mutex::new(None)),
|
connection_loop_handle: Arc::new(Mutex::new(None)),
|
||||||
host: host.to_string(),
|
host: host.to_string(),
|
||||||
port,
|
port,
|
||||||
|
server_cert, // Store certificate for connection
|
||||||
last_ping: Arc::new(Mutex::new(-1)),
|
last_ping: Arc::new(Mutex::new(-1)),
|
||||||
heartbeat_handle: Arc::new(Mutex::new(None)),
|
heartbeat_handle: Arc::new(Mutex::new(None)),
|
||||||
message_send_times: Arc::new(Mutex::new(HashMap::new())),
|
message_send_times: Arc::new(Mutex::new(HashMap::new())),
|
||||||
|
|
@ -535,7 +545,7 @@ impl OmegaConnection {
|
||||||
|
|
||||||
match tokio::time::timeout(timeout, rx.recv()).await {
|
match tokio::time::timeout(timeout, rx.recv()).await {
|
||||||
Ok(Some(response_cv)) => Ok(response_cv),
|
Ok(Some(response_cv)) => Ok(response_cv),
|
||||||
Ok(None) => Err("Channel closed".to_string()),
|
Ok(_) => Err("Channel closed".to_string()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
WAITING_TASKS.remove(&msg_id);
|
WAITING_TASKS.remove(&msg_id);
|
||||||
Err("Request timed out".to_string())
|
Err("Request timed out".to_string())
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,13 @@
|
||||||
use crate::{
|
use crate::{log, rho::connection::GeneralConnection, util::file_util::load_file_vec};
|
||||||
log,
|
|
||||||
rho::connection::GeneralConnection,
|
|
||||||
util::file_util::{load_file_buf, load_file_vec},
|
|
||||||
};
|
|
||||||
use epsilon_native::Host;
|
use epsilon_native::Host;
|
||||||
use quinn::ServerConfig;
|
|
||||||
use rustls::{
|
|
||||||
ServerConfig as CryptoConfig,
|
|
||||||
crypto::{CryptoProvider, aws_lc_rs},
|
|
||||||
pki_types::{
|
|
||||||
CertificateDer, PrivateKeyDer,
|
|
||||||
pem::{PemObject, SectionKind},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub async fn start(port: u16) {
|
pub async fn start(port: u16) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let _ = aws_lc_rs::default_provider().install_default();
|
let cert_pem = load_file_vec("certs", "cert.pem")
|
||||||
|
.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").unwrap();
|
let key_pem = load_file_vec("certs", "key.pem").unwrap();
|
||||||
let cert_pem = load_file_vec("certs", "cert.pem").unwrap();
|
let cert_pem = load_file_vec("certs", "cert.pem").unwrap();
|
||||||
|
|
||||||
|
|
@ -29,4 +19,22 @@ pub async fn start(port: u16) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
=======
|
||||||
|
let mut host: Host = epsilon_native::host(port, cert_pem, key_pem).await?;
|
||||||
|
log!(
|
||||||
|
0,
|
||||||
|
crate::util::logger::PrintType::Omikron,
|
||||||
|
"Webtransport Server listening on port {}",
|
||||||
|
port
|
||||||
|
);
|
||||||
|
|
||||||
|
while let Some((sender, receiver)) = host.next().await {
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let conn = GeneralConnection::new(sender, receiver);
|
||||||
|
conn.handle().await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
>>>>>>> b2e6e903f789a81dd3629c21c08f03bbb430280b
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue