Browse Source

Rewrite with modules, still in progress...

main
Quentin 1 year ago
parent
commit
a19ae25a7d
  1. 7
      src/config.rs
  2. 19
      src/diplonat.rs
  3. 9
      src/main.rs

7
src/config.rs

@ -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

@ -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;
}

9
src/main.rs

@ -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),
};
*/
}
Loading…
Cancel
Save