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