Expand description
STUN for the Sans-I/O WebRTC stack.
Session Traversal Utilities for NAT (RFC 5389, superseding RFC 3489), plus the attributes ICE (RFC 8445) and TURN (RFC 5766) layer on top. In WebRTC, STUN does double duty: it discovers a peer’s server-reflexive address, and its binding request/response exchange is the ICE connectivity check.
§Structure
message—Message, the STUN message itself: build one from attributes, marshal it, unmarshal one off the wire.attributes,textattrs,uattrs,xoraddr,error_code— the attribute types, includingXOR-MAPPED-ADDRESS,USERNAME,REALMandERROR-CODE.integrity,fingerprint—MESSAGE-INTEGRITY(HMAC-SHA1) andFINGERPRINT(CRC-32), the two attributes whose values depend on the encoded message.agent,client— transaction tracking and a Sans-I/O client for talking to a STUN server.uri— parsingstun:/stuns:URLs.checks— validation helpers for received messages.
§Example
use rtc_stun::attributes::ATTR_SOFTWARE;
use rtc_stun::message::{BINDING_REQUEST, Message, TransactionId};
use rtc_stun::textattrs::TextAttribute;
let mut msg = Message::new();
msg.build(&[
Box::new(TransactionId::new()),
Box::new(BINDING_REQUEST),
Box::new(TextAttribute::new(ATTR_SOFTWARE, "webrtc-rs".to_owned())),
])?;
// `build` encodes as it goes, so `raw` is ready to send.
assert!(!msg.raw.is_empty());
let mut decoded = Message::new();
decoded.raw = msg.raw.clone();
decoded.decode()?;
assert_eq!(decoded.typ, BINDING_REQUEST);Most applications do not depend on this crate directly — rtc-ice and
rtc-turn build on it, and the rtc crate drives those.
Modules§
- addr
- Socket-address helpers shared by the address attributes.
- agent
- Transaction tracking: which requests are outstanding and when they time out. STUN transaction tracking.
- attributes
- The STUN attribute types and the raw attribute representation. STUN attribute types.
- checks
- Validation helpers for received messages and attributes.
- client
- A Sans-I/O STUN client for talking to a STUN server. A Sans-I/O STUN client.
- error_
code - The
ERROR-CODEattribute and the codes defined by STUN, TURN and ICE. TheERROR-CODEattribute. - fingerprint
- The
FINGERPRINTattribute, a CRC-32 over the message. - integrity
- The
MESSAGE-INTEGRITYattribute, an HMAC-SHA1 over the message. - message
- The STUN message itself: header, attributes, and encoding. The STUN message: header, attributes, and encoding.
- textattrs
- Text-valued attributes such as
USERNAME,REALMandSOFTWARE. - uattrs
- The
UNKNOWN-ATTRIBUTESattribute, listing attributes a server could not process. - uri
- Parsing
stun:andstuns:URIs. - xoraddr
- The
XOR-MAPPED-ADDRESSattribute, whose value is masked with the magic cookie.
Constants§
- DEFAULT_
PORT - IANA assigned ports for “stun” protocol.
- DEFAULT_
TLS_ PORT - The default port for
stuns:(STUN over TLS/DTLS).