pub struct SnapTunnel { /* private fields */ }Expand description
A SNAP tunnel connection.
A background driver task runs the WireGuard session. Once the driver stops the tunnel is closed
for good: receiving fails with SnapTunnelReceiveError::ReceiveQueueClosed and sending fails
with an io::ErrorKind::ConnectionReset error. See SnapTunnel::is_closed for when that
happens.
Implementations§
Source§impl SnapTunnel
impl SnapTunnel
Sourcepub async fn send(&self, packet: Packet) -> Result<()>
pub async fn send(&self, packet: Packet) -> Result<()>
Send a packet to the remote server.
While a handshake is in progress the packet is queued and sent when the handshake
completes. Fails with io::ErrorKind::ConnectionReset once the tunnel is closed.
Sourcepub fn try_send(&self, packet: Packet) -> Result<()>
pub fn try_send(&self, packet: Packet) -> Result<()>
Try to send a packet to the remote server. Returns error of try_send_to.
Fails with io::ErrorKind::ConnectionReset once the tunnel is closed.
Sourcepub async fn recv(&self) -> Result<Bytes, SnapTunnelReceiveError>
pub async fn recv(&self) -> Result<Bytes, SnapTunnelReceiveError>
Receive a packet from the remote server.
Fails with SnapTunnelReceiveError::ReceiveQueueClosed once the tunnel is closed.
Sourcepub fn try_recv(&self) -> Result<Option<Bytes>, SnapTunnelReceiveError>
pub fn try_recv(&self) -> Result<Option<Bytes>, SnapTunnelReceiveError>
Try to receive a packet from the remote server without blocking.
Returns Ok(None) if no packet is currently available.
Sourcepub fn poll_recv(
&self,
cx: &mut Context<'_>,
) -> Poll<Result<Bytes, SnapTunnelReceiveError>>
pub fn poll_recv( &self, cx: &mut Context<'_>, ) -> Poll<Result<Bytes, SnapTunnelReceiveError>>
Poll for a packet from the remote server.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Get the local socket address. Assigned by the remote server.
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Whether the tunnel is closed. A closed tunnel delivers nothing in either direction.
The tunnel closes when the driver stops. The driver stops when the consumer of the receive
queue is gone, when an expired session cannot be re-established within a fixed budget, when
a re-handshake fails permanently, or when a re-handshake assigns a different local address.
The last case happens after the local network changed, because the data plane derives the
address from the source address it observes. An application that wants to continue then
connects a new tunnel; see the rules on super::SnapTunEndpoint.
Sourcepub fn data_plane_address(&self) -> SocketAddr
pub fn data_plane_address(&self) -> SocketAddr
The data plane the tunnel is connected to.
Sourcepub fn discarded_datagrams(&self) -> u64
pub fn discarded_datagrams(&self) -> u64
Total number of outbound datagrams the underlay socket refused since the tunnel was created.
A refused datagram is dropped rather than retried, because retrying one the socket will
never accept blocks every packet queued behind it. The tunnel therefore stays up when
sending fails persistently, for example because the interface went down or a firewall
answers EPERM, and this counter is what tells such a tunnel apart from a healthy one.
Trait Implementations§
Source§impl Drop for SnapTunnel
impl Drop for SnapTunnel
Auto Trait Implementations§
impl !Freeze for SnapTunnel
impl !Unpin for SnapTunnel
impl !UnsafeUnpin for SnapTunnel
impl RefUnwindSafe for SnapTunnel
impl Send for SnapTunnel
impl Sync for SnapTunnel
impl UnwindSafe for SnapTunnel
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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