mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
single thread tokio for daemon
This commit is contained in:
parent
e672e11f09
commit
695f1e1d74
3 changed files with 12 additions and 15 deletions
|
|
@ -9,14 +9,14 @@ use sd_notify::{NotifyState, notify};
|
|||
use std::io::Error as IoError;
|
||||
use std::pin::pin;
|
||||
use thiserror::Error;
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::runtime::Builder;
|
||||
use tokio::signal::ctrl_c;
|
||||
use tokio::signal::unix::{SignalKind, signal};
|
||||
use tokio_stream::wrappers::SignalStream;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
pub fn daemon(config: Config) -> MainResult {
|
||||
let rt = Runtime::new()?;
|
||||
let rt = Builder::new_current_thread().enable_io().build()?;
|
||||
Ok(rt.block_on(daemon_async(config))?)
|
||||
}
|
||||
|
||||
|
|
@ -76,11 +76,7 @@ async fn daemon_async(mut config: Config) -> Result<(), DaemonError> {
|
|||
for namespace in &state.namespaces {
|
||||
println!("{}:", namespace.name());
|
||||
for proxy in &namespace.proxies {
|
||||
println!(
|
||||
" {} => {}",
|
||||
proxy.source,
|
||||
proxy.destination,
|
||||
);
|
||||
println!(" {} => {}", proxy.source, proxy.destination,);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -105,12 +101,12 @@ struct State {
|
|||
|
||||
impl State {
|
||||
pub fn new() -> Result<Self, DaemonError> {
|
||||
let namespaces = NetNs::existing()?.map(ActiveNamespace::new).collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(State {
|
||||
namespaces
|
||||
})
|
||||
let namespaces = NetNs::existing()?
|
||||
.map(ActiveNamespace::new)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
Ok(State { namespaces })
|
||||
}
|
||||
|
||||
|
||||
pub fn update(&mut self, config: &Config) -> Result<(), DaemonError> {
|
||||
for removed in self.namespaces.extract_if(.., |namespace| {
|
||||
config.get_namespace(namespace.name()).is_none()
|
||||
|
|
@ -120,7 +116,8 @@ impl State {
|
|||
|
||||
for new in &config.namespaces {
|
||||
if !self.has_namespace(&new.name) {
|
||||
self.namespaces.push(ActiveNamespace::new(new.name.clone())?);
|
||||
self.namespaces
|
||||
.push(ActiveNamespace::new(new.name.clone())?);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue