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 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 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 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::Arc;

@ -1,3 +1,9 @@
/*
* vented asynchronous event based tcp server
* Copyright (C) 2020 trivernis
* See LICENSE for more information
*/
#[macro_use]
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 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 std::collections::HashMap;
use std::iter::FromIterator;
@ -30,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<Mutex<HashMap<(String, String), AsyncValue<CryptoStream, ()>>>>;
@ -131,7 +138,22 @@ impl VentedServer {
/// Emits an event to the specified Node
#[inline]
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.

@ -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};

@ -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};

@ -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;

@ -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;

@ -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};

@ -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;

Loading…
Cancel
Save