dig_stun/lib.rs
1//! `dig-stun` — the DIG ecosystem's single home for reflexive-address discovery: how a node learns
2//! the public address the outside world sees its traffic arrive from, and how it decides whether to
3//! believe what it was told. `SPEC.md` at the repository root is the normative contract this crate
4//! implements; every public item here is cross-referenced to the section that specifies it.
5//!
6//! It owns exactly five things (`SPEC.md` §1):
7//!
8//! 1. **The RFC 5389 Binding codec** ([`encode_binding_request`], [`parse_binding_response`],
9//! [`parse_binding_request`], [`encode_binding_success`]) — request and success-response, both
10//! directions.
11//! 2. **The UDP STUN client** ([`query_reflexive_address`]) — one Binding transaction against one
12//! server over one socket. This is the crate's only I/O and its only `async fn`; every other
13//! public item is a pure function.
14//! 3. **The address-scope classifier** ([`scope`]) — the single predicate every consumer uses to
15//! ask "could this address be a legitimate reflexive candidate, and could a stranger route to
16//! it?".
17//! 4. **The peer-observation role** ([`observe`]) and **the agreement rule** ([`establish`]) — the
18//! parts that let every directly-reachable DIG node act as a reflexive-address source for its
19//! peers, and let a requesting node combine what several sources said without trusting any one
20//! of them.
21//! 5. **The signed-Binding credential** ([`credential`], §14) — the challenge/response that lets a
22//! DIG-operated UDP STUN server tell a DIG node's ask from anyone else's, and the exact bytes a
23//! requester signs. The crate owns the wire form, the nonce contract, the signing preimage and
24//! the verifier; it does NOT hold private keys (§14.6).
25//!
26//! It deliberately does NOT own the happy-eyeballs walk over several STUN servers (that is
27//! `dig_nat::stun::discover_reflexive_address`, which composes this crate with `dig-ip`), a UDP STUN
28//! listener for DIG nodes (nodes never open one — [`observe`]), tier policy (which servers to ask,
29//! in what order — the consumer's job), any proof of inbound reachability (`SPEC.md` §1, §10), or
30//! any membership policy over a verified credential identity — that is a decision of the deployment
31//! that runs the server (§14.10).
32
33mod client;
34mod codec;
35mod transaction_id;
36
37pub mod credential;
38pub mod establish;
39pub mod observe;
40pub mod scope;
41
42pub use client::query_reflexive_address;
43pub use codec::{
44 encode_binding_request, encode_binding_success, parse_binding_request, parse_binding_response,
45 StunError, TransactionId, ATTR_MAPPED_ADDRESS, ATTR_XOR_MAPPED_ADDRESS, BINDING_REQUEST,
46 BINDING_SUCCESS, MAGIC_COOKIE,
47};
48pub use transaction_id::new_transaction_id;