Skip to main content

CoreStack

Struct CoreStack 

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

Internally i/o free userspace network stack built around smoltcp.

Implementations§

Source§

impl Netstack

Source

pub fn new(ns_config: Config, now: Instant) -> Netstack

Construct a netstack with the given config and starting instant.

§Panics

If ns_config.loopback is set and smoltcp’s iface-max-addr-count (feature flag) is less than 2.

Source

pub fn poll_at(&mut self, now: Instant) -> Option<Instant>

Report the next time the netstack should be polled.

Source

pub fn poll_delay(&mut self, now: Instant) -> Option<Duration>

Report the amount of time until the netstack should next be polled.

Source

pub fn process_cmds(&mut self)

Process all commands available in the command queue.

Source

pub fn wait_for_cmd_blocking( &mut self, timeout: Option<Duration>, ) -> Result<Request, RecvTimeoutError>

Synchronously block for a single command over the channel.

Source

pub fn wait_for_cmd(&self) -> impl Future<Output = Option<Request>> + use<>

Asynchronously wait for a single command over the channel.

Source

pub fn direct_set_ips(&mut self, ips: impl IntoIterator<Item = IpAddr>) -> bool

Set the IP addresses for this interface.

Loopback addresses are automatically appended if indicated by Config::loopback.

The return value reports whether the operation was successful: if not, it was because there wasn’t enough storage configured in smoltcp’s feature flags for the number of submitted interface IPs.

Source

pub fn process_one_cmd(&mut self, _: Request)

Process a single command.

Source

pub fn poll_device_io(&mut self, now: Instant, dev: &mut impl Device) -> bool

Poll the lower device to send and receive packets, and attempt to complete any blocked socket commands.

Returns whether there were any updates to socket state.

Source

pub fn poll_device_ingress_async( &mut self, cx: &mut Context<'_>, now: Instant, dev: Pin<&mut (impl AsyncWakeDevice + Device + Unpin)>, ) -> Poll<bool>

Poll the device for all synchronously-available packets and process them.

The return value indicates whether packets were consumed and if sockets made progress:

  • Poll::Pending: no packets were processed because we were waiting for them to arrive from `dev.
  • Poll::Ready(false): we received packets but socket state did not make progress
  • Poll::Ready(true): we received packets and socket state did make progress

When this function returns, it is guaranteed that all packets currently available to receive from dev have been processed.

Unlike the synchronous poll_device_io, this does not call drain_tcp_closes: the async driver loop (the netstack Future’s poll) owns that, calling it once per poll after both ingress and egress have run (so a socket smoltcp drove to Closed here — which always reports Poll::Ready(true) — is reaped in the same poll cycle). A future caller that drives this method outside that loop must call drain_tcp_closes itself, or autonomously-Closed sockets will linger in pending_tcp_closes until the next drain.

Source

pub fn poll_device_egress_async( &mut self, cx: &mut Context<'_>, now: Instant, dev: Pin<&mut (impl AsyncWakeDevice + Device + Unpin)>, ) -> Poll<bool>

Send all packets the netstack wants to transmit on the network.

Returns:

  • Poll::Pending if no packets could be sent because dev wasn’t ready (if AsyncWakeDevice::poll_tx returns Poll::Pending)
  • Poll::Ready(false) if dev was ready but no packets needed to be sent
  • Poll::Ready(true) if dev was ready and packets were sent
Source

pub fn wait_io_async<'stack, 'dev, D>( &'stack mut self, now: Instant, dev: &'dev mut D, ) -> IoPoller<'stack, 'dev, D>

Attempt to send and receive packets on dev.

The future becomes ready when dev sends or receives packets on the network. All synchronously-available network I/O is always performed.

Assumes that alarms are handled separately and that now does not advance over the course of the polled future.

Trait Implementations§

Source§

impl HasChannel for Netstack

Source§

fn borrow_channel(&self) -> impl Borrow<WeakSender<Request>> + Send

Retrieve a Channel borrow. Read more
Source§

fn command_channel(&self) -> WeakSender<Request>

Clone a new command channel.
Source§

fn request_blocking( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> Result<Response, ChannelClosedError>

Send a request through the channel. Read more
Source§

fn request( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> impl Future<Output = Result<Response, Error>> + Send

Asynchronously send a request through the channel. Read more
Source§

fn request_nonblocking( &self, handle: Option<SocketHandle>, command: impl Into<Command>, ) -> Result<(), ChannelClosedError>

Send a nonblocking request, discarding any response. Read more

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> CreateSocket for T
where T: HasChannel + Sync,

Source§

fn udp_bind_blocking(&self, endpoint: SocketAddr) -> Result<UdpSocket, Error>

Create and bind a new UdpSocket to the given local endpoint.
Source§

async fn udp_bind(&self, endpoint: SocketAddr) -> Result<UdpSocket, Error>

Asynchronously create and bind a new UdpSocket to the given local endpoint.
Source§

fn tcp_listen_blocking( &self, local_endpoint: SocketAddr, ) -> Result<TcpListener, Error>

Create a new TcpListener on the given endpoint.
Source§

async fn tcp_listen( &self, local_endpoint: SocketAddr, ) -> Result<TcpListener, Error>

Asynchronously create a new TcpListener on the given endpoint.
Source§

fn bound_tcp_ports_blocking(&self) -> Result<Vec<u16>, Error>

Snapshot the set of local ports that currently have an explicit TCP listener. Read more
Source§

async fn bound_tcp_ports(&self) -> Result<Vec<u16>, Error>

Asynchronously snapshot the set of local ports that currently have an explicit TCP listener. See CreateSocket::bound_tcp_ports_blocking.
Source§

fn tcp_connect_blocking( &self, local_endpoint: SocketAddr, remote_endpoint: SocketAddr, ) -> Result<TcpStream, Error>

Create a new TcpStream bound to the given local address and connected to the given remote. Read more
Source§

async fn tcp_connect( &self, local_endpoint: SocketAddr, remote_endpoint: SocketAddr, ) -> Result<TcpStream, Error>

Asynchronously create a new TcpStream bound to the given local address and connected to the given remote. Read more
Source§

fn raw_open_blocking( &self, ipv4: bool, ip_protocol: Protocol, ) -> Result<RawSocket, Error>

Create a new RawSocket on the selected ip version and protocol. Read more
Source§

async fn raw_open( &self, ipv4: bool, ip_protocol: Protocol, ) -> Result<RawSocket, Error>

Asynchronously create a new RawSocket on the selected ip version and protocol. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NetstackControl for T
where T: HasChannel,

Source§

fn set_ips_blocking( &self, ips: impl IntoIterator<Item = IpAddr>, ) -> Result<(), Error>

Set the IPs for the netstack interface. Read more
Source§

fn set_ips( &self, ips: impl IntoIterator<Item = IpAddr>, ) -> impl Future<Output = Result<(), Error>> + Send

Set the IPs for the netstack interface. Read more
Source§

fn set_any_ip_blocking(&self, enabled: bool) -> Result<(), Error>

Enable or disable “any-IP” acceptance on the netstack interface. Read more
Source§

fn set_any_ip( &self, enabled: bool, ) -> impl Future<Output = Result<(), Error>> + Send

Enable or disable “any-IP” acceptance on the netstack interface. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more