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: InstantLast time we received a packet from this client
last_sent: InstantLast time we sent a packet to this client
remote_address: SocketAddrThe address of the remote endpoint
Implementations§
Source§impl VirtualConnection
impl VirtualConnection
Sourcepub fn new(
addr: SocketAddr,
config: &Config,
time: Instant,
) -> VirtualConnection
pub fn new( addr: SocketAddr, config: &Config, time: Instant, ) -> VirtualConnection
Creates and returns a new Connection that wraps the provided socket address
Sourcepub fn record_send(&mut self) -> bool
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.
Sourcepub fn record_recv(&mut self) -> bool
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.
Sourcepub fn is_established(&self) -> bool
pub fn is_established(&self) -> bool
Returns if the connection has been established
Sourcepub fn packets_in_flight(&self) -> u16
pub fn packets_in_flight(&self) -> u16
Returns the current number of not yet acknowledged packets
Sourcepub fn last_heard(&self, time: Instant) -> Duration
pub fn last_heard(&self, time: Instant) -> Duration
Returns a Duration representing the interval since we last heard from the client
Sourcepub fn last_sent(&self, time: Instant) -> Duration
pub fn last_sent(&self, time: Instant) -> Duration
Returns a Duration representing the interval since we last sent to the client
Sourcepub fn process_outgoing<'a>(
&mut self,
packet: PacketInfo<'a>,
last_item_identifier: Option<u16>,
time: Instant,
) -> Result<OutgoingPackets<'a>>
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.
Sourcepub fn process_incoming(
&mut self,
received_data: &[u8],
time: Instant,
) -> Result<IncomingPackets>
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.
Sourcepub fn gather_dropped_packets(&mut self) -> Vec<SentPacket>
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
impl Connection for VirtualConnection
Source§type ReceiveEvent = SocketEvent
type ReceiveEvent = SocketEvent
Defines a connection event type.
Source§fn create_connection(
messenger: &mut impl ConnectionMessenger<Self::ReceiveEvent>,
address: SocketAddr,
time: Instant,
) -> VirtualConnection
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
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
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,
)
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,
)
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,
)
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.