Skip to main content

NetStack

Struct NetStack 

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

A userspace TCP/IP network stack.

Implementations§

Source§

impl NetStack

Source

pub fn new(wg_tunnel: Arc<WireGuardTunnel>) -> Arc<Self>

Create a new network stack backed by a WireGuard tunnel.

Source

pub fn create_tcp_socket(&self) -> SocketHandle

Create a new TCP socket and return its handle.

Source

pub fn connect(&self, handle: SocketHandle, addr: SocketAddr) -> Result<()>

Connect a TCP socket to the given address.

Source

pub fn is_connected(&self, handle: SocketHandle) -> bool

Check if a TCP socket is connected.

Source

pub fn can_send(&self, handle: SocketHandle) -> bool

Check if a TCP socket can send data.

Source

pub fn can_recv(&self, handle: SocketHandle) -> bool

Check if a TCP socket can receive data.

Source

pub fn may_send(&self, handle: SocketHandle) -> bool

Check if a TCP socket may send data (connection in progress or established).

Source

pub fn may_recv(&self, handle: SocketHandle) -> bool

Check if a TCP socket may receive data.

Source

pub fn socket_state(&self, handle: SocketHandle) -> TcpState

Get the TCP socket state.

Source

pub fn send(&self, handle: SocketHandle, data: &[u8]) -> Result<usize>

Send data on a TCP socket.

Source

pub fn recv(&self, handle: SocketHandle, buffer: &mut [u8]) -> Result<usize>

Receive data from a TCP socket.

Source

pub fn close(&self, handle: SocketHandle)

Close a TCP socket.

Source

pub fn remove_socket(&self, handle: SocketHandle)

Remove a socket from the socket set.

Source

pub fn poll(&self) -> bool

Poll the network stack, processing packets and updating socket states. Returns true if there was any activity.

Source

pub fn push_rx_packet(&self, packet: BytesMut)

Push a received packet (from WireGuard) into the network stack.

Source

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

Run the network stack polling loop.

Source

pub async fn run_rx_loop(self: &Arc<Self>, rx: Receiver<BytesMut>) -> Result<()>

Run the receive loop that takes packets from WireGuard and feeds them to the stack.

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