rtciv0.5.0

rtci-shared

Shared types of a sans-I/O WebRTC stack: marshalling traits, transport context, replay detection, the stream transport interface. 15 public modules, 97 items at 0.5.0.

README

What every crate of the workspace shares: the Marshal / Unmarshal / MarshalSize traits, the common error type, TransportContext and the tagged message types that carry a datagram with its addresses, replay detection, network interface listing, and the stream transport interface (stream): connection ids, the commands a driver carries out, RFC 4571 and TURN framing of arbitrarily segmented reads, an optional TLS layer and back-pressure.

Specifications

  • RFC 4571, framing RTP and RTCP over connection-oriented transport
  • RFC 8656 section 11.5, ChannelData framing over TCP
  • RFC 8305, Happy Eyeballs, as the stream interface's connection race uses it

Clause-by-clause status, with the test that proves each clause: rfc4571, rfc8305.

Use

Other crates use it directly; an application meets it as rtci::shared (the root crate re-exports it): TaggedBytesMut and TransportContext in its event loop, and stream::{StreamCommand, StreamEvent} when it drives the engine's TCP. Features: marshal, replay, ifaces (all default).

Sans-I/O

Types and codecs only. ifaces lists the host's interfaces when asked; nothing else touches the operating system or reads a clock.

Licence

Licensed under either of the MIT licence or the Apache License, Version 2.0, at your option.

This crate is part of the rtci workspace, which descends from webrtc-rs/rtc and is developed independently; FORK.md lists what it carries over upstream. Upstream's licence and copyright notices are retained.

rtci_shared

Shared types and utilities for the Sans-I/O WebRTC stack.

  • moderrorThe crate-wide error type shared by every protocol in the stack.
  • modifacescfg(feature = "ifaces")Local network interface enumeration, used to gather ICE host candidates.
  • modmarshalcfg(feature = "marshal")The wire-format traits every protocol codec in the stack implements.
  • modreplay_detectorcfg(feature = "replay")Replay protection for sequence-numbered packets, as DTLS and SRTP require.
  • modserdeserde helpers for types that have no natural serialized form, such as std::time::Instant.
  • modstreamStream transports (TCP, and TLS over TCP) for a sans-I/O engine.
  • modtcp_framingTCP framing utilities for ICE over TCP (RFC 4571/RFC 6544).
  • modtimeConversions between monotonic, Unix and NTP time.
  • modturn_framingSplitting a TURN byte stream back into messages (RFC 8656 §12.5).
  • modutilSmall shared helpers: packet demultiplexing predicates and random-string generation.
  • structFiveTuplefrom transport::FiveTupleFive Tuple consists of local address, peer address and protocol
  • structFourTuplefrom transport::FourTupleFour Tuple consists of local address and peer address
  • structTransportContextfrom transport::TransportContextTransport Context with local address, peer address, ECN, protocol, etc.
  • structTransportMessagefrom transport::TransportMessageA generic transmit with TransportContext
  • enumEcnCodepointfrom transport::EcnCodepointExplicit congestion notification codepoint (RFC 3168 section 5): the low two bits of the IPv4 TOS byte or the IPv6 Traffic Class. Not-ECT (00) is the absence of one, None.
  • enumTransportProtocolfrom transport::TransportProtocolType of transport protocol, either UDP or TCP
  • typeTaggedBytesMutfrom transport::TaggedBytesMutBytesMut type transmit with TransportContext

rtci_shared::ifacescfg(feature = "ifaces")

Local network interface enumeration, used to gather ICE host candidates.

  • modffiPlatform-specific interface enumeration (FFI into the OS).
  • structInterfaceOne address on one local network interface.
  • enumKindThe address family or link type an Interface entry describes.
  • enumNextHopThe next hop configured for an interface address.
  • useifacesfrom ffi::ifacesEnumerates local network interfaces.
  • usetemporary_ipv6_addressesfrom ffi::temporary_ipv6_addressesThe local IPv6 addresses the operating system flags as RFC 4941 temporary addresses: not read on this platform, always ErrorKind::Unsupported.

rtci_shared::ifaces::ffi

