wasmer_cli/commands/connect.rs
1// NOTE: not currently in use - but kept here to allow easy re-implementation.
2
3use std::net::IpAddr;
4
5use crate::config::WasmerEnv;
6
7use super::AsyncCliCommand;
8
9/// Connects to the Wasmer Edge distributed network.
10#[derive(clap::Parser, Debug)]
11pub struct CmdConnect {
12 #[clap(flatten)]
13 env: WasmerEnv,
14
15 /// Runs in promiscuous mode
16 #[clap(long)]
17 pub promiscuous: bool,
18 /// Prints the network token rather than connecting
19 #[clap(long)]
20 pub print: bool,
21 /// Skips bringing the interface up using the `ip` tool.
22 #[clap(long)]
23 pub leave_down: bool,
24 /// Do not modify the postfix of the URL before connecting
25 #[clap(long)]
26 pub leave_postfix: bool,
27 /// One or more static IP address to assign the interface
28 #[clap(long)]
29 pub ip: Vec<IpAddr>,
30 /// Thr URL we will be connecting to
31 #[clap(index = 1)]
32 pub url: url::Url,
33}
34
35#[async_trait::async_trait]
36impl AsyncCliCommand for CmdConnect {
37 type Output = ();
38
39 // Note (xdoardo, 28 Oct 2024):
40 // This part of the code is commented out as we did not manage
41 // to implement tun-tap yet.
42 //
43 //
44 //
45 //#[cfg(all(target_os = "linux", feature = "tun-tap"))]
46 //async fn run_async(mut self) -> Result<(), anyhow::Error> {
47 // use edge_schema::{AppId, NetworkIdEncodingMethod, WELL_KNOWN_VPN};
48 // use virtual_mio::Selector;
49
50 // use crate::net::TunTapSocket;
51
52 // // If the URL does not include the well known postfix then add it
53 // if !self.leave_postfix {
54 // self.url.set_path(WELL_KNOWN_VPN);
55 // }
56
57 // if self.print {
58 // println!("websocket-url: {}", self.url.as_str());
59 // return Ok(());
60 // }
61
62 // print!("Connecting...");
63 // let socket = TunTapSocket::create(
64 // Selector::new(),
65 // self.url.clone(),
66 // self.leave_down == false,
67 // self.ip,
68 // )
69 // .await
70 // .map_err(|err| {
71 // println!("failed");
72 // err
73 // })?;
74 // println!("\rConnected to {} ", self.url.as_str());
75
76 // for cidr in socket.ips().iter() {
77 // println!("Your IP: {}/{}", cidr.ip, cidr.prefix);
78 // }
79 // for route in socket.routes().iter() {
80 // println!(
81 // "Gateway: {}/{} -> {}",
82 // route.cidr.ip, route.cidr.prefix, route.via_router
83 // );
84 // }
85 // for cidr in socket.ips().iter() {
86 // if let Some((app_id, _)) =
87 // AppId::from_ip(&cidr.ip, NetworkIdEncodingMethod::PrivateProjection)
88 // {
89 // let ip = app_id.into_ip(
90 // cidr.ip,
91 // 0x00_1001,
92 // NetworkIdEncodingMethod::PrivateProjection,
93 // );
94 // println!("Instance: {}/{}", ip, cidr.prefix);
95 // }
96 // }
97 // println!("Press ctrl-c to terminate");
98 // socket.await?;
99
100 // Ok(())
101 //}
102
103 //#[cfg(not(all(target_os = "linux", feature = "tun-tap")))]
104 async fn run_async(self) -> Result<(), anyhow::Error> {
105 Err(anyhow::anyhow!(
106 "This CLI does not support the 'connect' command: only available on Linux (feature: tun-tap)"
107 ))
108 }
109}