Spawn tunnels in entirely separate threads

This commit is contained in:
Aram 🍐 2021-10-18 03:54:13 -04:00
parent 651ddaec49
commit ed835c47d3

View file

@ -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()))
.map(|(pf, wg, port_pool)| { .for_each(move |(pf, wg, port_pool)| {
tokio::spawn(async move { std::thread::spawn(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(