Update
CI / GCC 16 / C++26 / werror (push) Failing after 3m9s
CI / GCC 16 / C++26 / sanitizers (push) Failing after 10m15s
CI / GCC 16 / C++26 / default (push) Failing after 13m1s

Signed-off-by: faumaray <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-07-20 01:18:53 +03:00
1 parent 8583a479dd
commit 3851aeb703
42 files changed
+6948 -759

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
#pragma once
#include <Void/Crypto/Crypto.hpp>
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <Void/Text/Semver.hpp>
#include <array>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
namespace Void::Update
{
struct Compatibility {
std::unordered_map<std::string, Semver::VersionRange>
versionContracts;
std::unordered_map<std::string, std::string> exactContracts;
};
struct Release {
std::string component;
std::string artifactId;
std::string channel;
Semver::Version version;
std::string cohort;
std::string platform;
std::string architecture;
std::string url;
std::uint64_t size{0};
std::string sha256;
std::string packageType;
Compatibility compatibility;
std::string releaseManifestSha256;
};
struct Feed {
std::uint32_t schemaVersion{1};
std::string feedId;
std::uint64_t sequence{0};
std::chrono::system_clock::time_point generatedAt;
std::chrono::system_clock::time_point expiresAt;
std::vector<Release> releases;
};
struct FeedEnvelope {
std::uint32_t schemaVersion{1};
std::string keyId;
std::string payload;
Crypto::Digest signature;
};
using Ed25519PublicKey =
std::array<std::byte, Crypto::Ed25519PublicKeySize>;
using Keyring = std::unordered_map<std::string, Ed25519PublicKey>;
struct VerificationPolicy {
std::size_t maxEnvelopeBytes{5 * 1024 * 1024};
std::size_t maxPayloadBytes{4 * 1024 * 1024};
std::size_t maxReleases{10'000};
std::optional<std::uint64_t> minimumSequence;
std::chrono::system_clock::time_point now{
std::chrono::system_clock::now()};
bool requireUnexpired{true};
};
struct VerifiedFeed {
Feed feed;
std::string keyId;
std::string signedPayload;
};
struct Environment {
std::unordered_map<std::string, Semver::Version> versionContracts;
std::unordered_map<std::string, std::string> exactContracts;
std::string platform;
std::string architecture;
};
struct SelectionRequest {
std::string component;
std::string artifactId;
std::string channel;
Environment environment;
std::optional<Semver::Version> currentVersion;
std::optional<std::string> requiredCohort;
bool allowDowngrade{false};
bool includeCurrent{false};
};
/// Parse and validate an unsigned payload. Trust and activation policy is a
/// caller concern; all structural, size, expiry and replay checks still
/// run.
[[nodiscard]] Void::Result::Result<Feed>
parseFeedPayload(std::string_view payload,
const VerificationPolicy& policy = {});
/// Verify the envelope signature before parsing the signed payload.
[[nodiscard]] Void::Result::Result<VerifiedFeed>
verifyFeedEnvelope(std::string_view envelopeJson, const Keyring& keys,
const VerificationPolicy& policy = {});
/// Select the greatest compatible version, independent of feed order.
[[nodiscard]] std::optional<Release>
selectRelease(const Feed& feed, const SelectionRequest& request);
} // namespace Void::Update
+4
View File
@@ -0,0 +1,4 @@
#pragma once
#include <Void/Update/Feed.hpp>
#include <Void/Update/VersionStore.hpp>
+102
View File
@@ -0,0 +1,102 @@
#pragma once
#include <Void/Functional/Error.hpp>
#include <Void/Functional/Result.hpp>
#include <Void/Text/Semver.hpp>
#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <optional>
#include <vector>
namespace Void::Update
{
struct PendingActivation {
std::optional<Semver::Version> previousVersion;
Semver::Version candidateVersion;
/// Health-log generation observed before activation. A later
/// healthy event for the candidate is the durable commit marker
/// used to reconcile an activation journal left behind by a
/// post-commit cleanup failure.
std::uint64_t healthGeneration{};
};
/// Immutable version directory store with a relative `current` symlink and
/// a durable activation journal. An uncommitted activation is rolled back
/// by reconcile(), making candidate health checks an explicit commit
/// boundary.
///
/// The crash-durability and cross-process locking guarantees are provided
/// by the POSIX implementation. The current Windows fallback is functional
/// but does not yet provide equivalent crash durability or process locking.
class VersionStore
{
public:
explicit VersionStore(std::filesystem::path root);
[[nodiscard]] Void::Result::Result<void> initialize();
[[nodiscard]] Void::Result::Result<std::filesystem::path>
prepare(const Semver::Version& version);
[[nodiscard]] Void::Result::Result<void>
publish(const Semver::Version& version,
const std::filesystem::path& stagingDirectory);
[[nodiscard]] Void::Result::Result<void>
activate(const Semver::Version& version);
/// Idempotently accept the candidate. A durable healthy-history
/// event is the commit point; activation-journal cleanup after that
/// point cannot be reported as a reversible failure.
[[nodiscard]] Void::Result::Result<void> commit();
/// Idempotently restore the previous version. The journal is
/// retained until restoration succeeds. A candidate whose commit
/// marker is newer than the journal baseline is finalized instead
/// of rolled back.
[[nodiscard]] Void::Result::Result<void> rollback();
[[nodiscard]] Void::Result::Result<void> reconcile();
/// Record a successful activation performed by an external
/// lifecycle owner. The published version must be a real immediate
/// directory. Every call appends a durable healthy event and
/// refreshes retention order. It rejects stores with an internal
/// activation journal so it cannot implicitly commit activate().
/// This method does not initialize the store or create staging.
[[nodiscard]] Void::Result::Result<void>
recordHealthy(const Semver::Version& version);
/// Record a failed external activation unless this version's
/// current publication lifecycle is already known healthy. A
/// retired and later republished SemVer starts a new lifecycle.
/// This method does not initialize the store or create staging.
[[nodiscard]] Void::Result::Result<void>
recordFailed(const Semver::Version& version);
/// Return real, currently published versions whose current
/// lifecycle is known healthy, newest durable healthy event first.
/// Missing, symlinked, failed, retired, and unknown publications
/// are excluded.
[[nodiscard]]
Void::Result::Result<std::vector<Semver::Version>>
healthyPublishedVersions() const;
/// Remove structurally valid, published version directories except
/// the active version, an in-flight activation's candidate and
/// previous version, and the requested number of most recently
/// committed healthy versions. Unknown publication state is
/// retained conservatively. Symlinks and the staging tree are never
/// traversed or removed. Returns the versions that were quarantined
/// and removed.
[[nodiscard]]
Void::Result::Result<std::vector<Semver::Version>>
prune(std::size_t retainedPreviousVersions);
[[nodiscard]] Void::Result::Result<std::optional<Semver::Version>>
currentVersion() const;
[[nodiscard]] Void::Result::Result<std::optional<PendingActivation>>
pendingActivation() const;
[[nodiscard]] const std::filesystem::path& root() const noexcept;
[[nodiscard]] std::filesystem::path
versionPath(const Semver::Version& version) const;
private:
std::filesystem::path m_root;
};
} // namespace Void::Update