Rewrite for clarity

This commit is contained in:
Quentin 2020-05-22 18:13:32 +02:00
parent 5fafc1cb64
commit deeecd93e1

View file

@ -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)) 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 { fn to_parameters(catalog: &consul::CatalogNode) -> Vec<DiplonatConsul> {
let mut op = messages::PublicExposedPorts { let mut r = Vec::new();
tcp_ports: Vec::new(),
udp_ports: Vec::new()
};
for (_, service_info) in &catalog.Services { for (_, service_info) in &catalog.Services {
for tag in &service_info.Tags { for tag in &service_info.Tags {
let diplo_conf: error::Result<DiplonatConsul> = from_str(tag); let diplo_conf: error::Result<DiplonatConsul> = from_str(tag);
match diplo_conf { match diplo_conf {
Ok(conf) => { Ok(conf) => r.push(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),
}
}
}
Err(e) => debug!("Failed to parse entry {}. {}", tag, e), 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; return op;
} }
@ -91,7 +100,7 @@ impl ConsulActor {
} }
}; };
self.retries = 0; self.retries = 0;
info!("{:#?}", from_catalog_to_open_ports(&catalog)); info!("{:#?}", to_open_ports(&to_parameters(&catalog)));
} }
} }
} }