NetCmd

Enum NetCmd 

Source
pub enum NetCmd {
    Stop,
    BindListener(String, Sender<NetCmd>),
    BindUdpListener(String, Sender<NetCmd>),
    NewConn(usize, String, String, usize),
    BindConn(usize, Sender<NetCmd>),
    CloseConn(usize),
    RecvBytes(usize, Vec<u8>),
    RecvPkt(usize, String, String, Vec<u8>),
    SendBytes(usize, Vec<u8>),
    SendPkt(usize, String, Vec<u8>),
    SendReady(usize, usize),
}
Expand description

This is where d3 meets Tcp or UDP. The Network leans heavily upon Mio to provide the foundation for interacting with the network. The d3 network provides an additional abstraction to adapt it for d3 machines and encapsulate Mio.

This sequence diagram illustrates a machine, Alice asking for a TCP listener to be installed. When there is a connection, the network is told to send control and data commands to the machine Bob.

+-------+                                             +-----+                        +-----+
| Alice |                                             | Net |                        | Bob |
+-------+                                             +-----+                        +-----+
   |                                                    |                              |
   | BindListner(addres, Alice:sender)                  |                              |
   |--------------------------------------------------->|                              |
   | -------------------------------\                   |                              |
   |-| Alice waits for a connection |                   |                              |
   | |------------------------------|                   |                              |
   |                                                    |                              |
   |    NewConn(conn_id, local, remote, write_buf_size) |                              |
   |<---------------------------------------------------|                              |
   | ----------------------------------\                |                              |
   |-| Alice is told of the connection |                |                              |
   | | and has Bob handle it           |                |                              |
   | |---------------------------------|                |                              |
   | BindConn(conn_id, Bob:sender)                      |                              |
   |--------------------------------------------------->|                              |
   |                                                    |      ----------------------\ |
   |                                                    |      | Bob waits for bytes |-|
   |                                                    |      |---------------------| |
   |                                                    |                              |
   |                                                    | RecvBytes(conn_id, bytes)    |
   |                                                    |----------------------------->|
   |                                                    |     -----------------------\ |
   |                                                    |     | Bob sends some bytes |-|
   |                                                    |     |----------------------| |
   |                                                    |                              |
   |                                                    |    SendBytes(conn_id, bytes) |
   |                                                    |<-----------------------------|
   |                                                    |    ------------------------\ |
   |                                                    |    | Bob may be told how   |-|
   |                                                    |    | much more he can send | |
   |                                                    |    |-----------------------| |
   |                                                    | SendReady(write_buf_size)    |
   |                                                    |----------------------------->|
   |                                                    |----------------------------\ |
   |                                                    || Bob Closes the connection |-|
   |                                                    ||---------------------------| |
   |                                                    |                              |
   |                                                    |               Close(conn_id) |
   |                                                    |<-----------------------------|
   |                                                    |                              |

UDP is a bit simpler, as illusted by the following sequence diagram. Alice asks the network to bind a UDP address. Whenever a packet arrives it is sent to Alice. Alice can send a packet to the network too. Although there isn’t a connection, in the network sense, a conn_id is used, for both parity and as a shorthand for the local address.

+-------+                                    +-----+
| Alice |                                    | Net |
+-------+                                    +-----+
    |                                           |
    | BindUdpListener(address, Alice:sender)    |
    |------------------------------------------>|
    | ------------------------------\           |
    |-| Wait for a packet to arrive |           |
    | |-----------------------------|           |
    |                                           |
    |    RecvPkt(conn_id, local, remote, bytes) |
    |<------------------------------------------|
    | -----------------------\                  |
    |-| Alice sends a packet |                  |
    | |----------------------|                  |
    |                                           |
    | SendPkt(conn_id, remote, bytes)           |
    |------------------------------------------>|
    |                                           |

Variants§

§

Stop

Stop the network. Stop is used in conjuntion with starting and stopping the Server and Network.

§

BindListener(String, Sender<NetCmd>)

Binds a TCP listener to an address, notifying the sender when a connection is accepted.

§

BindUdpListener(String, Sender<NetCmd>)

Bind a UDP listener to an address, notifying the sender when a connection is accepted.

§

NewConn(usize, String, String, usize)

New connection notification (connection_id, bind_addr, connect_from, max_byte) are sent to the sender regitered via the BindListener.

§

BindConn(usize, Sender<NetCmd>)

BindConn starts the flow of information (connection_id, sender) between the network and a sender.

§

CloseConn(usize)

When sent to the network, CloseConn closes the connection, also known as a local close. When received by the BindConn listener, CloseConn is notification that the connection has been closed, also known as a remote close.

§

RecvBytes(usize, Vec<u8>)

Sent to the BindConn sender, RecvBytes provides bytes read from the connection.

§

RecvPkt(usize, String, String, Vec<u8>)

Sent to UDP listener socket id, destination, source, bytes

§

SendBytes(usize, Vec<u8>)

Sent to the network, SendBytes provides bytes to be written to the network.

§

SendPkt(usize, String, Vec<u8>)

Send UDP packet to network socket id, destination, bytes

§

SendReady(usize, usize)

Sent to the BindConn sender, it provides an update to the number of bytes available for writing to the network. A use case for this would be providing feedback for throttling data being generated for a connection.

Trait Implementations§

Source§

impl Debug for NetCmd

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for NetCmd

§

impl !RefUnwindSafe for NetCmd

§

impl Send for NetCmd

§

impl Sync for NetCmd

§

impl Unpin for NetCmd

§

impl !UnwindSafe for NetCmd

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.