macula_content_serve (macula v13.2.0)

View Source

How 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

body/0

-type body() ::
          #{kind := block | manifest,
            mcid := macula:mcid(),
            bytes => binary(),
            manifest => macula_manifest:manifest()}.

lookup/0

-type lookup() :: fun((want(), macula:mcid()) -> {ok, body()} | not_found).

want/0

-type want() :: root | block.

Functions

lookup(_, MCID, Store)

-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.

serve(Stream, Args, Lookup)

-spec serve(pid(), term(), lookup()) -> ok.

Answer one fetch on Stream, looking the content up with Lookup.