From 9a556309e4a705bf3fce531209d746a6a87bb69a Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 8 Nov 2020 20:09:01 +0100 Subject: [PATCH] Add check if node is known for redirect events Signed-off-by: trivernis --- Cargo.toml | 2 +- src/server/mod.rs | 2 +- src/server/server_events.rs | 45 ++++++++++++++++++++----------------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1fd2367..963fff6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "vented" description = "Event driven encrypted tcp communicaton" -version = "0.6.3" +version = "0.6.4" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/src/server/mod.rs b/src/server/mod.rs index dd80412..9f32260 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -333,7 +333,7 @@ impl VentedServer { } } - log::debug!("All connection attempts to {} failed!", target); + log::trace!("All direct connection attempts to {} failed", target); Err(VentedError::UnreachableNode(target.clone())) } diff --git a/src/server/server_events.rs b/src/server/server_events.rs index 493a57c..6e58515 100644 --- a/src/server/server_events.rs +++ b/src/server/server_events.rs @@ -143,34 +143,37 @@ impl VentedServer { let event_handler = Arc::clone(&self.event_handler); let connections = Arc::clone(&self.connections); let pool = Arc::clone(&self.sender_pool); + let known_nodes = Arc::clone(&self.known_nodes); move |event| { let payload = event.get_payload::().ok()?; let event = Event::from_bytes(&mut &payload.content[..]).ok()?; let proxy_stream = connections.lock().get(&payload.proxy)?.clone(); - pool.lock().execute({ - let event_handler = Arc::clone(&event_handler); - move || { - let response = event_handler.lock().handle_event(event); - let event = response.first().cloned().map(|mut value| { - Event::with_payload( - REDIRECT_EVENT, - &RedirectPayload::new( - payload.target, - payload.proxy, - payload.source, - value.as_bytes(), - ), - ) - }); - if let Some(event) = event { - proxy_stream - .send(event) - .expect("Failed to respond to redirected event."); + if known_nodes.lock().contains_key(&payload.source) { + pool.lock().execute({ + let event_handler = Arc::clone(&event_handler); + move || { + let response = event_handler.lock().handle_event(event); + let event = response.first().cloned().map(|mut value| { + Event::with_payload( + REDIRECT_EVENT, + &RedirectPayload::new( + payload.target, + payload.proxy, + payload.source, + value.as_bytes(), + ), + ) + }); + if let Some(event) = event { + proxy_stream + .send(event) + .expect("Failed to respond to redirected event."); + } } - } - }); + }); + } None }