aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorQuentin <quentin@deuxfleurs.fr>2020-02-14 10:26:50 +0100
committerQuentin <quentin@deuxfleurs.fr>2020-02-14 10:26:50 +0100
commitf827fd3113a8d5dd267c544251420c87f9a1650a (patch)
tree8bc9025639400619c831662b0d8956f232223eea /src
parent0a31e36854c4d3826491947715b61d373c9ac771 (diff)
downloaddiplonat-f827fd3113a8d5dd267c544251420c87f9a1650a.tar.gz
diplonat-f827fd3113a8d5dd267c544251420c87f9a1650a.zip
WIP consul integration
Diffstat (limited to 'src')
-rw-r--r--src/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index c041886..84acca1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,8 +4,12 @@ use std::net::SocketAddrV4;
use igd::aio::search_gateway;
use igd::PortMappingProtocol;
+use consul::catalog::Catalog;
+use consul::{Client, Config};
+
struct DiplonatConfig {
private_ip: String,
+ consul_node_name: String,
refresh_time: u32,
expiration_time: u32
}
@@ -28,12 +32,19 @@ fn fetch_configuration() -> Result<DiplonatConfig, String> {
Ok(val) => val.parse().unwrap(),
Err(e) => return Err(format!("unable to fetch environment variable {}: {}", env_expiration_time,e))
};
+
+ let env_consul_node_name = "DIPLONAT_CONSUL_NODE_NAME";
+ let consul_node_name = match env::var(env_consul_node_name) {
+ Ok(val) => val,
+ Err(e) => return Err(format!("unable to fetch environment variable {}: {}", env_consul_node_name,e))
+ };
if refresh_time * 2 > expiration_time {
return Err(format!("Expiration time (currently: {}s) must be twice bigger than refresh time (currently: {}s)", expiration_time, refresh_time))
}
- let config = DiplonatConfig { private_ip: private_ip, refresh_time: refresh_time, expiration_time: expiration_time };
+ let config = DiplonatConfig { private_ip: private_ip, refresh_time: refresh_time, expiration_time: expiration_time, consul_node_name: consul_node_name };
+ println!("\tConsul node name: {}", config.consul_node_name);
println!("\tPrivate IP address: {}", config.private_ip);
println!("\tRefresh time: {} seconds", config.refresh_time);
println!("\tExpiration time: {} seconds", config.expiration_time);
@@ -47,6 +58,13 @@ async fn main() {
Err(e) => return println!("unable to build configuration: {}", e),
};
+ let consul_config = Config::new().unwrap();
+ let consul_client = Client::new(consul_config);
+
+ match consul_client.nodes(None) {
+ Ok(v) => println!("ok: {:?}", v),
+ Err(err) => println!("err: {}", err),
+ };
let gateway = match search_gateway(Default::default()).await {
Ok(g) => g,