aboutsummaryrefslogtreecommitdiff
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
parent0a31e36854c4d3826491947715b61d373c9ac771 (diff)
downloaddiplonat-f827fd3113a8d5dd267c544251420c87f9a1650a.tar.gz
diplonat-f827fd3113a8d5dd267c544251420c87f9a1650a.zip
WIP consul integration
-rw-r--r--Cargo.lock4
-rwxr-xr-xdiplonat_debug8
-rw-r--r--src/main.rs20
3 files changed, 29 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c75e1b3..c141996 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -31,9 +31,9 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
[[package]]
name = "backtrace"
-version = "0.3.43"
+version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f80256bc78f67e7df7e36d77366f636ed976895d91fe2ab9efa3973e8fe8c4f"
+checksum = "e4036b9bf40f3cf16aba72a3d65e8a520fc4bafcdc7079aea8f848c58c5b5536"
dependencies = [
"backtrace-sys",
"cfg-if",
diff --git a/diplonat_debug b/diplonat_debug
new file mode 100755
index 0000000..c5de2d6
--- /dev/null
+++ b/diplonat_debug
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+export DIPLONAT_PRIVATE_IP=10.3.3.37
+export DIPLONAT_REFRESH_TIME=60
+export DIPLONAT_EXPIRATION_TIME=180
+export DIPLONAT_CONSUL_NODE_NAME=rincevent
+
+./target/debug/diplonat
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,