diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-02-12 19:14:02 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2020-02-12 19:14:02 +0100 |
commit | 91ba85236d3623402963ecafbf67512521b9f782 (patch) | |
tree | e2a622a1f4b4d4760b809c036e77ae8f5613858b | |
parent | 796a8d6f0bb47da4c888cbac7761b60609c50893 (diff) | |
download | diplonat-91ba85236d3623402963ecafbf67512521b9f782.tar.gz diplonat-91ba85236d3623402963ecafbf67512521b9f782.zip |
WIP serious configuration (broken code)
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index a676662..a6bca8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,38 @@ +use std::env; +use std::net::SocketAddrV4; + use igd::aio::search_gateway; +use igd::PortMappingProtocol; + +struct DiplonatConfig<'a> { + private_ip: &'a str, + refresh_time: u16, + expiration_time: u16 +} + +fn fetch_configuration { + let env_private_ip = "DIPLONAT_PRIVATE_IP"; + let private_ip = match env::var(env_private_ip) { + Ok(val) => val, + Err(e) => return println!("Unable to fetch {} environment variable: {}", env_private_ip, e), + }; + +} #[tokio::main] async fn main() { + + println!("Private IP address: {}", private_ip); + let gateway = match search_gateway(Default::default()).await { Ok(g) => g, Err(err) => return println!("Faild to find IGD: {}", err), }; - let pub_ip = match gateway.get_external_ip().await { - Ok(ip) => ip, - Err(err) => return println!("Failed to get external IP: {}", err), + let service = format!("{}:{}", private_ip, 1234); + let service: SocketAddrV4 = private_ip.parse().expect("Invalid socket address"); + match gateway.add_port(PortMappingProtocol::TCP, 1234, service, 120, "diplonat").await { + Ok(_) => (), + Err(e) => return println!("Unable to insert port 1234: {}", e), }; - println!("Our public IP is {}", pub_ip); } |