Skip to main content

encode_binding_success

Function encode_binding_success 

Source
pub fn encode_binding_success(
    transaction_id: &TransactionId,
    reflexive: SocketAddr,
) -> Vec<u8> 
Expand description

Encode a STUN Binding success response carrying reflexive in one XOR-MAPPED-ADDRESS attribute and nothing else — no MAPPED-ADDRESS, no SOFTWARE, no FINGERPRINT (SPEC.md §2.7). The server-side counterpart of parse_binding_response.

reflexive’s IP is folded per SPEC.md §5.3 (fold_ip) BEFORE encoding, so an IPv4-mapped IPv6 address (::ffff:a.b.c.d) is encoded as family 0x01 carrying the embedded IPv4 address, never as a 16-byte family 0x02 value — answering an IPv4 caller with a 16-byte address is exactly the family-crossing defect measured on relay.dig.net (relay.dig.net#11). The port is carried unchanged; only the IP is folded.

parse_binding_response(&encode_binding_success(id, a), Some(id)) == Ok(a) for every SocketAddr a whose IP is native IPv4 or native IPv6 — proven in tests/codec.rs as the round-trip law SPEC.md §2.7 requires.