diff options
author | Quentin <quentin@dufour.io> | 2021-09-20 16:06:02 +0200 |
---|---|---|
committer | Quentin <quentin@dufour.io> | 2021-09-20 16:06:02 +0200 |
commit | 4d4d453afa3edafe71db2ae60171b8696b38a3c9 (patch) | |
tree | 64a54012efbac76bca6c5f0d8214fdae44743bc8 /src/consul_actor.rs | |
parent | 2bbc9109991f8bb79a09a965a1d2779e1749b25b (diff) | |
parent | 68cb4d5482649baca3a79d3fd0e3449a6af0533b (diff) | |
download | diplonat-4d4d453afa3edafe71db2ae60171b8696b38a3c9.tar.gz diplonat-4d4d453afa3edafe71db2ae60171b8696b38a3c9.zip |
Merge pull request 'Extensively use rustfmt' (#11) from quality/rustfmt into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/diplonat/pulls/11
Diffstat (limited to 'src/consul_actor.rs')
-rw-r--r-- | src/consul_actor.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/consul_actor.rs b/src/consul_actor.rs index d66f7fd..b111f09 100644 --- a/src/consul_actor.rs +++ b/src/consul_actor.rs @@ -1,14 +1,12 @@ -use crate::consul; -use crate::messages; +use std::{cmp, collections::HashSet, time::Duration}; + use anyhow::Result; use log::*; use serde::{Deserialize, Serialize}; use serde_lexpr::{error, from_str}; -use std::cmp; -use std::collections::HashSet; -use std::time::Duration; -use tokio::sync::watch; -use tokio::time::delay_for; +use tokio::{sync::watch, time::delay_for}; + +use crate::{consul, messages}; #[derive(Serialize, Deserialize, Debug)] pub enum DiplonatParameter { @@ -32,11 +30,12 @@ pub struct ConsulActor { fn retry_to_time(retries: u32, max_time: Duration) -> Duration { // 1.2^x seems to be a good value to exponentially increase time at a good pace - // eg. 1.2^32 = 341 seconds ~= 5 minutes - ie. after 32 retries we wait 5 minutes + // eg. 1.2^32 = 341 seconds ~= 5 minutes - ie. after 32 retries we wait 5 + // minutes return Duration::from_secs(cmp::min( max_time.as_secs(), 1.2f64.powf(retries as f64) as u64, - )); + )) } fn to_parameters(catalog: &consul::CatalogNode) -> Vec<DiplonatConsul> { @@ -52,7 +51,7 @@ fn to_parameters(catalog: &consul::CatalogNode) -> Vec<DiplonatConsul> { } } - return r; + return r } fn to_open_ports(params: &Vec<DiplonatConsul>) -> messages::PublicExposedPorts { @@ -71,7 +70,7 @@ fn to_open_ports(params: &Vec<DiplonatConsul>) -> messages::PublicExposedPorts { } } - return op; + return op } impl ConsulActor { @@ -87,7 +86,7 @@ impl ConsulActor { tx_open_ports: tx, node: node.to_string(), retries: 0, - }; + } } pub async fn listen(&mut self) -> Result<()> { @@ -104,7 +103,7 @@ impl ConsulActor { e ); delay_for(will_retry_in).await; - continue; + continue } }; self.retries = 0; |