Skip to main content

Crate reliable

Crate reliable 

Source
Expand description

reliable is a simple packet acknowledgement system for UDP-based protocols.

It’s useful in situations where you need to know which UDP packets you sent were received by the other side.

It has the following features:

  1. Acknowledgement when packets are received
  2. Packet fragmentation and reassembly
  3. RTT, jitter and packet loss estimates
  4. Duplicate packets are detected and dropped

This crate is a faithful port of the C library reliable and is wire compatible with it.

§Usage

reliable is designed to operate with your own network socket library. Create one Endpoint per connection: a client has one, a server has one per client slot.

use reliable::{Config, Endpoint};

let mut endpoint = Endpoint::new(Config::default(), 0.0);

// sending hands the framed packet (or its fragments) to your transmit closure
endpoint.send_packet(&[1, 2, 3], |_sequence, data| {
    // send data over your UDP socket
});

// call this for each packet received from your UDP socket
endpoint.receive_packet(incoming, |_sequence, data| {
    // process the packet contents here.
    // return false if the packet should not be acked
    true
});

// once per-frame, update stats and process acks
endpoint.update(0.01);
for &acked_sequence in endpoint.acks() {
    // the packet you sent with this sequence number was received by the other side
}
endpoint.clear_acks();

Endpoint::drain_acks yields the acked sequence numbers and clears them in one call, if you prefer not to keep the two steps in sync.

In place of the C library’s process-wide log level and printf function, this crate logs through the log crate facade: install any logger implementation and enable the Debug level to see per-packet detail.

Structs§

Bandwidth
Bandwidth statistics, in kilobits per-second.
Config
Configuration for an Endpoint.
Counters
Counters tracked by an Endpoint.
Endpoint
A reliable endpoint.

Constants§

FRAGMENT_HEADER_BYTES
The size of a fragment header in bytes.
MAX_PACKET_HEADER_BYTES
The maximum size of a packet header in bytes.
VERSION
The version of the C library this crate is a port of (and wire compatible with).

Functions§

sequence_greater_than
Returns true if sequence number s1 is greater than s2, taking wrap-around into account.
sequence_less_than
Returns true if sequence number s1 is less than s2, taking wrap-around into account.