diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-22 18:13:32 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-05-22 18:13:32 +0200 |
commit | deeecd93e1fc5545e6e0280d1799436638e84a38 (patch) | |
tree | 5e56f4fa62acd2ab80cd175f09d3aa2a09470a9b /src/consul_actor.rs | |
parent | 5fafc1cb648fadd200736f74bd72867f4e7960d5 (diff) | |
download | diplonat-deeecd93e1fc5545e6e0280d1799436638e84a38.tar.gz diplonat-deeecd93e1fc5545e6e0280d1799436638e84a38.zip |
Rewrite for clarity
Diffstat (limited to 'src/consul_actor.rs')
-rw-r--r-- | src/consul_actor.rs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/consul_actor.rs b/src/consul_actor.rs index 241a643..de5e216 100644 --- a/src/consul_actor.rs +++ b/src/consul_actor.rs @@ -35,29 +35,38 @@ fn retry_to_time(retries: u32, max_time: Duration) -> Duration { return Duration::from_secs(cmp::min(max_time.as_secs(), 1.2f64.powf(retries as f64) as u64)) } -fn from_catalog_to_open_ports(catalog: &consul::CatalogNode) -> messages::PublicExposedPorts { - let mut op = messages::PublicExposedPorts { - tcp_ports: Vec::new(), - udp_ports: Vec::new() - }; +fn to_parameters(catalog: &consul::CatalogNode) -> Vec<DiplonatConsul> { + let mut r = Vec::new(); for (_, service_info) in &catalog.Services { for tag in &service_info.Tags { let diplo_conf: error::Result<DiplonatConsul> = from_str(tag); match diplo_conf { - Ok(conf) => { - let DiplonatConsul::diplonat(c) = conf; - for parameter in &c { - match parameter { - DiplonatParameter::tcp_port(p) => op.tcp_ports.extend(p), - DiplonatParameter::udp_port(p) => op.udp_ports.extend(p), - } - } - } + Ok(conf) => r.push(conf), Err(e) => debug!("Failed to parse entry {}. {}", tag, e), }; } } + + return r; +} + +fn to_open_ports(params: &Vec<DiplonatConsul>) -> messages::PublicExposedPorts { + let mut op = messages::PublicExposedPorts { + tcp_ports: Vec::new(), + udp_ports: Vec::new() + }; + + for conf in params { + let DiplonatConsul::diplonat(c) = conf; + for parameter in c { + match parameter { + DiplonatParameter::tcp_port(p) => op.tcp_ports.extend(p), + DiplonatParameter::udp_port(p) => op.udp_ports.extend(p), + }; + } + } + return op; } @@ -91,7 +100,7 @@ impl ConsulActor { } }; self.retries = 0; - info!("{:#?}", from_catalog_to_open_ports(&catalog)); + info!("{:#?}", to_open_ports(&to_parameters(&catalog))); } } } |