feat(shorturl): complete P2 M-SHORTURL-01..04 V2 local, storage, and remote providers with frozen V1
This commit is contained in:
1 parent
658c21a2fa
commit
691808eab6
13 files changed
+2317
-1
No files matched your search
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/ShortUrl/V2.hpp>
|
||||
#include <Void/Storage/Engine.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace Void::ShortUrl::V2
|
||||
{
|
||||
/// CSPRNG byte source backed by `Void::Security` (libsodium).
|
||||
class SecurityRandomBytesPort final : public RandomBytesPort
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
fill(std::span<std::byte> out) override;
|
||||
};
|
||||
|
||||
/// Durable `LinkRepositoryPort` backed by `Void::Storage::Engine`
|
||||
/// conditional `Batch` writes, preserving tombstones, V2 idempotency
|
||||
/// records, and quotas across crash/restart boundaries.
|
||||
class StorageLinkRepository final : public LinkRepositoryPort
|
||||
{
|
||||
public:
|
||||
|
||||
explicit StorageLinkRepository(
|
||||
std::shared_ptr<Void::Storage::Engine> engine,
|
||||
std::uint64_t disk_quota_bytes = 1024ULL * 1024 * 1024);
|
||||
|
||||
[[nodiscard]] bool is_durable() const noexcept override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<InsertOutcome>
|
||||
insert_conditional(const LinkRecord& record,
|
||||
const std::optional<IdempotencyRecord>& idem,
|
||||
std::int64_t now_unix_seconds,
|
||||
std::size_t max_entries,
|
||||
std::size_t max_retained_identities) override;
|
||||
|
||||
[[nodiscard]] Void::Result::Result<std::optional<LinkRecord>>
|
||||
get(std::string_view key) const override;
|
||||
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
revoke(std::string_view key,
|
||||
std::int64_t now_unix_seconds) override;
|
||||
|
||||
private:
|
||||
|
||||
mutable std::mutex m_write_mutex;
|
||||
std::shared_ptr<Void::Storage::Engine> m_engine;
|
||||
std::uint64_t m_disk_quota_bytes;
|
||||
};
|
||||
|
||||
} // namespace Void::ShortUrl::V2
|
||||
Reference in new issue
Block a user