Expand description
dig-stun — the DIG ecosystem’s single home for reflexive-address discovery: how a node learns
the public address the outside world sees its traffic arrive from, and how it decides whether to
believe what it was told. SPEC.md at the repository root is the normative contract this crate
implements; every public item here is cross-referenced to the section that specifies it.
It owns exactly five things (SPEC.md §1):
- The RFC 5389 Binding codec (
encode_binding_request,parse_binding_response,parse_binding_request,encode_binding_success) — request and success-response, both directions. - The UDP STUN client (
query_reflexive_address) — one Binding transaction against one server over one socket. This is the crate’s only I/O and its onlyasync fn; every other public item is a pure function. - The address-scope classifier (
scope) — the single predicate every consumer uses to ask “could this address be a legitimate reflexive candidate, and could a stranger route to it?”. - The peer-observation role (
observe) and the agreement rule (establish) — the parts that let every directly-reachable DIG node act as a reflexive-address source for its peers, and let a requesting node combine what several sources said without trusting any one of them. - The signed-Binding credential (
credential, §14) — the challenge/response that lets a DIG-operated UDP STUN server tell a DIG node’s ask from anyone else’s, and the exact bytes a requester signs. The crate owns the wire form, the nonce contract, the signing preimage and the verifier; it does NOT hold private keys (§14.6).
It deliberately does NOT own the happy-eyeballs walk over several STUN servers (that is
dig_nat::stun::discover_reflexive_address, which composes this crate with dig-ip), a UDP STUN
listener for DIG nodes (nodes never open one — observe), tier policy (which servers to ask,
in what order — the consumer’s job), any proof of inbound reachability (SPEC.md §1, §10), or
any membership policy over a verified credential identity — that is a decision of the deployment
that runs the server (§14.10).
Modules§
- credential
- The signed-Binding credential (
SPEC.md§14) — how a DIG-operated UDP STUN server tells a DIG node’s ask from anyone else’s. - establish
- Provenance and agreement (
SPEC.md§7): how several untrusted readings of this node’s own reflexive address combine into something worth writing into an on-chain advertisement — or, failing that, into nothing at all. - observe
- The peer-observation responder role (
SPEC.md§6) — how a directly-reachable DIG node answersdig.getObservedAddressfor a peer, and the abuse bounds on doing so. - scope
- The single address-scope classifier (
SPEC.md§5) — the one range table every consumer asks “could this address be a legitimate reflexive candidate, and could a stranger route to it?” against.
Enums§
- Stun
Error - Errors decoding a STUN message or performing a Binding transaction (
SPEC.md§2.8).
Constants§
- ATTR_
MAPPED_ ADDRESS - Legacy
MAPPED-ADDRESSattribute type (RFC 5389 §15.1) — some servers still emit it. - ATTR_
XOR_ MAPPED_ ADDRESS XOR-MAPPED-ADDRESSattribute type (RFC 5389 §15.2).- BINDING_
REQUEST - Binding request message type (RFC 5389 §6 — method Binding = 0x001, class Request = 0b00).
- BINDING_
SUCCESS - Binding success response message type (method Binding, class Success = 0b10).
- MAGIC_
COOKIE - STUN magic cookie (RFC 5389 §6). Always the first 4 bytes after the message type + length.
Functions§
- encode_
binding_ request - Encode a STUN Binding request: a 20-byte header (type, length = 0, cookie, the 96-bit
transaction id) and no attributes.
transaction_idis caller-supplied so the response can later be matched to this request (SPEC.md§2.3). - encode_
binding_ success - Encode a STUN Binding success response carrying
reflexivein oneXOR-MAPPED-ADDRESSattribute and nothing else — noMAPPED-ADDRESS, noSOFTWARE, noFINGERPRINT(SPEC.md§2.7). The server-side counterpart ofparse_binding_response. - new_
transaction_ id - Generate a 96-bit STUN transaction id from a CSPRNG (RFC 5389 §10.1: “It primarily serves to correlate requests with responses… and MUST be uniformly and randomly chosen from the interval 0 .. 296 - 1, and SHOULD be cryptographically random”).
- parse_
binding_ request - Parse a STUN Binding request datagram, returning its transaction id (
SPEC.md§2.5). The server-side counterpart ofparse_binding_response, used to answer a peer or the operator/ relay/public UDP tiers withencode_binding_success. - parse_
binding_ response - Parse a STUN Binding success response, returning the reflexive
SocketAddrfrom itsXOR-MAPPED-ADDRESS(preferred) or legacyMAPPED-ADDRESSattribute (SPEC.md§2.4). - query_
reflexive_ address - Perform a single STUN Binding transaction against
serveroversocket, returning the discovered reflexive (public)SocketAddrofsocket.
Type Aliases§
- Transaction
Id - The 96-bit STUN transaction id. A plain array alias (not a newtype) so
dig-nat’s re-exported signatures stay unchanged for its existing consumers (SPEC.md§2.1, §8.2).