Skip to main content

WireGuardTunnel

Struct WireGuardTunnel 

Source
pub struct WireGuardTunnel { /* private fields */ }
Expand description

A WireGuard tunnel that encrypts/decrypts IP packets.

Implementations§

Source§

impl WireGuardTunnel

Source

pub async fn new(config: WireGuardConfig) -> Result<Arc<Self>>

Create a new WireGuard tunnel with the given configuration.

Source

pub fn tunnel_ip(&self) -> Ipv4Addr

Get our tunnel IP address.

Source

pub fn mtu(&self) -> u16

Get the MTU for the tunnel.

Source

pub fn outgoing_sender(&self) -> Sender<BytesMut>

Get the sender for outgoing packets.

Source

pub fn take_incoming_receiver(&self) -> Option<Receiver<BytesMut>>

Get the receiver for incoming packets (takes ownership of the receiver).

Source

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.

Source

pub async fn initiate_handshake(&self) -> Result<()>

Initiate the WireGuard handshake.

Source

pub async fn send_ip_packet(&self, packet: BytesMut) -> Result<()>

Send an IP packet through the tunnel (encrypts and sends via UDP).

Source

pub async fn run_receive_loop(self: &Arc<Self>) -> Result<()>

Run the tunnel’s receive loop (listens for UDP packets and decrypts them).

Source

pub async fn run_send_loop(self: &Arc<Self>) -> Result<()>

Run the tunnel’s send loop (encrypts and sends IP packets).

Source

pub async fn run_timer_loop(self: &Arc<Self>) -> Result<()>

Run the tunnel’s timer loop (handles keepalives and handshake retries).

Source

pub async fn wait_for_handshake(&self, timeout_duration: Duration) -> Result<()>

Wait for the handshake to complete (with timeout).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V