-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathrelay_list.rs
40 lines (36 loc) · 1.32 KB
/
relay_list.rs
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
40
//! Fetches and prints the full relay list in JSON.
//! Used by the installer artifact packer to bundle the latest available
//! relay list at the time of creating the installer.
use mullvad_api::{self, proxy::ApiConnectionMode, rest::Error as RestError, RelayListProxy};
use std::process;
use talpid_types::ErrorExt;
#[tokio::main]
async fn main() {
let runtime = mullvad_api::Runtime::new(tokio::runtime::Handle::current())
.expect("Failed to load runtime");
let relay_list_request = RelayListProxy::new(runtime.mullvad_rest_handle(
ApiConnectionMode::Direct,
ApiConnectionMode::Direct.into_repeat(),
))
.relay_list(None)
.await;
let relay_list = match relay_list_request {
Ok(relay_list) => relay_list,
Err(RestError::TimeoutError) => {
eprintln!("Request timed out");
process::exit(2);
}
Err(e @ RestError::DeserializeError(_)) => {
eprintln!(
"{}",
e.display_chain_with_msg("Failed to deserialize relay list")
);
process::exit(3);
}
Err(e) => {
eprintln!("{}", e.display_chain_with_msg("Failed to fetch relay list"));
process::exit(1);
}
};
println!("{}", serde_json::to_string_pretty(&relay_list).unwrap());
}