|
|
@ -9,7 +9,7 @@ use crate::event::Event;
|
|
|
|
use crate::event_handler::EventHandler;
|
|
|
|
use crate::event_handler::EventHandler;
|
|
|
|
use crate::result::VentedError::UnknownNode;
|
|
|
|
use crate::result::VentedError::UnknownNode;
|
|
|
|
use crate::result::{VentedError, VentedResult};
|
|
|
|
use crate::result::{VentedError, VentedResult};
|
|
|
|
use crate::server::data::{Future, Node, ServerConnectionContext};
|
|
|
|
use crate::server::data::{AsyncValue, Node, ServerConnectionContext};
|
|
|
|
use crate::server::server_events::{
|
|
|
|
use crate::server::server_events::{
|
|
|
|
AuthPayload, ChallengePayload, NodeInformationPayload, RedirectPayload, VersionMismatchPayload,
|
|
|
|
AuthPayload, ChallengePayload, NodeInformationPayload, RedirectPayload, VersionMismatchPayload,
|
|
|
|
ACCEPT_EVENT, AUTH_EVENT, CHALLENGE_EVENT, CONNECT_EVENT, MISMATCH_EVENT,
|
|
|
|
ACCEPT_EVENT, AUTH_EVENT, CHALLENGE_EVENT, CONNECT_EVENT, MISMATCH_EVENT,
|
|
|
@ -22,6 +22,7 @@ use std::io::Write;
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::thread;
|
|
|
|
use std::thread;
|
|
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
use x25519_dalek::StaticSecret;
|
|
|
|
use x25519_dalek::StaticSecret;
|
|
|
|
|
|
|
|
|
|
|
|
pub mod data;
|
|
|
|
pub mod data;
|
|
|
@ -29,7 +30,7 @@ pub mod server_events;
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
pub(crate) const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
|
|
|
|
|
|
|
|
type ForwardFutureVector = Arc<Mutex<HashMap<(String, String), Future<CryptoStream>>>>;
|
|
|
|
type ForwardFutureVector = Arc<Mutex<HashMap<(String, String), AsyncValue<CryptoStream>>>>;
|
|
|
|
type CryptoStreamMap = Arc<Mutex<HashMap<String, CryptoStream>>>;
|
|
|
|
type CryptoStreamMap = Arc<Mutex<HashMap<String, CryptoStream>>>;
|
|
|
|
|
|
|
|
|
|
|
|
/// The vented server that provides parallel handling of connections
|
|
|
|
/// The vented server that provides parallel handling of connections
|
|
|
@ -72,7 +73,7 @@ pub struct VentedServer {
|
|
|
|
event_handler: Arc<Mutex<EventHandler>>,
|
|
|
|
event_handler: Arc<Mutex<EventHandler>>,
|
|
|
|
global_secret_key: SecretKey,
|
|
|
|
global_secret_key: SecretKey,
|
|
|
|
node_id: String,
|
|
|
|
node_id: String,
|
|
|
|
redirect_handles: Arc<Mutex<HashMap<[u8; 16], Future<bool>>>>,
|
|
|
|
redirect_handles: Arc<Mutex<HashMap<[u8; 16], AsyncValue<bool>>>>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl VentedServer {
|
|
|
|
impl VentedServer {
|
|
|
@ -226,10 +227,10 @@ impl VentedServer {
|
|
|
|
target.clone(),
|
|
|
|
target.clone(),
|
|
|
|
event.clone().as_bytes(),
|
|
|
|
event.clone().as_bytes(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let mut future = Future::new();
|
|
|
|
let mut future = AsyncValue::new();
|
|
|
|
self.redirect_handles
|
|
|
|
self.redirect_handles
|
|
|
|
.lock()
|
|
|
|
.lock()
|
|
|
|
.insert(payload.id, Future::clone(&future));
|
|
|
|
.insert(payload.id, AsyncValue::clone(&future));
|
|
|
|
|
|
|
|
|
|
|
|
if let Ok(stream) = self.get_connection(&node.id) {
|
|
|
|
if let Ok(stream) = self.get_connection(&node.id) {
|
|
|
|
if let Err(e) = stream.send(Event::with_payload(REDIRECT_EVENT, &payload)) {
|
|
|
|
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 {
|
|
|
|
if value {
|
|
|
|
return Ok(());
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|