morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
file_store.hpp File Reference

The file side channel's store (files/1, spec 6 §18): uploads in chunks, and files a principal may read by a capability reference. More...

#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <expected>
#include <functional>
#include <map>
#include <mutex>
#include <random>
#include <string>
#include <string_view>
#include <utility>

Go to the source code of this file.

Classes

struct  morph::ui::FileInfo
 What a file is, as its uploader described it. More...
struct  morph::ui::FileSlice
 A slice of a stored file. More...
class  morph::ui::IFileStore
 Where uploaded and issued files live. Every call names the principal it is made for, and an upload id or a file reference works only for the principal it was made for. More...
struct  morph::ui::MemoryFileStoreOptions
 How much a MemoryFileStore keeps. More...
class  morph::ui::MemoryFileStore
 An IFileStore in memory: bounded per file and per principal; an upload that stalls expires. More...

Enumerations

enum class  morph::ui::FileError : std::uint8_t {
  NotFound , TooLarge , OverQuota , BadOffset ,
  Incomplete
}
 Why a store refused a call. More...

Functions

constexpr std::string_view morph::ui::fileErrorText (FileError error) noexcept
 The text of a FileError, as a ui-file refusal carries it.
std::string morph::ui::newFileRef (std::string_view prefix="file:")
 A new unguessable id: prefix, then 32 lower-case hex digits read straight from std::random_device.

Detailed Description

The file side channel's store (files/1, spec 6 §18): uploads in chunks, and files a principal may read by a capability reference.

Specified in docs/spec/ui/service.md, "Files".

Definition in file file_store.hpp.

Enumeration Type Documentation

◆ FileError

enum class morph::ui::FileError : std::uint8_t
strong

Why a store refused a call.

Enumerator
NotFound 

No such upload or file for this principal; a caller cannot tell the two apart.

TooLarge 

The file is larger than the store accepts.

OverQuota 

The principal's files would exceed what the store keeps for one principal.

BadOffset 

A chunk does not start where the bytes received so far end.

Incomplete 

An upload ended before every byte it announced arrived.

Definition at line 26 of file file_store.hpp.

Function Documentation

◆ fileErrorText()

std::string_view morph::ui::fileErrorText ( FileError error)
nodiscardconstexprnoexcept

The text of a FileError, as a ui-file refusal carries it.

Parameters
errorThe error.
Returns
Its text.

Definition at line 37 of file file_store.hpp.

◆ newFileRef()

std::string morph::ui::newFileRef ( std::string_view prefix = "file:")
inlinenodiscard

A new unguessable id: prefix, then 32 lower-case hex digits read straight from std::random_device.

std::random_device is read directly, never used as a seed: libstdc++, libc++ and MSVC back it with the operating system's entropy source, which is what makes the id a capability.

Parameters
prefixfile: for a reference, upload: for an upload id.
Returns
The id.

Definition at line 135 of file file_store.hpp.