2020-02-12 18:14:02 +00:00
|
|
|
use std::net::SocketAddrV4;
|
2020-05-09 13:33:02 +00:00
|
|
|
//use std::collections::HashMap;
|
|
|
|
|
|
|
|
use log::*;
|
2020-02-12 18:14:02 +00:00
|
|
|
|
|
|
|
use igd::PortMappingProtocol;
|
|
|
|
|
2020-05-09 13:53:22 +00:00
|
|
|
mod diplonat;
|
2020-05-09 13:33:02 +00:00
|
|
|
mod config;
|
2020-05-09 14:27:54 +00:00
|
|
|
mod gw;
|
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();
|
|
|
|
|
2020-05-09 14:27:54 +00:00
|
|
|
let ctx = diplonat::setup().await.expect("Setup failed");
|
2020-05-09 14:19:09 +00:00
|
|
|
diplonat::listen();
|
2020-05-09 13:53:22 +00:00
|
|
|
/*
|
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)
|
2020-02-14 09:46:39 +00:00
|
|
|
.await
|
2020-05-08 08:57:10 +00:00
|
|
|
.unwrap();
|
|
|
|
//.json::<HashMap<String, String>>()
|
|
|
|
//.await.unwrap();
|
2020-02-14 09:46:39 +00:00
|
|
|
println!("{:#?}", resp);
|
2020-02-12 18:14:02 +00:00
|
|
|
|
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-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 {
|
2020-02-12 18:14:02 +00:00
|
|
|
Ok(_) => (),
|
|
|
|
Err(e) => return println!("Unable to insert port 1234: {}", e),
|
2020-02-12 17:33:10 +00:00
|
|
|
};
|
2020-05-09 13:53:22 +00:00
|
|
|
*/
|
2020-02-12 17:33:10 +00:00
|
|
|
}
|