1/* @ajax/mesh-blobs-frame: the blob frames on the peer links (blobd.rs), each a type byte, a u32
2 * length, then the body, which starts with the blob's sha256:
3 * - F_BLOB_PUT: hash, u64 job, u32 len, the bytes (a push of job's copy);
4 * - F_BLOB_ACK: hash, u32 ok, u64 job (the receiver's copy is durable, or was refused);
5 * - F_BLOB_GET: hash, u64 job (a fetch; any job's copy serves);
6 * - F_BLOB: hash, u32 found, the bytes when found (a fetch's answer). */
7#ifndef MESH_BLOBS_FRAME_H
8#define MESH_BLOBS_FRAME_H
910#include "mesh/jobs/id.h"
11#include "mesh/strbuf.h"
1213#include <stdbool.h>
14#include <stddef.h>
15#include <stdint.h>
1617void mbf_put(msb *out, const mj_hash *h, mj_job_id job, const void *bytes, uint32_t n);
18void mbf_ack(msb *out, const mj_hash *h, bool ok, mj_job_id job);
19void mbf_get(msb *out, const mj_hash *h, mj_job_id job);
20void mbf_blob(msb *out, const mj_hash *h, const void *bytes, size_t n, bool found);
2122/* A blob frame's body read: the fields its type has (bytes point into the body). */
23typedef struct {
24 mj_hash hash;
25 mj_job_id job; /* PUT, ACK, GET */
26 uint32_t len; /* PUT: the declared length */
27 bool ok; /* ACK: durable; BLOB: found */
28 const uint8_t *bytes; /* PUT, BLOB */
29 size_t nbytes;
30} mbf_body;
3132/* False when the body is too short for its type (blobd drops such a frame). */
33bool mbf_decode(uint8_t ty, const uint8_t *body, size_t n, mbf_body *out);
3435#endif