Files
shoes/src/ip_stack/test_gate.rs
T
cfal 2be0409531 Add userspace WireGuard endpoints (#186)
Add named userspace WireGuard endpoints so Shoes can route inbound and outbound traffic through WireGuard without a kernel interface. Includes TCP/UDP forwarding, proxy-chain transports, reload lifecycle management, configuration validation, documentation, and dependency notices for release artifacts.
2026-10-17 15:23:44 -04:00

52 lines
1.2 KiB
Rust

use std::sync::mpsc::{self, Receiver, SyncSender};
use std::time::Duration;
pub(crate) struct TestGate {
entered: SyncSender<()>,
resume: Receiver<()>,
}
pub(crate) struct GateControl {
entered: Receiver<()>,
resume: SyncSender<()>,
}
impl TestGate {
pub fn new() -> (Self, GateControl) {
let (entered_tx, entered_rx) = mpsc::sync_channel(1);
let (resume_tx, resume_rx) = mpsc::sync_channel(1);
(
Self {
entered: entered_tx,
resume: resume_rx,
},
GateControl {
entered: entered_rx,
resume: resume_tx,
},
)
}
pub fn pause(self) {
if self.entered.send(()).is_ok() {
self.resume
.recv_timeout(Duration::from_secs(5))
.expect("test did not release the TUN gate");
}
}
}
impl GateControl {
pub fn wait(&self) {
self.entered
.recv_timeout(Duration::from_secs(5))
.expect("TUN thread did not reach the test gate");
}
}
impl Drop for GateControl {
fn drop(&mut self) {
let _ = self.resume.try_send(());
}
}