Browse Source

WIP consul integration

main
Quentin 1 year ago
parent
commit
f827fd3113
  1. 4
      Cargo.lock
  2. 8
      diplonat_debug
  3. 20
      src/main.rs

4
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",

8
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

20
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,

Loading…
Cancel
Save