VirtualConnection

Struct VirtualConnection 

Source
pub struct VirtualConnection {
    pub last_heard: Instant,
    pub last_sent: Instant,
    pub remote_address: SocketAddr,
    /* private fields */
}
Expand description

Contains the information about a certain ‘virtual connection’ over udp. This connections also keeps track of network quality, processing packets, buffering data related to connection etc.

Fields§

§last_heard: Instant

Last time we received a packet from this client

§last_sent: Instant

Last time we sent a packet to this client

§remote_address: SocketAddr

The address of the remote endpoint

Implementations§

Source§

impl VirtualConnection

Source

pub fn new( addr: SocketAddr, config: &Config, time: Instant, ) -> VirtualConnection

Creates and returns a new Connection that wraps the provided socket address

Source

pub fn record_send(&mut self) -> bool

Records that this connection has sent a packet. Returns whether the connection has become acknowledged because of this send.

Source

pub fn record_recv(&mut self) -> bool

Records that this connection has sent a packet. Returns whether the connection has become acknowledged because of this send.

Source

pub fn is_established(&self) -> bool

Returns if the connection has been established

Source

pub fn packets_in_flight(&self) -> u16

Returns the current number of not yet acknowledged packets

Source

pub fn last_heard(&self, time: Instant) -> Duration

Returns a Duration representing the interval since we last heard from the client

Source

pub fn last_sent(&self, time: Instant) -> Duration

Returns a Duration representing the interval since we last sent to the client

Source

pub fn process_outgoing<'a>( &mut self, packet: PacketInfo<'a>, last_item_identifier: Option<u16>, time: Instant, ) -> Result<OutgoingPackets<'a>>

Pre-processes the given buffer to be sent over the network.

Source

pub fn process_incoming( &mut self, received_data: &[u8], time: Instant, ) -> Result<IncomingPackets>

Processes the incoming data and returns a packet once the data is complete.

Source

pub fn gather_dropped_packets(&mut self) -> Vec<SentPacket>

Gathers dropped packets from the acknowledgment handler.

Note that after requesting dropped packets the dropped packets will be removed from this client.

Trait Implementations§

Source§

impl Connection for VirtualConnection

Source§

type SendEvent = Packet

Defines a user event type.

Source§

type ReceiveEvent = SocketEvent

Defines a connection event type.

Source§

fn create_connection( messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>, address: SocketAddr, time: Instant, ) -> VirtualConnection

Creates new connection and initialize it by sending an connection event to the user.

  • address - defines a address that connection is associated with.
  • time - creation time, used by connection, so that it doesn’t get dropped immediately or send heartbeat packet.
  • initial_data - if initiated by remote host, this will hold that a packet data.
Source§

fn is_established(&self) -> bool

Connections are considered established once they both have had a send and a receive.

Source§

fn should_drop( &mut self, messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>, time: Instant, ) -> bool

Determines if the given Connection should be dropped due to its state.

Source§

fn process_packet( &mut self, messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>, payload: &[u8], time: Instant, )

Processes a received packet: parse it and emit an event.

Source§

fn process_event( &mut self, messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>, event: Self::SendEvent, time: Instant, )

Processes a received event and send a packet.

Source§

fn update( &mut self, messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>, time: Instant, )

Processes various connection-related tasks: resend dropped packets, send heartbeat packet, etc… This function gets called very frequently.

Source§

impl Debug for VirtualConnection

Source§

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

Formats the value using the given formatter. 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> 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, 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