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:
- Acknowledgement when packets are received
- Packet fragmentation and reassembly
- RTT, jitter and packet loss estimates
- 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
s1is greater thans2, taking wrap-around into account. - sequence_
less_ than - Returns true if sequence number
s1is less thans2, taking wrap-around into account.