Platform-specific interface enumeration (FFI into the OS).

  • fnifacescfg(target_family = "windows")from self::windows::ifacesQuery the local system for all interface addresses.
  • fnifacescfg(target_family = "unix")from self::unix::ifacesQuery the local system for all interface addresses.
  • fnifacescfg(not(any(target_family = "windows", target_family = "unix")))Enumerates local network interfaces.
  • fntemporary_ipv6_addressescfg(target_family = "windows")from self::windows::temporary_ipv6_addressesThe local IPv6 addresses the operating system reports as RFC 4941 temporary addresses: none, on Windows. Always ErrorKind::Unsupported, so nothing is marked and every address stays hidden behind its mDNS name.
  • fntemporary_ipv6_addressescfg(target_family = "unix")from self::unix::temporary_ipv6_addressesThe local IPv6 addresses the operating system flags as RFC 4941 temporary addresses.
  • fntemporary_ipv6_addressescfg(not(any(target_family = "windows", target_family = "unix")))The local IPv6 addresses the operating system flags as RFC 4941 temporary addresses: not read on this platform, always ErrorKind::Unsupported.

rtci_shared::marshalcfg(feature = "marshal")

The wire-format traits every protocol codec in the stack implements.

  • traitMarshalEncodes a value into its wire format.
  • traitMarshalSizeThe encoded size of a value, in bytes.
  • traitUnmarshalDecodes a value from its wire format.

rtci_shared::replay_detectorcfg(feature = "replay")

Replay protection for sequence-numbered packets, as DTLS and SRTP require.

rtci_shared::error

The crate-wide error type shared by every protocol in the stack.

  • structIoErrorWrapper around std::io::Error that implements PartialEq.
  • structStdErrorAn escape hatch to preserve stack traces for errors whose concrete type is unknown.
  • enumErrorUnified error type for all WebRTC sub-protocols.
  • fnflatten_errsFlattens a list of errors into a single enum@Error, joining their messages with newlines.
  • typeResultA type alias for std::result::Result with this crate's enum@Error type.

rtci_shared::serde

serde helpers for types that have no natural serialized form, such as std::time::Instant.

  • modinstant_to_epochSerializes a SystemInstant as epoch time in milliseconds, an f64 with sub-millisecond precision: W3C stats timestamps are DOMHighResTimeStamps, milliseconds that "SHOULD be accurate to 5 microseconds".

rtci_shared::serde::instant_to_epoch

Serializes a SystemInstant as epoch time in milliseconds, an f64 with sub-millisecond precision: W3C stats timestamps are DOMHighResTimeStamps, milliseconds that "SHOULD be accurate to 5 microseconds".

  • fndeserializeDeserializes an SystemInstant from the relative offset written by serialize.
  • fnserializeSerializes an SystemInstant as a duration relative to the process's reference instant.

rtci_shared::stream

