diff --git a/Cargo.toml b/Cargo.toml index 89bde36..3fb361a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "vented" description = "Event driven encrypted tcp communicaton" -version = "0.7.0" +version = "0.7.1" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/src/server/data.rs b/src/server/data.rs index 96cce01..6aecb0e 100644 --- a/src/server/data.rs +++ b/src/server/data.rs @@ -27,17 +27,17 @@ pub(crate) struct ServerConnectionContext { pub known_nodes: Arc>>, pub event_handler: Arc>, pub connections: Arc>>, - pub forwarded_connections: Arc>>>, + pub forwarded_connections: Arc>>>, pub listener_pool: Arc>, } #[derive(Clone)] -pub(crate) struct Future { +pub struct AsyncValue { value: Arc>>, wg: Option, } -impl Future { +impl AsyncValue { /// Creates the future with no value pub fn new() -> Self { Self { @@ -63,12 +63,12 @@ impl Future { } /// Returns the value of the future only blocking for the given timeout - pub fn get_value_with_timeout(&mut self, millis: u128) -> Option { + pub fn get_value_with_timeout(&mut self, timeout: Duration) -> Option { let start = Instant::now(); while self.value.lock().is_none() { thread::sleep(Duration::from_millis(1)); - if start.elapsed().as_millis() > millis { + if start.elapsed() > timeout { break; } } diff --git a/src/server/mod.rs b/src/server/mod.rs index b2c591b..4ac2df3 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -9,7 +9,7 @@ use crate::event::Event; use crate::event_handler::EventHandler; use crate::result::VentedError::UnknownNode; use crate::result::{VentedError, VentedResult}; -use crate::server::data::{Future, Node, ServerConnectionContext}; +use crate::server::data::{AsyncValue, Node, ServerConnectionContext}; use crate::server::server_events::{ AuthPayload, ChallengePayload, NodeInformationPayload, RedirectPayload, VersionMismatchPayload, ACCEPT_EVENT, AUTH_EVENT, CHALLENGE_EVENT, CONNECT_EVENT, MISMATCH_EVENT, @@ -22,6 +22,7 @@ use std::io::Write; use std::iter::FromIterator; use std::sync::Arc; use std::thread; +use std::time::Duration; use x25519_dalek::StaticSecret; pub mod data; @@ -29,7 +30,7 @@ pub mod server_events; pub(crate) const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION"); -type ForwardFutureVector = Arc>>>; +type ForwardFutureVector = Arc>>>; type CryptoStreamMap = Arc>>; /// The vented server that provides parallel handling of connections @@ -72,7 +73,7 @@ pub struct VentedServer { event_handler: Arc>, global_secret_key: SecretKey, node_id: String, - redirect_handles: Arc>>>, + redirect_handles: Arc>>>, } impl VentedServer { @@ -226,10 +227,10 @@ impl VentedServer { target.clone(), event.clone().as_bytes(), ); - let mut future = Future::new(); + let mut future = AsyncValue::new(); self.redirect_handles .lock() - .insert(payload.id, Future::clone(&future)); + .insert(payload.id, AsyncValue::clone(&future)); if let Ok(stream) = self.get_connection(&node.id) { if let Err(e) = stream.send(Event::with_payload(REDIRECT_EVENT, &payload)) { @@ -238,7 +239,7 @@ impl VentedServer { } } - if let Some(value) = future.get_value_with_timeout(1000) { + if let Some(value) = future.get_value_with_timeout(Duration::from_secs(1)) { if value { return Ok(()); }