Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
Haio::Cdn Namespace Reference

Namespaces

namespace  Bucket
namespace  Detail

Classes

struct  BucketConfig
class  Cache
struct  CacheConfig
struct  CacheEntry
class  CacheStore
struct  Config
struct  SecurityConfig

Functions

std::string cacheKey (std::string_view bucket, std::string_view path, std::string_view query)
std::vector< uint8_t > encodeEntry (const CacheEntry &entry)
std::optional< CacheEntry > decodeEntry (std::span< const uint8_t > raw)
std::unique_ptr< CacheStore > makeMemoryStore (size_t maxUsage, std::chrono::seconds ttl)
std::unique_ptr< CacheStore > makeFileStore (std::filesystem::path root, std::chrono::seconds ttl, size_t maxUsage)
std::unique_ptr< CacheStore > makeRedisStore (std::string url, std::chrono::seconds ttl, size_t maxUsage, boost::asio::any_io_executor executor)
Config parseConfig (std::string_view text)
Config loadConfig (const std::filesystem::path &path)
boost::asio::awaitable< Result< Blob > > fetchBucket (const Config &config, Bucket::ZipArchives &archives, std::string bucket, std::string path)
boost::asio::awaitable< void > runServer (Config config)
std::unique_ptr< CacheStore > makeRedisStore (std::string url, std::chrono::seconds ttl, size_t maxUsage, asio::any_io_executor executor)

Class Documentation

◆ Haio::Cdn::BucketConfig

struct Haio::Cdn::BucketConfig

a bucket is described entirely by the scheme of its url:

file://relative/dir file:///absolute/dir http://host/prefix https://host/prefix s3://host/bucket https://* open, the request names the host //* open, the request names the scheme and the host

Definition at line 201 of file haio_cdn.hpp.

Class Members
string accessKey

s3 only, and the reason a config file deserves careful permissions. empty leaves the request unsigned, which is what a public bucket wants.

string name
bool open = false
string region

s3 only: from ?region=, then the host, then AWS_DEFAULT_REGION

path root
string scheme
string secretKey
string sessionToken
string url

◆ Haio::Cdn::CacheConfig

struct Haio::Cdn::CacheConfig

Definition at line 28 of file haio_cache.hpp.

Class Members
size_t maxUsage = 64u << 20
seconds ttl {0}
string url

◆ Haio::Cdn::CacheEntry

struct Haio::Cdn::CacheEntry

what the cache holds is a finished response, not an image: the work being saved is the fetch and the whole conversion behind it, so replaying an entry costs a copy.

Definition at line 22 of file haio_cache.hpp.

Class Members
string contentType
vector< uint8_t > data
string filename

◆ Haio::Cdn::Config

struct Haio::Cdn::Config

Definition at line 261 of file haio_cdn.hpp.

Collaboration diagram for Haio::Cdn::Config:
Class Members
map< string, BucketConfig > buckets
CacheConfig cache
set< string > declared

the keys the file actually spelled out, as "max_size" or "cache.max_ip".

the safety limits all have a default, so leaving one out is safe rather than open; this is what lets the server say which ones it chose for itself instead of letting an operator believe they had configured something.

string host = "0.0.0.0"
unsigned short port = 8080
SecurityConfig security

◆ Haio::Cdn::SecurityConfig

struct Haio::Cdn::SecurityConfig

every limit the server has, in one table, so that reviewing what protects this deployment is reading one page of the config rather than hunting for it.

each one is safe when left out, and the server says at startup which ones it chose for itself; see Security.

Definition at line 229 of file haio_cdn.hpp.

Class Members
bool allowUnzip = false

whether a path may reach inside a zip; off unless asked for

size_t maxCacheEntriesByIp = 0

entries one address may create per cache window; zero is no limit

size_t maxRequestsByIp = 0

requests one address may make per second; zero is no limit

int maxSizePercent = 500

the largest share a resize may ask for, as a percentage.

it is a separate number because it bounds a different thing: a picture scaled by a share is bounded by what it was, so five hundred percent of a thumbnail is still small, while five hundred percent of something large is not.

int maxSizePixel = 4096

the largest width or height a resize may ask for outright

size_t maxUnzip = 64u << 20

bytes one file out of a zip may take, and what the archives kept in memory may take altogether. megabytes in the config.

seconds timeout {10}

seconds one conversion may run before it is given up on

Function Documentation

◆ cacheKey()

std::string Haio::Cdn::cacheKey ( std::string_view bucket,
std::string_view path,
std::string_view query )

the md5 of the bucket, the path and the query, in the order they were written.

the query is not sorted, and must not be: it spells out a pipeline, so crop before resize is a different picture from resize before crop. sorting would collide two different requests onto one entry and serve the wrong image, which is a worse fault than keeping two entries for one answer. the method is left out so a HEAD finds what a GET stored.

Definition at line 34 of file key.cpp.

Here is the call graph for this function:

◆ decodeEntry()

std::optional< CacheEntry > Haio::Cdn::decodeEntry ( std::span< const uint8_t > raw)

a truncated or corrupt entry reads as a miss rather than as a bad response

Definition at line 58 of file key.cpp.

Here is the call graph for this function:

◆ encodeEntry()

std::vector< uint8_t > Haio::Cdn::encodeEntry ( const CacheEntry & entry)

the framing the file and redis backends share; the memory one keeps the struct

Definition at line 45 of file key.cpp.

Here is the call graph for this function:

◆ fetchBucket()

boost::asio::awaitable< Result< Blob > > Haio::Cdn::fetchBucket ( const Config & config,
Bucket::ZipArchives & archives,
std::string bucketName,
std::string path )

picks a fetcher by the scheme the config already parsed, and turns whatever it throws into a Result, so nothing above this line has to catch anything.

Definition at line 15 of file bucket.cpp.

Here is the call graph for this function:

◆ loadConfig()

Config Haio::Cdn::loadConfig ( const std::filesystem::path & path)

the file may hold an s3 secret, so anybody who can read it can sign as this server. the check is a warning rather than a refusal: whose machine this is, and who else is on it, is not haio's call to make.

Definition at line 287 of file config.cpp.

Here is the call graph for this function:

◆ makeFileStore()

std::unique_ptr< CacheStore > Haio::Cdn::makeFileStore ( std::filesystem::path root,
std::chrono::seconds ttl,
size_t maxUsage )

Definition at line 171 of file file.cpp.

Here is the call graph for this function:

◆ makeMemoryStore()

std::unique_ptr< CacheStore > Haio::Cdn::makeMemoryStore ( size_t maxUsage,
std::chrono::seconds ttl )

Definition at line 87 of file memory.cpp.

Here is the call graph for this function:

◆ makeRedisStore() [1/2]

std::unique_ptr< CacheStore > Haio::Cdn::makeRedisStore ( std::string url,
std::chrono::seconds ttl,
size_t maxUsage,
asio::any_io_executor executor )

Definition at line 232 of file redis.cpp.

Here is the call graph for this function:

◆ makeRedisStore() [2/2]

std::unique_ptr< CacheStore > Haio::Cdn::makeRedisStore ( std::string url,
std::chrono::seconds ttl,
size_t maxUsage,
boost::asio::any_io_executor executor )
Here is the call graph for this function:

◆ parseConfig()

Config Haio::Cdn::parseConfig ( std::string_view text)

Definition at line 190 of file config.cpp.

Here is the call graph for this function:

◆ runServer()

asio::awaitable< void > Haio::Cdn::runServer ( Config config)

Definition at line 431 of file server.cpp.

Here is the call graph for this function: