diplonat/src/main.rs

41 lines
1.2 KiB
Rust
Raw Normal View History

use std::net::SocketAddrV4;
2020-05-09 13:33:02 +00:00
//use std::collections::HashMap;
use log::*;
2020-02-12 17:33:10 +00:00
use igd::aio::search_gateway;
use igd::PortMappingProtocol;
2020-05-09 13:33:02 +00:00
mod config;
2020-02-12 17:33:10 +00:00
#[tokio::main]
async fn main() {
2020-05-09 13:33:02 +00:00
pretty_env_logger::init();
let config = match config::load_env() {
2020-02-12 23:17:23 +00:00
Ok(val) => val,
Err(e) => return println!("unable to build configuration: {}", e),
};
2020-05-08 10:46:10 +00:00
let url = format!("http://127.0.0.1:8500/v1/catalog/node/{}", config.consul_node_name);
let resp = reqwest::get(&url)
.await
2020-05-08 08:57:10 +00:00
.unwrap();
//.json::<HashMap<String, String>>()
//.await.unwrap();
println!("{:#?}", resp);
2020-02-12 17:33:10 +00:00
let gateway = match search_gateway(Default::default()).await {
Ok(g) => g,
Err(err) => return println!("Faild to find IGD: {}", err),
};
2020-05-09 13:33:02 +00:00
info!("Gateway: {}", gateway);
2020-02-12 17:33:10 +00:00
2020-02-12 23:17:23 +00:00
let service = format!("{}:{}", config.private_ip, 1234);
let service: SocketAddrV4 = service.parse().expect("Invalid socket address");
match gateway.add_port(PortMappingProtocol::TCP, 1234, service, config.expiration_time, "diplonat").await {
Ok(_) => (),
Err(e) => return println!("Unable to insert port 1234: {}", e),
2020-02-12 17:33:10 +00:00
};
}