Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelize cleanup init #822

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions clu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::fs::File;
use std::io::Read;
use std::net::IpAddr;
use std::path::Path;
use std::str;
use std::{str, thread};

mod error;
pub use error::NewCluError;
Expand Down Expand Up @@ -70,23 +70,26 @@ pub fn cleanup() -> Result<(), NewCluError> {
static ref RE: Regex = Regex::new(r"^wg[0-9]+$").unwrap();
}

let mut interfaces: Vec<String> = Vec::new();

for i in KI.get_interfaces()? {
if RE.is_match(&i) {
if let Err(e) = KI.del_interface(&i) {
trace!("Failed to delete wg# {:?}", e);
}
interfaces.push(i);
}
}
interfaces.push("wg_exit".to_string());
interfaces.push("wg_exit_v2".to_string());

if let Err(e) = KI.del_interface("wg_exit") {
trace!("Failed to delete wg_exit {:?}", e);
}
del_multiple_interfaces(interfaces);
Ok(())
}

if let Err(e) = KI.del_interface("wg_exit_v2") {
trace!("Failed to delete wg_exit_v2 {:?}", e);
/// Given a list of interfaces, deletes all them in parallel
pub fn del_multiple_interfaces(interfaces: Vec<String>) {
for name in interfaces {
// run each command in its own thread to prevent
thread::spawn(move || KI.del_interface(&name.clone()));
}

Ok(())
}

fn linux_init(settings: RitaClientSettings) -> Result<RitaClientSettings, NewCluError> {
Expand Down
Loading