mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 09:04:07 +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
|
|
@ -5,7 +5,7 @@ edition = "2024"
|
|||
rust-version = "1.87.0"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "signal", "net", "io-util"] }
|
||||
tokio = { version = "1.48.0", features = ["macros", "rt", "signal", "net", "io-util"] }
|
||||
tokio-stream = { version = "0.1.17", features = ["signal", "net"] }
|
||||
toml = "0.9.8"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -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,10 +101,10 @@ 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> {
|
||||
|
|
@ -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())?);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ impl Proxy {
|
|||
})
|
||||
}
|
||||
|
||||
pub async fn run(self, target: ForwardTarget, abort: AbortRegistration,) {
|
||||
pub async fn run(self, target: ForwardTarget, abort: AbortRegistration) {
|
||||
match self.socket {
|
||||
ProxyListener::Tcp(socket) => {
|
||||
run_tcp(socket, target.addr, abort).await
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue