pub struct WireGuardTunnel { /* private fields */ }Expand description
A WireGuard tunnel that encrypts/decrypts IP packets.
Implementations§
Source§impl WireGuardTunnel
impl WireGuardTunnel
Sourcepub async fn new(config: WireGuardConfig) -> Result<Arc<Self>>
pub async fn new(config: WireGuardConfig) -> Result<Arc<Self>>
Create a new WireGuard tunnel with the given configuration.
Sourcepub fn outgoing_sender(&self) -> Sender<BytesMut>
pub fn outgoing_sender(&self) -> Sender<BytesMut>
Get the sender for outgoing packets.
Sourcepub fn take_incoming_receiver(&self) -> Option<Receiver<BytesMut>>
pub fn take_incoming_receiver(&self) -> Option<Receiver<BytesMut>>
Get the receiver for incoming packets (takes ownership of the receiver).
Sourcepub fn time_since_last_handshake(&self) -> Option<Duration>
pub fn time_since_last_handshake(&self) -> Option<Duration>
Returns the time elapsed since the last successful WireGuard handshake.
Returns Some(duration) if a handshake has completed, or None if no
handshake has occurred yet. This is useful for health-checking the tunnel:
WireGuard re-handshakes every ~120s on an active session, so a value
exceeding ~180s typically indicates the tunnel is stale.
Sourcepub async fn initiate_handshake(&self) -> Result<()>
pub async fn initiate_handshake(&self) -> Result<()>
Initiate the WireGuard handshake.
Sourcepub async fn send_ip_packet(&self, packet: BytesMut) -> Result<()>
pub async fn send_ip_packet(&self, packet: BytesMut) -> Result<()>
Send an IP packet through the tunnel (encrypts and sends via UDP).
Sourcepub async fn run_receive_loop(self: &Arc<Self>) -> Result<()>
pub async fn run_receive_loop(self: &Arc<Self>) -> Result<()>
Run the tunnel’s receive loop (listens for UDP packets and decrypts them).
Sourcepub async fn run_send_loop(self: &Arc<Self>) -> Result<()>
pub async fn run_send_loop(self: &Arc<Self>) -> Result<()>
Run the tunnel’s send loop (encrypts and sends IP packets).
Sourcepub async fn run_timer_loop(self: &Arc<Self>) -> Result<()>
pub async fn run_timer_loop(self: &Arc<Self>) -> Result<()>
Run the tunnel’s timer loop (handles keepalives and handshake retries).
Sourcepub async fn wait_for_handshake(&self, timeout_duration: Duration) -> Result<()>
pub async fn wait_for_handshake(&self, timeout_duration: Duration) -> Result<()>
Wait for the handshake to complete (with timeout).
Auto Trait Implementations§
impl !Freeze for WireGuardTunnel
impl !RefUnwindSafe for WireGuardTunnel
impl Send for WireGuardTunnel
impl Sync for WireGuardTunnel
impl Unpin for WireGuardTunnel
impl UnsafeUnpin for WireGuardTunnel
impl !UnwindSafe for WireGuardTunnel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more