quic_address_token (quic v1.4.5)
View SourceSummary
Functions
Decode a token envelope. Returns the kind, bound address, timestamp, and (for retries) the original DCID. Signature is NOT verified here; callers pass the result through validate/3.
Encode a NEW_TOKEN for a client address.
Encode a retry token binding a client address, timestamp, and the original DCID from the Initial that triggered the retry.
Validate a decoded token: the signature must match (checked in decode/2) and the timestamp must be within max_age_ms of now. The address is checked by the listener against the current source. The retry token's ODCID is NOT compared here — it carries the client's original DCID so the server can recover it for the original_destination_connection_id transport param (RFC 9000 §7.3), not to be matched against the retried Initial's DCID.
Types
-type addr() :: {inet:ip_address(), inet:port_number()}.
-type kind() :: retry | new_token.
Functions
-spec decode(binary(), binary()) -> {ok, #{kind := kind(), addr := addr(), ts := non_neg_integer(), odcid := binary() | undefined}} | {error, term()}.
Decode a token envelope. Returns the kind, bound address, timestamp, and (for retries) the original DCID. Signature is NOT verified here; callers pass the result through validate/3.
-spec encode_new_token(binary(), addr(), non_neg_integer()) -> binary().
Encode a NEW_TOKEN for a client address.
-spec encode_retry(binary(), addr(), binary(), non_neg_integer()) -> binary().
Encode a retry token binding a client address, timestamp, and the original DCID from the Initial that triggered the retry.
-spec validate(map(), #{max_age_ms => non_neg_integer()}) -> ok | {error, term()}.
Validate a decoded token: the signature must match (checked in decode/2) and the timestamp must be within max_age_ms of now. The address is checked by the listener against the current source. The retry token's ODCID is NOT compared here — it carries the client's original DCID so the server can recover it for the original_destination_connection_id transport param (RFC 9000 §7.3), not to be matched against the retried Initial's DCID.