summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid-core/src/tunnel/openvpn.rs31
-rw-r--r--talpid-ipc/src/lib.rs12
2 files changed, 35 insertions, 8 deletions
diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs
index 81d4bd88a4..368fb20257 100644
--- a/talpid-core/src/tunnel/openvpn.rs
+++ b/talpid-core/src/tunnel/openvpn.rs
@@ -39,6 +39,7 @@ lazy_static!{
/// Struct for monitoring an OpenVPN process.
+#[derive(Debug)]
pub struct OpenVpnMonitor<C: OpenVpnBuilder = OpenVpnCommand> {
child: Arc<C::ProcessHandle>,
event_dispatcher: Option<OpenVpnEventDispatcher>,
@@ -150,6 +151,7 @@ impl<C: OpenVpnBuilder> OpenVpnMonitor<C> {
}
/// A handle to an `OpenVpnMonitor` for closing it.
+#[derive(Debug, Clone)]
pub struct OpenVpnCloseHandle<H: ProcessHandle = duct::Handle> {
child: Arc<H>,
closed: Arc<AtomicBool>,
@@ -167,6 +169,7 @@ impl<H: ProcessHandle> OpenVpnCloseHandle<H> {
}
/// Internal enum to differentiate between if the child process or the event dispatcher died first.
+#[derive(Debug)]
enum WaitResult {
Child(io::Result<ExitStatus>, bool),
EventDispatcher(talpid_ipc::Result<()>),
@@ -224,6 +227,7 @@ impl ProcessHandle for duct::Handle {
/// IPC server for listening to events coming from plugin loaded into OpenVPN.
+#[derive(Debug)]
pub struct OpenVpnEventDispatcher {
server: talpid_ipc::IpcServer,
}
@@ -300,10 +304,10 @@ mod tests {
use std::sync::{Arc, Mutex};
- #[derive(Default, Clone)]
+ #[derive(Debug, Default, Clone)]
struct TestOpenVpnBuilder {
pub plugin: Arc<Mutex<Option<PathBuf>>>,
- pub exit_status: i32,
+ pub process_handle: Option<TestProcessHandle>,
}
impl OpenVpnBuilder for TestOpenVpnBuilder {
@@ -315,10 +319,11 @@ mod tests {
}
fn start(&self) -> io::Result<Self::ProcessHandle> {
- Ok(TestProcessHandle(self.exit_status))
+ self.process_handle.ok_or(io::Error::new(io::ErrorKind::Other, "failed to start"))
}
}
+ #[derive(Debug, Copy, Clone)]
struct TestProcessHandle(i32);
impl ProcessHandle for TestProcessHandle {
@@ -340,9 +345,9 @@ mod tests {
}
#[test]
- fn plugin() {
+ fn sets_plugin() {
let builder = TestOpenVpnBuilder::default();
- OpenVpnMonitor::new_internal(builder.clone(), |_, _| {}, "./my_test_plugin").unwrap();
+ let _ = OpenVpnMonitor::new_internal(builder.clone(), |_, _| {}, "./my_test_plugin");
assert_eq!(
Some(PathBuf::from("./my_test_plugin")),
*builder.plugin.lock().unwrap()
@@ -352,7 +357,7 @@ mod tests {
#[test]
fn exit_successfully() {
let mut builder = TestOpenVpnBuilder::default();
- builder.exit_status = 0;
+ builder.process_handle = Some(TestProcessHandle(0));
let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap();
assert!(testee.wait().is_ok());
}
@@ -360,7 +365,7 @@ mod tests {
#[test]
fn exit_error() {
let mut builder = TestOpenVpnBuilder::default();
- builder.exit_status = 1;
+ builder.process_handle = Some(TestProcessHandle(1));
let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap();
assert!(testee.wait().is_err());
}
@@ -368,9 +373,19 @@ mod tests {
#[test]
fn wait_closed() {
let mut builder = TestOpenVpnBuilder::default();
- builder.exit_status = 1;
+ builder.process_handle = Some(TestProcessHandle(1));
let testee = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap();
testee.close_handle().close().unwrap();
assert!(testee.wait().is_ok());
}
+
+ #[test]
+ fn failed_process_start() {
+ let builder = TestOpenVpnBuilder::default();
+ let error = OpenVpnMonitor::new_internal(builder, |_, _| {}, "").unwrap_err();
+ match error.kind() {
+ &ErrorKind::ChildProcessError(_) => (),
+ _ => panic!("Wrong error"),
+ }
+ }
}
diff --git a/talpid-ipc/src/lib.rs b/talpid-ipc/src/lib.rs
index 3ef9bf4733..9875bb198e 100644
--- a/talpid-ipc/src/lib.rs
+++ b/talpid-ipc/src/lib.rs
@@ -15,6 +15,7 @@ extern crate url;
use jsonrpc_core::{MetaIoHandler, Metadata};
use jsonrpc_ws_server::{MetaExtractor, NoopExtractor, Server, ServerBuilder};
+use std::fmt;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
@@ -79,6 +80,17 @@ impl IpcServer {
}
}
+// FIXME: This custom impl is because `Server` does not implement `Debug` yet:
+// https://github.com/paritytech/jsonrpc/pull/195
+impl fmt::Debug for IpcServer {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.debug_struct("IpcServer")
+ .field("address", &self.address)
+ .finish()
+ }
+}
+
+
#[derive(Clone)]
pub struct CloseHandle(jsonrpc_ws_server::CloseHandle);