Expand description
The subset of Macula’s signed DHT records that direct-dial resolution
needs: procedure_advertisement and station_endpoint construction,
signing, verification, and storage-key derivation, plus thin wrappers
around the mesh’s _dht.* RPC procedures.
Ported from macula-io/macula’s src/record/macula_record.erl and
src/macula.erl (the put_record/find_record/find_records facade),
cross-checked against macula-go‘s own port of the same reference
(dht/record.go, dht/client.go) — see those files’ doc comments for
the fuller reasoning behind each field. Only the two record types
direct-dial needs are ported; add more constructors here as other
direct-dial consumers (streaming, content) are built.
This is a thin RPC client, not a DHT participant. Every function
here just issues an ordinary signed CALL (_dht.put_record etc.) to
whichever station the given Session is
already connected to — real Kademlia routing, replication, and k-bucket
maintenance stay entirely on the relay side (macula-station). Nothing
in this module talks DHT protocol directly.
Structs§
- Content
Announcement - A
content_announcementrecord’s fields, read out of its payload — mirrorsmacula_record:read_content_announcement/1. The optionalname/size/chunk_countmetadata fields (content_announcement_opts()) are not ported — direct-dial content fetch doesn’t need them to resolve and dial; add them if a future caller needs to prioritize candidates without fetching the manifest. - Procedure
Advertisement - A
procedure_advertisementrecord’s fields, read out of its payload — mirrorsmacula_record:read_procedure_advertisement/1.cert_chainisNonewhen the advertisement carries nocert_chainfield (the common, unmanaged-realm case); seecert_chain::verify_advertisement_cert_chain. - Record
- Mirrors
macula_record.erl’s envelope map (type/key/version/ created_at/expires_at/payload/signature).subject_idis not carried — neither record type this module builds uses it. - Station
Endpoint - A
station_endpointrecord’s fields, read out of its payload — mirrorsmacula_record:read_station_endpoint/1.
Enums§
Constants§
- DEFAULT_
TTL - Matches
macula_record’s?DEFAULT_TTL_MS(48h) — the TTL aprocedure_advertisementgets when the caller doesn’t specify one. - TYPE_
CONTENT_ ANNOUNCEMENT - TYPE_
PROCEDURE_ ADVERTISEMENT - Record type tags —
macula_record.erl’s?TYPE_*constants. - TYPE_
STATION_ ENDPOINT
Functions§
- content_
key - The DHT storage key for every
content_announcementnamingmcid:SHA-256(mcid). Matchesmacula_record:content_key/1. Consumers use this withfind_records(there may be more than one announcer) before holding any record. - discovery_
uri - Matches
macula_direct_dial’sdiscovery_uri/2: the DHT lookup/advertisement key input ishex(realm) + "/" + procedure, so the same procedure name under different realms doesn’t collide in the DHT. The advertiser and every resolver must derive this identically. - find_
record - Fetches one record by its storage key (see
procedure_key/station_endpoint_key). ReturnsDhtError::NotFoundif none exists — the caller’s signature should still be checked viaverifybefore the payload is trusted; this function does not verify on the caller’s behalf. - find_
records - Fetches every record stored at
key— the full signer-deduped multiset (e.g. everyprocedure_advertisementfor one procedure). Each record’s signature should be verified viaverifybefore its payload is trusted; this function does not verify on the caller’s behalf. - find_
records_ by_ type - Returns every record of
typcurrently visible from the station this session is connected to. Coverage depends on that station’s own view of the DHT. Mirrorsmacula:find_records_by_type/2. - new_
content_ announcement - Builds an UNSIGNED
content_announcementrecord namingannouncer_nodeas reachable atendpointformcid. Sign beforeput_record. Mirrorsmacula_record:content_announcement/3,4— seeContentAnnouncementfor which optional metadata fields are not ported. - new_
procedure_ advertisement - Builds an UNSIGNED
procedure_advertisementrecord namingserving_stationasprocedure_uri’s current handler.procedure_urishould be the realm-qualified discovery URI (seediscovery_uri), matchingmacula_direct_dial’s own convention — the advertiser and the resolver must derive the identical URI or the DHT storage key (procedure_key) will not agree. Sign beforeput_record. - new_
procedure_ advertisement_ with_ cert_ chain new_procedure_advertisementplus an embedded X.509 service-cert chain (leaf-first PEM: leaf ++ org CA), for Slice 7c Direction B managed-realm authorization — seecert_chain::verify_advertisement_cert_chainfor the corresponding check. Opt-in: plainnew_procedure_advertisementis unaffected and remains the right choice for unmanaged realms.- procedure_
key - The DHT storage key for a
procedure_advertisementby its (already realm-qualified — seediscovery_uri) URI:SHA-256(uri). Matchesmacula_record:procedure_key/1. - put_
record - Stores a signed record in the mesh DHT. Mirrors
macula:put_record/2— the relay validates the signature on receipt. - read_
content_ announcement - Extracts a
content_announcementrecord’s typed fields, or an error ifrisn’t one or is malformed. Mirrorsmacula_record:read_content_announcement/1. - read_
procedure_ advertisement - Extracts a
procedure_advertisementrecord’s typed fields, or an error ifrisn’t one or is malformed. - read_
station_ endpoint - Extracts a
station_endpointrecord’s typed fields, or an error ifrisn’t one or is malformed. - sign
- Sets
r.signatureto the Ed25519 signature overSIG_DOMAIN || canonical_unsigned(r), matchingmacula_record:sign/2. - station_
endpoint_ key - The DHT storage key for a station’s own
station_endpointrecord:SHA-256("station_endpoint" || pubkey). Matchesmacula_record:station_endpoint_key/1. - verify
- Checks
r’s Ed25519 signature against its ownkey, then its expiry. Matchesmacula_record:verify/1. DistinguishesVerifyError::ExpiredfromVerifyError::InvalidSignaturebecause a caller resolving a record (e.g.direct_dial’s retry loop) should retry past a stale-but-once-valid replica, never past a forged one — seemacula_direct_dial.erl’son_endpoint_verified/3doing exactly this branch.