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))
}
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!("Private IP address: {}", config.private_ip);
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::PortMappingProtocol;
mod diplonat;
mod config;
#[tokio::main]
async fn main() {
pretty_env_logger::init();
let config = match config::load_env() {
Ok(val) => val,
Err(e) => return println!("unable to build configuration: {}", e),
};
let ctx = diplonat::setup().expect("Setup failed:");
/*
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
let resp = reqwest::get(&url)
.await
@ -37,4 +35,5 @@ async fn main() {
Ok(_) => (),
Err(e) => return println!("Unable to insert port 1234: {}", e),
};
*/
}