Stream transports (TCP, and TLS over TCP) for a sans-I/O engine.

  • modhappy_eyeballsHappy Eyeballs (RFC 8305) for a sans-I/O engine: the order in which a server's addresses are tried and when the next attempt starts. The driver resolves names (StreamCommand::Resolve), answering both families at once (StreamEvent::Resolved) or each as it arrives (StreamEvent::ResolvedFamily); the engine sorts and staggers the attempts with HappyEyeballs and keeps the first that …
  • modnat64NAT64 for the Happy Eyeballs engine on an IPv6-only network (RFC 8305 section 7, RFC 8445 section 5.1.1.2): the prefix the network's NAT64 uses is discovered with RFC 7050 (the AAAA records of IPV4ONLY_ARPA, which a DNS64 resolver synthesizes from its well-known IPv4 addresses), and IPv4 addresses are written into IPv6 ones with that prefix as RFC 6052 section 2.2 has it.
  • structListenerIdA listening socket, as the engine names it in StreamCommand::Listen.
  • structStreamConfigLimits of a StreamTable.
  • structStreamDecoderSplits a byte stream of one Framing back into its messages. Bytes can be fed in any segmentation; memory stays bounded by two messages whatever the read size, because input is taken a message's worth at a time and drained in between.
  • structStreamIdA connection, as the engine names it. Every id is allocated by the engine: for a connection it asks for in StreamCommand::Connect, and for one the driver accepted, by StreamTable::accept. Ids are never reused.
  • structStreamInfoA connection, as StreamTable::info describes it.
  • structStreamTableThe engine's side of its stream transports: listeners, connections, framing, the optional security layer and back-pressure. See the module documentation.
  • structStreamTransmitBytes to write on a connection, after every earlier transmit of the same connection.
  • enumDnsRecordA DNS record, as the driver reports it (StreamEvent::ResolvedRecords).
  • enumFramingHow messages are delimited on a connection.
  • enumRecordKindA DNS record type the engine asks for (StreamCommand::ResolveRecords).
  • enumStreamCommandWhat the engine asks the driver to do with its sockets.
  • enumStreamEventWhat the driver tells the engine about its sockets.
  • enumStreamNoticeWhat a StreamTable reports to its owner, in the order it happened.
  • enumStreamOriginHow a connection came to be.
  • enumStreamStateWhere a connection is in its life.
  • traitStreamLayerA security layer between the framing and the socket: TLS for TURN over TLS, in its sans-I/O form. Ciphertext comes in with receive, plaintext goes out with send once the handshake is done, and the table collects what the layer has to write after every call.
  • constRECORDS_TIMEOUTHow long the engine waits for a StreamCommand::ResolveRecords answer before it takes the name's addresses instead (a driver that does not look records up).

rtci_shared::stream::happy_eyeballs

Happy Eyeballs (RFC 8305) for a sans-I/O engine: the order in which a server's addresses are tried and when the next attempt starts. The driver resolves names (StreamCommand::Resolve), answering both families at once (StreamEvent::Resolved) or each as it arrives (StreamEvent::ResolvedFamily); the engine sorts and staggers the attempts with HappyEyeballs and keeps the first that …

  • structAddressHistoryWhat attempts on a server's addresses came to, for the order of later attempts (RFC 8305 section 4): "If the client is stateful and has a history of expected round-trip times (RTTs) for the routes to access each address, it SHOULD add a Destination Address Selection rule between rules 8 and 9 that prefers addresses with lower RTTs. If the client keeps track of which addresses it used in the …
  • structAddressRankWhat the history says of one address, for the order of the attempts (AddressHistory::rank): lower first. The default (nothing known) sorts after an address that answered and before one whose last attempt failed.
  • structHappyEyeballsOne Happy Eyeballs race over sorted addresses: next_attempt says which address to try when, a failure moves to the next at once, the first success ends it (the attempts still running are to be cancelled, the rest ignored).
  • fnsort_addressesRFC 8305 section 4: addresses interleaved by family, the preferred family first ("First Address Family Count" of one), each family keeping its own order. IPv6 is preferred, as the RFC's default; duplicates are dropped.
  • fnsort_addresses_rankedAs sort_addresses, each family ordered first by rank (lower first; the given order among equal ranks).
  • constCONNECTION_ATTEMPT_DELAYRFC 8305 section 8: the recommended Connection Attempt Delay.
  • constMAX_CONNECTION_ATTEMPT_DELAYRFC 8305 section 5: the upper bound of the delay ("Maximum Connection Attempt Delay").
  • constMIN_CONNECTION_ATTEMPT_DELAYRFC 8305 section 5: an attempt never starts within 10 ms of the previous one.
  • constRESOLUTION_DELAYRFC 8305 section 8: the recommended Resolution Delay, how long an IPv4 answer waits for the IPv6 one before the race starts on it.

rtci_shared::stream::nat64

