aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 16:27:43 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2020-05-22 16:27:43 +0200
commit5fafc1cb648fadd200736f74bd72867f4e7960d5 (patch)
tree2bac6323990d92055ec9ce04be22a8a4c35d1068 /src
parentec777652c17ccefed9b332b13e7a233de1a32867 (diff)
downloaddiplonat-5fafc1cb648fadd200736f74bd72867f4e7960d5.tar.gz
diplonat-5fafc1cb648fadd200736f74bd72867f4e7960d5.zip
Handle UDP/TCP
Diffstat (limited to 'src')
-rw-r--r--src/consul_actor.rs27
-rw-r--r--src/messages.rs5
2 files changed, 22 insertions, 10 deletions
diff --git a/src/consul_actor.rs b/src/consul_actor.rs
index 94ed9ab..241a643 100644
--- a/src/consul_actor.rs
+++ b/src/consul_actor.rs
@@ -11,7 +11,8 @@ use crate::consul;
#[derive(Serialize, Deserialize, Debug)]
pub enum DiplonatParameter {
- port(Vec<u16>)
+ tcp_port(Vec<u16>),
+ udp_port(Vec<u16>)
}
#[derive(Serialize, Deserialize, Debug)]
@@ -20,12 +21,12 @@ pub enum DiplonatConsul {
}
pub struct ConsulActor {
- pub rx_open_ports: watch::Receiver<messages::OpenPorts>,
+ pub rx_open_ports: watch::Receiver<messages::PublicExposedPorts>,
consul: consul::Consul,
node: String,
retries: u32,
- tx_open_ports: watch::Sender<messages::OpenPorts>
+ tx_open_ports: watch::Sender<messages::PublicExposedPorts>
}
fn retry_to_time(retries: u32, max_time: Duration) -> Duration {
@@ -34,8 +35,12 @@ 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::OpenPorts {
- let mut op = messages::OpenPorts { ports: Vec::new() };
+fn from_catalog_to_open_ports(catalog: &consul::CatalogNode) -> messages::PublicExposedPorts {
+ let mut op = messages::PublicExposedPorts {
+ tcp_ports: Vec::new(),
+ udp_ports: Vec::new()
+ };
+
for (_, service_info) in &catalog.Services {
for tag in &service_info.Tags {
let diplo_conf: error::Result<DiplonatConsul> = from_str(tag);
@@ -43,8 +48,10 @@ fn from_catalog_to_open_ports(catalog: &consul::CatalogNode) -> messages::OpenPo
Ok(conf) => {
let DiplonatConsul::diplonat(c) = conf;
for parameter in &c {
- let DiplonatParameter::port(p) = parameter;
- op.ports.extend(p);
+ 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),
@@ -56,7 +63,11 @@ fn from_catalog_to_open_ports(catalog: &consul::CatalogNode) -> messages::OpenPo
impl ConsulActor {
pub fn new(url: &str, node: &str) -> Self {
- let (tx, rx) = watch::channel(messages::OpenPorts{ports: Vec::new() });
+ let (tx, rx) = watch::channel(messages::PublicExposedPorts{
+ tcp_ports: Vec::new(),
+ udp_ports: Vec::new()
+ });
+
return Self {
consul: consul::Consul::new(url),
rx_open_ports: rx,
diff --git a/src/messages.rs b/src/messages.rs
index 719d2c0..46cc4c5 100644
--- a/src/messages.rs
+++ b/src/messages.rs
@@ -1,4 +1,5 @@
#[derive(Debug, Clone)]
-pub struct OpenPorts {
- pub ports: Vec<u16>
+pub struct PublicExposedPorts {
+ pub tcp_ports: Vec<u16>,
+ pub udp_ports: Vec<u16>
}