Rewrite with modules, still in progress...

This commit is contained in:
Quentin 2020-05-09 15:53:22 +02:00
parent 643d6980e5
commit a19ae25a7d
3 changed files with 29 additions and 6 deletions

View file

@ -38,7 +38,12 @@ pub fn load_env() -> Result<DiplonatConfig, String> {
return Err(format!("Expiration time (currently: {}s) must be twice bigger than refresh time (currently: {}s)", expiration_time, refresh_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, consul_node_name: consul_node_name }; let config = DiplonatConfig {
private_ip: private_ip,
refresh_time: refresh_time,
expiration_time: expiration_time,
consul_node_name: consul_node_name
};
info!("Consul node name: {}", config.consul_node_name); info!("Consul node name: {}", config.consul_node_name);
info!("Private IP address: {}", config.private_ip); info!("Private IP address: {}", config.private_ip);
info!("Refresh time: {} seconds", config.refresh_time); info!("Refresh time: {} seconds", config.refresh_time);

19
src/diplonat.rs Normal file
View file

@ -0,0 +1,19 @@
use igd::Gateway;
use crate::*;
pub struct DiplonatContext {
pub config: config::DiplonatConfig,
//pub gateway: igd::Gateway
}
pub fn setup() -> Result<DiplonatContext, String> {
return Ok(DiplonatContext {
config: config::load_env()?,
//gateway: search_gateway(Default::default()).await
});
}
pub fn dloop() -> bool {
return true;
}

View file

@ -6,17 +6,15 @@ use log::*;
use igd::aio::search_gateway; use igd::aio::search_gateway;
use igd::PortMappingProtocol; use igd::PortMappingProtocol;
mod diplonat;
mod config; mod config;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
let config = match config::load_env() { let ctx = diplonat::setup().expect("Setup failed:");
Ok(val) => val, /*
Err(e) => return println!("unable to build configuration: {}", e),
};
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name); let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
let resp = reqwest::get(&url) let resp = reqwest::get(&url)
.await .await
@ -37,4 +35,5 @@ async fn main() {
Ok(_) => (), Ok(_) => (),
Err(e) => return println!("Unable to insert port 1234: {}", e), Err(e) => return println!("Unable to insert port 1234: {}", e),
}; };
*/
} }