aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a6bca8a5e84f0d77080311cd8c1227243c47c25d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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 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),
    };
}