feat(ha-term-safety): add WAL_CONFIG_MARKER entry type + reference payload codec (task 4.1)
This commit is contained in:
parent
f1783f7952
commit
f447ad4183
5 changed files with 215 additions and 1 deletions
|
|
@ -37,6 +37,57 @@
|
|||
#include "xce/cluster_def.h"
|
||||
#include "wal_types.h" /* wal_entry_hdr_t, WAL_* constants */
|
||||
|
||||
/* ── WAL_CONFIG_MARKER codec (ha-term-safety task 4.1) ───────────────
|
||||
* Fixed, padding-independent serialization of a config-change marker:
|
||||
* 8-byte big-endian version_tag followed by the raw 32-byte SHA-256. NO
|
||||
* configuration bytes are ever encoded (R7.2/R7.4) — the bytes travel
|
||||
* out-of-band on the config-push transport. The explicit byte layout (rather
|
||||
* than a struct memcpy) keeps the form stable across compiler padding and host
|
||||
* endianness, since this payload replicates to standbys via AppendEntries. */
|
||||
|
||||
int config_marker_encode(uint64_t version_tag, const uint8_t sha256[32],
|
||||
uint8_t *buf, size_t bufsz, size_t *out_len)
|
||||
{
|
||||
if (!sha256 || !buf || !out_len)
|
||||
return -EINVAL;
|
||||
if (bufsz < WAL_CONFIG_MARKER_PAYLOAD_LEN)
|
||||
return -ENOSPC;
|
||||
|
||||
/* version_tag: 8 bytes, big-endian (matches config_repl wire convention). */
|
||||
buf[0] = (uint8_t)(version_tag >> 56);
|
||||
buf[1] = (uint8_t)(version_tag >> 48);
|
||||
buf[2] = (uint8_t)(version_tag >> 40);
|
||||
buf[3] = (uint8_t)(version_tag >> 32);
|
||||
buf[4] = (uint8_t)(version_tag >> 24);
|
||||
buf[5] = (uint8_t)(version_tag >> 16);
|
||||
buf[6] = (uint8_t)(version_tag >> 8);
|
||||
buf[7] = (uint8_t)(version_tag);
|
||||
|
||||
/* sha256: raw 32 bytes — the configuration *reference*, never the bytes. */
|
||||
memcpy(buf + 8, sha256, 32);
|
||||
|
||||
*out_len = WAL_CONFIG_MARKER_PAYLOAD_LEN;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_marker_decode(const uint8_t *buf, size_t len,
|
||||
uint64_t *version_tag, uint8_t sha256_out[32])
|
||||
{
|
||||
if (!buf || len < WAL_CONFIG_MARKER_PAYLOAD_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
if (version_tag) {
|
||||
*version_tag = ((uint64_t)buf[0] << 56) | ((uint64_t)buf[1] << 48) |
|
||||
((uint64_t)buf[2] << 40) | ((uint64_t)buf[3] << 32) |
|
||||
((uint64_t)buf[4] << 24) | ((uint64_t)buf[5] << 16) |
|
||||
((uint64_t)buf[6] << 8) | ((uint64_t)buf[7]);
|
||||
}
|
||||
if (sha256_out)
|
||||
memcpy(sha256_out, buf + 8, 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* SSL context for xce_probe_config_tag.
|
||||
* Stored as void* to avoid SSL_CTX type at this point in the translation unit. */
|
||||
static void *s_probe_ssl_ctx = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue