summaryrefslogtreecommitdiffhomepage
path: root/mullvad-rpc/src/bin/address_cache.rs
blob: efb2501ba968df0eed46961d2e3c76647a31d1c5 (plain)
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
39
/// Generate a first list of IP addresses for Mullvad VPN to use to talk to the API.
use mullvad_rpc::{rest::Error as RestError, ApiProxy, MullvadRpcRuntime};
use std::process;
use talpid_types::ErrorExt;

#[tokio::main]
async fn main() {
    let mut runtime =
        MullvadRpcRuntime::new(tokio::runtime::Handle::current()).expect("Failed to load runtime");

    let api_proxy = ApiProxy::new(runtime.mullvad_rest_handle());
    let request = api_proxy.get_api_addrs().await;

    let api_list = match request {
        Ok(api_list) => api_list,
        Err(RestError::TimeoutError(_)) => {
            eprintln!("Request timed out");
            process::exit(2);
        }
        Err(e @ RestError::DeserializeError(_)) => {
            eprintln!(
                "{}",
                e.display_chain_with_msg("Failed to deserialize API address list")
            );
            process::exit(3);
        }
        Err(e) => {
            eprintln!(
                "{}",
                e.display_chain_with_msg("Failed to fetch API address list")
            );
            process::exit(1);
        }
    };

    for address in api_list {
        println!("{}", address);
    }
}