diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-07-10 09:10:48 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-07-10 09:10:48 +0200 |
| commit | 5e82c3b62b7bac95e27f7c7782ceed6379537643 (patch) | |
| tree | 9f8f482b236e321bb617eff87c1582723d769fa8 /talpid_cli | |
| parent | 82a5ddf1bd3e697ae165af991ea0a3e2476f7bc8 (diff) | |
| parent | ec4d8bd1a5e35bd2f653042d673079dec20e9f49 (diff) | |
| download | mullvadvpn-5e82c3b62b7bac95e27f7c7782ceed6379537643.tar.xz mullvadvpn-5e82c3b62b7bac95e27f7c7782ceed6379537643.zip | |
Merge branch 'cli-with-rpc'
Diffstat (limited to 'talpid_cli')
| -rw-r--r-- | talpid_cli/Cargo.toml | 14 | ||||
| -rw-r--r-- | talpid_cli/src/cli.rs | 82 | ||||
| -rw-r--r-- | talpid_cli/src/main.rs | 62 |
3 files changed, 0 insertions, 158 deletions
diff --git a/talpid_cli/Cargo.toml b/talpid_cli/Cargo.toml deleted file mode 100644 index 8a3f013737..0000000000 --- a/talpid_cli/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "talpid_cli" -version = "0.0.0" -authors = ["Linus Färnstrand <linus@mullvad.net>", "Erik Larkö <erik@mullvad.net>"] -description = "Run Talpid easily from the command line" - -[dependencies] -clap = "2.20" -error-chain = "0.10" -log = "0.3" -env_logger = "0.4" - -[dependencies.talpid_core] -path = "../talpid_core" diff --git a/talpid_cli/src/cli.rs b/talpid_cli/src/cli.rs deleted file mode 100644 index b61c4112b5..0000000000 --- a/talpid_cli/src/cli.rs +++ /dev/null @@ -1,82 +0,0 @@ -use clap::{App, Arg, ArgMatches}; -use std::path::PathBuf; - -use talpid_core::net::RemoteAddr; - -#[cfg(all(unix, not(target_os="macos")))] -const DEFAULT_PLUGIN_PATH: &'static str = "./target/debug/libtalpid_openvpn_plugin.so"; -#[cfg(target_os="macos")] -const DEFAULT_PLUGIN_PATH: &'static str = "./target/debug/libtalpid_openvpn_plugin.dylib"; -#[cfg(windows)] -const DEFAULT_PLUGIN_PATH: &'static str = "./target/debug/libtalpid_openvpn_plugin.dll"; - - -pub struct Args { - pub binary: String, - pub plugin_path: PathBuf, - pub config: PathBuf, - pub remotes: Vec<RemoteAddr>, - pub verbosity: u64, -} - -pub fn parse_args_or_exit() -> Args { - let matches = get_matches(); - let remotes = values_t!(matches.values_of("remotes"), RemoteAddr).unwrap_or_else(|e| e.exit()); - Args { - binary: matches.value_of("openvpn").unwrap().to_owned(), - plugin_path: PathBuf::from(matches.value_of("plugin").unwrap()), - config: PathBuf::from(matches.value_of("config").unwrap()), - remotes: remotes, - verbosity: matches.occurrences_of("verbose"), - } -} - -fn get_matches() -> ArgMatches<'static> { - let app = create_app(); - app.clone().get_matches() -} - -fn create_app() -> App<'static, 'static> { - App::new(crate_name!()) - .version(crate_version!()) - .author(crate_authors!()) - .about(crate_description!()) - .arg( - Arg::with_name("openvpn") - .long("openvpn") - .help("Specify what OpenVPN binary to run") - .default_value("/usr/sbin/openvpn"), - ) - .arg( - Arg::with_name("config") - .short("c") - .long("config") - .help("Specify what config file to start OpenVPN with") - .default_value("./openvpn.conf"), - ) - .arg( - Arg::with_name("remotes") - .short("r") - .long("remotes") - .help( - "Configure what remote(s) to connect to. Accepts anything OpenVPN can use. \ - Format: <address>:<port>", - ) - .takes_value(true) - .multiple(true) - .required(true), - ) - .arg( - Arg::with_name("plugin") - .long("plugin") - .help("Path to talpid plugin") - .default_value(DEFAULT_PLUGIN_PATH), - ) - .arg( - Arg::with_name("verbose") - .short("v") - .long("verbose") - .multiple(true) - .help("Sets the level of verbosity"), - ) -} diff --git a/talpid_cli/src/main.rs b/talpid_cli/src/main.rs deleted file mode 100644 index 2f1e5c36dc..0000000000 --- a/talpid_cli/src/main.rs +++ /dev/null @@ -1,62 +0,0 @@ -// `error_chain!` can recurse deeply -#![recursion_limit = "1024"] - -extern crate talpid_core; -#[macro_use] -extern crate clap; -#[macro_use] -extern crate error_chain; -extern crate log; -extern crate env_logger; - -use std::sync::Mutex; -use std::sync::mpsc::{self, Receiver}; -use talpid_core::net::RemoteAddr; - -use talpid_core::tunnel::{TunnelEvent, TunnelMonitor}; - -mod cli; - - -error_chain!{} - -quick_main!(run); - -fn run() -> Result<()> { - init_logger()?; - let args = cli::parse_args_or_exit(); - main_loop(&args.remotes) -} - -pub fn init_logger() -> Result<()> { - env_logger::init().chain_err(|| "Failed to bootstrap logging system") -} - -fn main_loop(remotes: &[RemoteAddr]) -> Result<()> { - let mut remotes_iter = remotes.iter().cloned().cycle(); - let (monitor, rx) = create_tunnel_monitor()?; - loop { - monitor.start(remotes_iter.next().unwrap()).chain_err(|| "Unable to start OpenVPN")?; - while let Ok(msg) = rx.recv() { - match msg { - TunnelEvent::Shutdown => { - println!("Monitored process exited"); - break; - } - TunnelEvent::Up => println!("Tunnel UP"), - TunnelEvent::Down => println!("Tunnel DOWN"), - } - } - std::thread::sleep(std::time::Duration::from_millis(500)); - } -} - -fn create_tunnel_monitor() -> Result<(TunnelMonitor, Receiver<TunnelEvent>)> { - let (event_tx, event_rx) = mpsc::channel(); - let event_tx_mutex = Mutex::new(event_tx); - let on_event = move |event: TunnelEvent| { - event_tx_mutex.lock().unwrap().send(event).expect("Unable to send on tx_lock"); - }; - let monitor = TunnelMonitor::new(on_event).chain_err(|| "Unable to start OpenVPN monitor")?; - Ok((monitor, event_rx)) -} |
