weida

GitHub crates.io

Connection statistics and peer events

Rendered from docs/c/stats.md at 92c768a

Contents
  1. weida_connection_stats
  2. weida_peer_events (a try handle, R3a)
  3. weida_peer_event
  4. Constants

The stats area (0045 §5): what a requester knows about its connections, read as values, and the transitions of its dialled addresses, read from a queue (decision 10). Every function is callable from any thread (R5); every int function can also return -WEIDA_EINVAL and -WEIDA_EPANIC. Durations are microseconds (R7).

weida_connection_stats

One snapshot of weida_requester_connection_stats (requester.md): one record per live dialled address, in dial order, copied at the call; a record is read by its index, 0 to weida_connection_stats_len - 1. No record carries an address: the dialled URL is the only label (0036 §4.4).

FunctionReturns
size_t weida_connection_stats_len(const weida_connection_stats *s)the number of records; 0 for NULL
const char *weida_connection_stats_url(const weida_connection_stats *s, size_t index, size_t *len_out)the URL the record was dialled as, exactly as given to weida_requester_connect; NULL past the end. Lives as long as s
int weida_connection_stats_<field>(const weida_connection_stats *s, size_t index, uint64_t *out)1 and *out when present; 0 past the end, for a NULL argument, or when the record does not carry it (R2)
void weida_connection_stats_drop(weida_connection_stats *s)—
<field>Rust fieldAbsent when
age_usage (µs)never, within len
redialsredialsnever, within len
transport_path_rtt_ustransport.path.rtt (µs)the transport is local
transport_path_min_rtt_ustransport.path.min_rtt (µs)the transport is local
transport_path_cwndtransport.path.cwndthe transport is local
transport_path_congestion_eventstransport.path.congestion_eventsthe transport is local
transport_path_lost_packetstransport.path.lost_packetsthe transport is local
transport_path_lost_bytestransport.path.lost_bytesthe transport is local
transport_path_sent_packetstransport.path.sent_packetsthe transport is local
transport_path_current_mtutransport.path.current_mtuthe transport is local
transport_path_max_datagram_sizetransport.path.max_datagram_sizethe transport is local, or the peer accepts no datagram
transport_tx_datagramstransport.tx.datagramsthe transport is local
transport_tx_bytestransport.tx.bytesthe transport is local
transport_rx_datagramstransport.rx.datagramsthe transport is local
transport_rx_bytestransport.rx.bytesthe transport is local
remote_rtt_usremote.rtt (µs)no record from the peer yet, a local transport, or path_report off on either side
remote_min_rtt_usremote.min_rtt (µs)no record from the peer yet, a local transport, or path_report off on either side
remote_cwndremote.cwndno record from the peer yet, a local transport, or path_report off on either side
remote_congestion_eventsremote.congestion_eventsno record from the peer yet, a local transport, or path_report off on either side
remote_lost_packetsremote.lost_packetsno record from the peer yet, a local transport, or path_report off on either side
remote_lost_bytesremote.lost_bytesno record from the peer yet, a local transport, or path_report off on either side
remote_sent_packetsremote.sent_packetsno record from the peer yet, a local transport, or path_report off on either side
remote_current_mturemote.current_mtuno record from the peer yet, a local transport, or path_report off on either side
remote_tx_datagramsremote.tx.datagramsno record from the peer yet, a local transport, or path_report off on either side
remote_tx_bytesremote.tx.bytesno record from the peer yet, a local transport, or path_report off on either side
remote_rx_datagramsremote.rx.datagramsno record from the peer yet, a local transport, or path_report off on either side
remote_rx_bytesremote.rx.bytesno record from the peer yet, a local transport, or path_report off on either side
remote_age_usremote.age (µs)no record from the peer yet, a local transport, or path_report off on either side

weida_peer_events (a try handle, R3a)

FunctionBlocksReturns
int weida_peer_events_fd(const weida_peer_events *e, int64_t *out)never0; -WEIDA_EIO
int weida_peer_events_recv(const weida_peer_events *e, int64_t timeout_ms, weida_peer_event **out)up to timeout_ms0 and the next event; 0 with *out == NULL once the requester, or the relayed binding's registration, is gone; -WEIDA_EAGAIN, -WEIDA_EINTR, -WEIDA_ECLOSED
void weida_peer_events_drop(weida_peer_events *e)never—

Each weida_requester_events or weida_binding_relay_events call is an independent reader that sees every event from then on. The queue holds 64 events; a reader that falls further behind gets one WEIDA_PEER_EVENT_MISSED event carrying how many it lost. Dropping a reader ends a thread waiting in recv with -WEIDA_ECLOSED.

weida_peer_event

FunctionReturns
int weida_peer_event_kind(const weida_peer_event *e)the kind, a WEIDA_PEER_EVENT_* constant
const char *weida_peer_event_url(const weida_peer_event *e, size_t *len_out)the address as dialled; NULL for MISSED. Lives as long as e
const char *weida_peer_event_peer_fingerprint(const weida_peer_event *e, size_t *len_out)CONNECTED: the fingerprint (sha256: text) the peer proved; NULL for an anonymous peer or a local principal
int weida_peer_event_cause(const weida_peer_event *e, int *out)LOST: 1 and the WEIDA_LOSS_* cause
int weida_peer_event_attempt(const weida_peer_event *e, uint32_t *out)RETRYING: 1 and which attempt since the last connection that stayed up, from 1
int weida_peer_event_delay_us(const weida_peer_event *e, uint64_t *out)RETRYING: 1 and the wait before it, in microseconds
int weida_peer_event_why(const weida_peer_event *e, int *out)GAVE_UP: 1 and why, a WEIDA_GIVE_UP_* constant
int weida_peer_event_why_attempts(const weida_peer_event *e, uint32_t *out)GAVE_UP for POLICY: 1 and the redials attempted after the loss
const char *weida_peer_event_why_presented(const weida_peer_event *e, size_t *len_out)GAVE_UP for PEER_CHANGED: the fingerprint that answered instead; NULL when it proved none
const char *weida_peer_event_why_message(const weida_peer_event *e, size_t *len_out)GAVE_UP for FAILED: why the redial could not be used
int weida_peer_event_missed(const weida_peer_event *e, uint64_t *out)MISSED: 1 and how many events this reader lost
void weida_peer_event_drop(weida_peer_event *e)—

A getter of another kind's field reads absent: 0, or NULL.

Constants

Rust typeConstants, value
PeerEventWEIDA_PEER_EVENT_CONNECTED 0, _LOST 1, _RETRYING 2, _GAVE_UP 3, _MISSED 4
GiveUpWEIDA_GIVE_UP_POLICY 0, _PEER_CHANGED 1, _FAILED 2