summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/routing/unix.rs17
-rw-r--r--talpid-core/src/routing/windows.rs7
-rw-r--r--talpid-core/src/tunnel_state_machine/mod.rs4
3 files changed, 16 insertions, 12 deletions
diff --git a/talpid-core/src/routing/unix.rs b/talpid-core/src/routing/unix.rs
index c766fbfbe8..1ac83665db 100644
--- a/talpid-core/src/routing/unix.rs
+++ b/talpid-core/src/routing/unix.rs
@@ -82,23 +82,20 @@ pub enum RouteManagerCommand {
/// the route will be adjusted dynamically when the default route changes.
pub struct RouteManager {
manage_tx: Option<UnboundedSender<RouteManagerCommand>>,
- runtime: tokio::runtime::Runtime,
+ runtime: tokio::runtime::Handle,
}
impl RouteManager {
/// Constructs a RouteManager and applies the required routes.
/// Takes a set of network destinations and network nodes as an argument, and applies said
/// routes.
- pub fn new(required_routes: HashSet<RequiredRoute>) -> Result<Self, Error> {
+ pub fn new(
+ runtime: tokio::runtime::Handle,
+ required_routes: HashSet<RequiredRoute>,
+ ) -> Result<Self, Error> {
let (manage_tx, manage_rx) = mpsc::unbounded();
- let mut runtime = tokio::runtime::Builder::new()
- .threaded_scheduler()
- .core_threads(1)
- .max_threads(1)
- .enable_all()
- .build()?;
let manager = runtime.block_on(imp::RouteManagerImpl::new(required_routes))?;
- runtime.handle().spawn(manager.run(manage_rx));
+ runtime.spawn(manager.run(manage_rx));
Ok(Self {
runtime,
@@ -243,7 +240,7 @@ impl RouteManager {
/// Exposes runtime handle
#[cfg(target_os = "linux")]
pub fn runtime_handle(&self) -> tokio::runtime::Handle {
- self.runtime.handle().clone()
+ self.runtime.clone()
}
/// Route DNS requests through the tunnel interface.
diff --git a/talpid-core/src/routing/windows.rs b/talpid-core/src/routing/windows.rs
index 412384574b..f3e2197602 100644
--- a/talpid-core/src/routing/windows.rs
+++ b/talpid-core/src/routing/windows.rs
@@ -22,18 +22,23 @@ pub type Result<T> = std::result::Result<T, Error>;
pub struct RouteManager {
callback_handles: Vec<winnet::WinNetCallbackHandle>,
is_stopped: bool,
+ runtime: tokio::runtime::Handle,
}
impl RouteManager {
/// Creates a new route manager that will apply the provided routes and ensure they exist until
/// it's stopped.
- pub fn new(required_routes: HashSet<RequiredRoute>) -> Result<Self> {
+ pub fn new(
+ runtime: tokio::runtime::Handle,
+ required_routes: HashSet<RequiredRoute>,
+ ) -> Result<Self> {
if !winnet::activate_routing_manager() {
return Err(Error::FailedToStartManager);
}
let manager = Self {
callback_handles: vec![],
is_stopped: false,
+ runtime,
};
manager.add_routes(required_routes)?;
Ok(manager)
diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs
index b98eb820d1..9b33e8ae48 100644
--- a/talpid-core/src/tunnel_state_machine/mod.rs
+++ b/talpid-core/src/tunnel_state_machine/mod.rs
@@ -109,6 +109,7 @@ pub async fn spawn(
let (startup_result_tx, startup_result_rx) = sync_mpsc::channel();
std::thread::spawn(move || {
let state_machine = TunnelStateMachine::new(
+ runtime.clone(),
allow_lan,
block_when_disconnected,
is_offline,
@@ -189,6 +190,7 @@ struct TunnelStateMachine {
impl TunnelStateMachine {
fn new(
+ runtime: tokio::runtime::Handle,
allow_lan: bool,
block_when_disconnected: bool,
is_offline: bool,
@@ -209,7 +211,7 @@ impl TunnelStateMachine {
let firewall = Firewall::new(args).map_err(Error::InitFirewallError)?;
let dns_monitor = DnsMonitor::new(cache_dir).map_err(Error::InitDnsMonitorError)?;
let route_manager =
- RouteManager::new(HashSet::new()).map_err(Error::InitRouteManagerError)?;
+ RouteManager::new(runtime, HashSet::new()).map_err(Error::InitRouteManagerError)?;
let mut shared_values = SharedTunnelStateValues {
firewall,
dns_monitor,