NAT64 for the Happy Eyeballs engine on an IPv6-only network (RFC 8305 section 7, RFC 8445 section 5.1.1.2): the prefix the network's NAT64 uses is discovered with RFC 7050 (the AAAA records of IPV4ONLY_ARPA, which a DNS64 resolver synthesizes from its well-known IPv4 addresses), and IPv4 addresses are written into IPv6 ones with that prefix as RFC 6052 section 2.2 has it.

  • structNat64PrefixA NAT64 prefix (RFC 6052 section 2.2): its first len bits are the network's.
  • fndiscover_prefixesRFC 7050 section 3: the NAT64 prefixes the AAAA answers for IPV4ONLY_ARPA show. Each IPv6 address is searched for one of the WELL_KNOWN_IPV4 addresses at each prefix length (longest first); an address that holds none is not a synthesized one and is ignored. Duplicates are dropped; the order of the answers is kept.
  • fnsynthesize_allRFC 8305 section 7.1: the IPv6 addresses synthesized for the IPv4 ones among addresses with each of prefixes, with their ports. "The synthesized addresses are then inserted into the list of addresses as if they were results from DNS queries".
  • constIPV4ONLY_ARPARFC 7050 section 2: the well-known name whose AAAA records a DNS64 resolver synthesizes.
  • constPREFIX_LENGTHSRFC 6052 section 2.2: the prefix lengths an IPv4-embedded IPv6 address may have.
  • constWELL_KNOWN_IPV4RFC 7050 section 2.2: the well-known IPv4 addresses of IPV4ONLY_ARPA.

rtci_shared::tcp_framing

TCP framing utilities for ICE over TCP (RFC 4571/RFC 6544).

  • structTcpFrameDecoderA stateful decoder for RFC 4571 framed TCP packets.
  • fnframe_packetAdds RFC 4571 framing header to a packet.
  • fnframe_packet_toAdds RFC 4571 framing header to a packet, writing into a provided buffer.
  • fntry_frame_packetLike frame_packet, without the panic: None when buf is longer than a frame can carry (MAX_FRAMED_PACKET_SIZE).
  • constDEFAULT_MAX_BUFFEREDWhat a TcpFrameDecoder holds at most by default: two whole frames, so a reader that takes every complete packet after each TcpFrameDecoder::push never reaches it, whatever its read size up to one frame.
  • constFRAMING_HEADER_LENLength of the framing header (2 bytes for length prefix).
  • constMAX_FRAMED_PACKET_SIZEMaximum packet size that can be framed (u16::MAX = 65535 bytes).

rtci_shared::time

Conversions between monotonic, Unix and NTP time.

  • structSystemInstantA monotonic Instant paired with the wall-clock time it was taken at.
  • fnnear_leap_secondWhether the NTP timestamp ntp falls where a positive leap second could make it ambiguous: the last second of the last day of a month (UTC) or the second after it.

rtci_shared::turn_framing

Splitting a TURN byte stream back into messages (RFC 8656 §12.5).

  • structTurnStreamDecoderSans-IO splitter for a TURN stream: push bytes as they arrive, pop whole messages. A message comes out exactly as it was on the wire, ChannelData padding included, which TURN's decoders accept.

rtci_shared::util

Small shared helpers: packet demultiplexing predicates and random-string generation.

  • fngenerate_crypto_random_stringGenerates a random n-character string drawn from runes.
  • fnis_rtcpReturns true if buf is RTCP rather than RTP.
  • fnlookup_hostlookup host to SocketAddr
  • fnmatch_dtlsMatchFuncs as described in RFC7983 <https://tools.ietf.org/html/rfc7983> +----------------+ | [0..3] -+--> forward to STUN | | | [16..19] -+--> forward to ZRTP | | packet --> | [20..63] -+--> forward to DTLS | | | [64..79] -+--> forward to TURN Channel | | | [128..191] -+--> forward to RTP/RTCP …
  • fnmatch_srtcpmatch_srtcp is a MatchFunc that only matches SRTCP and not SRTP
  • fnmatch_srtpmatch_srtp is a MatchFunc that only matches SRTP and not SRTCP
  • fnmatch_srtp_or_srtcpReturns true if b looks like SRTP or SRTCP: its first byte is in [128, 191].
  • fnmath_rand_alphamath_rand_alpha generates a mathematical random alphabet sequence of the requested length.
  • fnmath_rand_alpha_numbermath_rand_alpha generates a mathematical random alphabet and number sequence of the requested length.

Generated from the sources of rtci-shared 0.5.0 at its release tag. Items made by macros and methods are on docs.rs.