Merge pull request #1 from Trivernis/develop

Develop
pull/2/head
Trivernis 4 years ago committed by GitHub
commit 31a5c06833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 async_std::io::{Read, ReadExt};
use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; use byteorder::{BigEndian, ByteOrder, ReadBytesExt};

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::event::Event; use crate::event::Event;

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
use std::collections::HashMap; use std::collections::HashMap;
use crate::event::Event; use crate::event::Event;

@ -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::atomic::{AtomicUsize, Ordering};
use std::sync::Arc; use std::sync::Arc;

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
#[macro_use] #[macro_use]
pub mod utils; pub mod utils;

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
use x25519_dalek::PublicKey; use x25519_dalek::PublicKey;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};

@ -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 async_std::net::{TcpListener, TcpStream};
use std::collections::HashMap; use std::collections::HashMap;
use std::iter::FromIterator; use std::iter::FromIterator;
@ -30,6 +36,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");
pub const PROTOCOL_VERSION: &str = "1.0"; pub const PROTOCOL_VERSION: &str = "1.0";
pub const RETRY_LIMIT: usize = 3;
type ForwardFutureVector = Arc<Mutex<HashMap<(String, String), AsyncValue<CryptoStream, ()>>>>; type ForwardFutureVector = Arc<Mutex<HashMap<(String, String), AsyncValue<CryptoStream, ()>>>>;
@ -131,7 +138,22 @@ impl VentedServer {
/// Emits an event to the specified Node /// Emits an event to the specified Node
#[inline] #[inline]
pub async fn emit<S: ToString>(&self, node_id: S, event: Event) -> VentedResult<()> { pub async fn emit<S: ToString>(&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. /// Adds a handler for the given event.

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
use std::sync::Arc; use std::sync::Arc;
use rand::{thread_rng, RngCore}; use rand::{thread_rng, RngCore};

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
use async_std::prelude::*; use async_std::prelude::*;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};

@ -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::PublicKey;
pub use crypto_box::SecretKey; pub use crypto_box::SecretKey;

@ -1,2 +1,8 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
pub mod result; pub mod result;
pub mod sync; pub mod sync;

@ -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::error::Error;
use std::{fmt, io}; use std::{fmt, io};

@ -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::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use std::{mem};
use parking_lot::Mutex; use parking_lot::Mutex;

Loading…
Cancel
Save