diff options
| -rw-r--r-- | talpid-core/src/proxy/mod.rs | 50 | ||||
| -rw-r--r-- | talpid-core/src/proxy/noop.rs | 44 |
2 files changed, 50 insertions, 44 deletions
diff --git a/talpid-core/src/proxy/mod.rs b/talpid-core/src/proxy/mod.rs index f16c84da5f..57065fb99d 100644 --- a/talpid-core/src/proxy/mod.rs +++ b/talpid-core/src/proxy/mod.rs @@ -1,9 +1,10 @@ +mod noop; mod shadowsocks; pub use std::io::Result; use self::shadowsocks::ShadowsocksProxyMonitor; -use std::{fmt, path::PathBuf, sync::mpsc}; +use std::{fmt, path::PathBuf}; use talpid_types::net::openvpn; pub enum WaitResult { @@ -32,47 +33,6 @@ pub trait ProxyMonitorCloseHandle: Send { fn close(self: Box<Self>) -> Result<()>; } -struct NoopProxyMonitor { - tx: mpsc::Sender<()>, - rx: mpsc::Receiver<()>, - port: u16, -} - -impl NoopProxyMonitor { - fn start(port: u16) -> Result<Self> { - let (tx, rx) = mpsc::channel(); - Ok(NoopProxyMonitor { tx, rx, port }) - } -} - -impl ProxyMonitor for NoopProxyMonitor { - fn close_handle(&mut self) -> Box<dyn ProxyMonitorCloseHandle> { - Box::new(NoopProxyMonitorCloseHandle { - tx: self.tx.clone(), - }) - } - - fn wait(self: Box<Self>) -> Result<WaitResult> { - let _ = self.rx.recv(); - Ok(WaitResult::ProperShutdown) - } - - fn port(&self) -> u16 { - self.port - } -} - -struct NoopProxyMonitorCloseHandle { - tx: mpsc::Sender<()>, -} - -impl ProxyMonitorCloseHandle for NoopProxyMonitorCloseHandle { - fn close(self: Box<Self>) -> Result<()> { - let _ = self.tx.send(()); - Ok(()) - } -} - /// Variables that define the environment to help /// proxy implementations find their way around. /// TODO: Move struct to wider scope and use more generic name. @@ -88,11 +48,13 @@ pub fn start_proxy( match settings { openvpn::ProxySettings::Local(local_settings) => { // These are generic proxy settings with the proxy client not managed by us. - Ok(Box::new(NoopProxyMonitor::start(local_settings.port)?)) + Ok(Box::new(noop::NoopProxyMonitor::start( + local_settings.port, + )?)) } openvpn::ProxySettings::Remote(remote_settings) => { // These are generic proxy settings with the proxy client not managed by us. - Ok(Box::new(NoopProxyMonitor::start( + Ok(Box::new(noop::NoopProxyMonitor::start( remote_settings.address.port(), )?)) } diff --git a/talpid-core/src/proxy/noop.rs b/talpid-core/src/proxy/noop.rs new file mode 100644 index 0000000000..f6e800a0c4 --- /dev/null +++ b/talpid-core/src/proxy/noop.rs @@ -0,0 +1,44 @@ +use std::sync::mpsc; + +use super::{ProxyMonitor, ProxyMonitorCloseHandle, Result, WaitResult}; + +pub struct NoopProxyMonitor { + tx: mpsc::Sender<()>, + rx: mpsc::Receiver<()>, + port: u16, +} + +impl NoopProxyMonitor { + pub fn start(port: u16) -> Result<Self> { + let (tx, rx) = mpsc::channel(); + Ok(NoopProxyMonitor { tx, rx, port }) + } +} + +impl ProxyMonitor for NoopProxyMonitor { + fn close_handle(&mut self) -> Box<dyn ProxyMonitorCloseHandle> { + Box::new(NoopProxyMonitorCloseHandle { + tx: self.tx.clone(), + }) + } + + fn wait(self: Box<Self>) -> Result<WaitResult> { + let _ = self.rx.recv(); + Ok(WaitResult::ProperShutdown) + } + + fn port(&self) -> u16 { + self.port + } +} + +struct NoopProxyMonitorCloseHandle { + tx: mpsc::Sender<()>, +} + +impl ProxyMonitorCloseHandle for NoopProxyMonitorCloseHandle { + fn close(self: Box<Self>) -> Result<()> { + let _ = self.tx.send(()); + Ok(()) + } +} |
