mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 12:18:31 -04:00
Spawn tunnels in entirely separate threads
This commit is contained in:
parent
651ddaec49
commit
ed835c47d3
1 changed files with 12 additions and 12 deletions
24
src/main.rs
24
src/main.rs
|
@ -58,22 +58,22 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let port_forwards = config.port_forwards;
|
let port_forwards = config.port_forwards;
|
||||||
let source_peer_ip = config.source_peer_ip;
|
let source_peer_ip = config.source_peer_ip;
|
||||||
|
|
||||||
futures::future::try_join_all(
|
port_forwards
|
||||||
port_forwards
|
.into_iter()
|
||||||
.into_iter()
|
.map(|pf| (pf, wg.clone(), port_pool.clone()))
|
||||||
.map(|pf| (pf, wg.clone(), port_pool.clone()))
|
.for_each(move |(pf, wg, port_pool)| {
|
||||||
.map(|(pf, wg, port_pool)| {
|
std::thread::spawn(move || {
|
||||||
tokio::spawn(async move {
|
let cpu_pool = tokio::runtime::Runtime::new().unwrap();
|
||||||
|
cpu_pool.block_on(async move {
|
||||||
port_forward(pf, source_peer_ip, port_pool, wg)
|
port_forward(pf, source_peer_ip, port_pool, wg)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| error!("Port-forward failed for {} : {}", pf, e))
|
.unwrap_or_else(|e| error!("Port-forward failed for {} : {}", pf, e))
|
||||||
})
|
});
|
||||||
}),
|
});
|
||||||
)
|
});
|
||||||
.await
|
|
||||||
.with_context(|| "A port-forward instance failed.")
|
|
||||||
.map(|_| ())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
futures::future::pending().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn port_forward(
|
async fn port_forward(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue