macula_content_serve (macula v13.2.1)
View SourceHow a sharing node answers a fetch on its content procedure (D27). One content id per stream, a server_stream: the stream's args name the content id (mcid) and what is wanted (want), root for the content id a fetcher was given or block for a chunk of a manifest it holds. The answer is one DATA body, then the end of the stream:
#{kind => block, mcid => MCID, bytes => Bytes}for a raw root or a chunk;#{kind => manifest, mcid => MCID, manifest => Manifest}for a manifest root.
Content this node does not hold is refused with the stream error not_shared, and args that name no content id, or want anything else, with malformed. The args are read as a station link delivers them, keys and text values tagged or not, as macula_record:payload_field/2 reads any wire payload. The fetcher verifies every body against the content id it asked for; nothing here is trusted by it.
Summary
Functions
What a store answers for Want of MCID: the DATA body, or not_found.
Answer one fetch on Stream, looking the content up with Lookup.
Types
-type body() :: #{kind := block | manifest, mcid := macula:mcid(), bytes => binary(), manifest => macula_manifest:manifest()}.
-type lookup() :: fun((want(), macula:mcid()) -> {ok, body()} | not_found).
-type want() :: root | block.
Functions
-spec lookup(want(), macula:mcid(), macula_content_store:store()) -> {ok, body()} | not_found.
What a store answers for Want of MCID: the DATA body, or not_found.
Answer one fetch on Stream, looking the content up with Lookup.