From e62e841d47a638fd99ba4d5a1ea8ce6ef2f79041 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 14 Nov 2020 12:21:34 +0100 Subject: [PATCH 1/2] Add copyright to source files Signed-off-by: trivernis --- src/event/mod.rs | 6 ++++++ src/event/tests.rs | 6 ++++++ src/event_handler/mod.rs | 6 ++++++ src/event_handler/tests.rs | 6 ++++++ src/lib.rs | 6 ++++++ src/server/data.rs | 6 ++++++ src/server/mod.rs | 6 ++++++ src/server/server_events.rs | 6 ++++++ src/stream/cryptostream.rs | 6 ++++++ src/stream/mod.rs | 6 ++++++ src/utils/mod.rs | 6 ++++++ src/utils/result.rs | 6 ++++++ src/utils/sync.rs | 8 +++++++- 13 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/event/mod.rs b/src/event/mod.rs index b90e5ca..100dfc9 100644 --- a/src/event/mod.rs +++ b/src/event/mod.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use async_std::io::{Read, ReadExt}; use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; diff --git a/src/event/tests.rs b/src/event/tests.rs index 3184499..8230cff 100644 --- a/src/event/tests.rs +++ b/src/event/tests.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use serde::{Deserialize, Serialize}; use crate::event::Event; diff --git a/src/event_handler/mod.rs b/src/event_handler/mod.rs index a1478e2..49d7729 100644 --- a/src/event_handler/mod.rs +++ b/src/event_handler/mod.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use std::collections::HashMap; use crate::event::Event; diff --git a/src/event_handler/tests.rs b/src/event_handler/tests.rs index 6507b66..4c5b354 100644 --- a/src/event_handler/tests.rs +++ b/src/event_handler/tests.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; diff --git a/src/lib.rs b/src/lib.rs index e80517d..6c72304 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + #[macro_use] pub mod utils; diff --git a/src/server/data.rs b/src/server/data.rs index 6c79824..911845c 100644 --- a/src/server/data.rs +++ b/src/server/data.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use x25519_dalek::PublicKey; use std::time::{Duration, Instant}; diff --git a/src/server/mod.rs b/src/server/mod.rs index 26d12cf..79fa504 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use async_std::net::{TcpListener, TcpStream}; use std::collections::HashMap; use std::iter::FromIterator; diff --git a/src/server/server_events.rs b/src/server/server_events.rs index fdcc40f..72672ef 100644 --- a/src/server/server_events.rs +++ b/src/server/server_events.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use std::sync::Arc; use rand::{thread_rng, RngCore}; diff --git a/src/stream/cryptostream.rs b/src/stream/cryptostream.rs index 5fc0f7e..b7d32d1 100644 --- a/src/stream/cryptostream.rs +++ b/src/stream/cryptostream.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use async_std::prelude::*; use byteorder::{BigEndian, ByteOrder}; diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 3dc9a7c..9031300 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + pub use crypto_box::PublicKey; pub use crypto_box::SecretKey; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 54c6d3d..840d65d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,8 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + pub mod result; pub mod sync; diff --git a/src/utils/result.rs b/src/utils/result.rs index 8987d0f..022efcf 100644 --- a/src/utils/result.rs +++ b/src/utils/result.rs @@ -1,3 +1,9 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + use std::error::Error; use std::{fmt, io}; diff --git a/src/utils/sync.rs b/src/utils/sync.rs index 2daf2e6..311ff18 100644 --- a/src/utils/sync.rs +++ b/src/utils/sync.rs @@ -1,6 +1,12 @@ +/* + * vented asynchronous event based tcp server + * Copyright (C) 2020 trivernis + * See LICENSE for more information + */ + +use std::mem; use std::sync::Arc; use std::time::{Duration, Instant}; -use std::{mem}; use parking_lot::Mutex; From 47e78948601836a66a55729bc97140c26d2512bd Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 14 Nov 2020 12:41:30 +0100 Subject: [PATCH 2/2] Add retries to emit Signed-off-by: trivernis --- src/server/mod.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/server/mod.rs b/src/server/mod.rs index 79fa504..b87f233 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -36,6 +36,7 @@ pub mod server_events; pub(crate) const CRATE_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const PROTOCOL_VERSION: &str = "1.0"; +pub const RETRY_LIMIT: usize = 3; type ForwardFutureVector = Arc>>>; @@ -137,7 +138,22 @@ impl VentedServer { /// Emits an event to the specified Node #[inline] pub async fn emit(&self, node_id: S, event: Event) -> VentedResult<()> { - self.send_event(&node_id.to_string(), event, true).await + let mut count = 0; + loop { + match self + .send_event(&node_id.to_string(), event.clone(), true) + .await + { + Ok(()) => return Ok(()), + Err(e) => { + count += 1; + log::warn!("Failed to send event on try {}: {}", count, e); + if count == RETRY_LIMIT { + return Err(e); + } + } + } + } } /// Adds a handler for the given event.