ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
edge_cache_proxy.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#ifndef PROTOCORE_EDGE_CACHE_PROXY_H
5#define PROTOCORE_EDGE_CACHE_PROXY_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
10
11/**
12 * @file edge_cache_proxy.h
13 * @brief CDN edge-cache tier - server glue (PROTOCORE_ENABLE_EDGE_CACHE).
14 *
15 * Wires the pure engine (edge_cache) + async fetch (edge_fetch) into a PC: registers the
16 * cache as a middleware and installs the async-fetch poll hook, maps request path prefixes to upstream
17 * origins (fetched over protocore_client), and serves hits with the constant-memory send-pump. A miss or a
18 * stale-entry revalidation suspends the client request and drives the origin fetch from the slot's poll,
19 * so the worker never stalls; every failure path fails open. Purge + stats round it out.
20 *
21 * @c work is PROTOCORE_EDGE_PROXY_BORROW bytes the CALLER took, at an address it knows. It is not held past the call,
22 * so nothing here aliases it. How those bytes are carved is this module's and is never named here.
23 *
24 * @author Douglas Quigg (dstroy0)
25 * @date 2026
26 */
27
28// Named at file scope first: a struct whose first mention is a parameter list is scoped to that one
29// prototype, so the table's members and the functions below would each name a different type.
30struct protocore_dbm;
31struct EdgeCacheStats;
32
33/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
34typedef struct
35{
36 void (*enable)(uint8_t *);
37 proto_bool (*map)(uint8_t *, const char *, const char *);
38 void (*bind_sd)(uint8_t *, struct protocore_dbm *);
39 proto_bool (*add_peer)(uint8_t *, const char *, uint16_t);
40 void (*mesh_serve)(uint8_t *);
41 void (*reset)(uint8_t *);
42 proto_bool (*purge)(uint8_t *, const char *);
43 uint32_t (*purge_prefix)(uint8_t *, const char *);
44 void (*stats)(uint8_t *, struct EdgeCacheStats *);
46PROTOCORE_NS_LAYOUT(EdgeProxyNs, enable, map, bind_sd, add_peer, mesh_serve, reset, purge, purge_prefix, stats);
47
48/**
49 * @brief Enable the edge cache on server: register the cache middleware + .
50 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
51 */
52void protocore_edge_proxy_enable(uint8_t *work);
53/**
54 * @brief Map a request path prefix to an upstream origin (e.g. "/cdn/" -> .
55 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
56 * @param path_prefix Path prefix
57 * @param origin_base_url Origin base url
58 * @return PROTO_TRUE on success.
59 */
60proto_bool protocore_edge_proxy_map(uint8_t *work, const char *path_prefix, const char *origin_base_url);
61/**
62 * @brief Bind an L2 persistent tier: an opened dbm handle (on a mounted WAL .
63 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
64 * @param dbm Dbm
65 */
66void protocore_edge_proxy_bind_sd(uint8_t *work, struct protocore_dbm *dbm);
67/**
68 * @brief Add a sibling peer to query on a full local miss before hitting the .
69 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
70 * @param host Host
71 * @param port Port
72 * @return PROTO_TRUE on success.
73 */
74proto_bool protocore_edge_proxy_add_peer(uint8_t *work, const char *host, uint16_t port);
75/**
76 * @brief Serve sibling queries: register the PROTO_MESH handler so this node .
77 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
78 */
80/**
81 * @brief Clear the L1 store, the L2 store (if bound), all route maps, and .
82 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
83 */
84void protocore_edge_proxy_reset(uint8_t *work);
85/**
86 * @brief Invalidate a single canonical key. true if an entry was purged.
87 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
88 * @param canonical_key Canonical key
89 * @return PROTO_TRUE on success.
90 */
91proto_bool protocore_edge_proxy_purge(uint8_t *work, const char *canonical_key);
92/**
93 * @brief Invalidate every entry whose request path begins with prefix. the .
94 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
95 * @param path_prefix Path prefix
96 * @return The uint32_t.
97 */
98uint32_t protocore_edge_proxy_purge_prefix(uint8_t *work, const char *path_prefix);
99/**
100 * @brief Snapshot the cache counters.
101 * @param work PROTOCORE_EDGE_PROXY_BORROW bytes the caller took. Not held past the call.
102 * @param out Out
103 */
104void protocore_edge_proxy_stats(uint8_t *work, struct EdgeCacheStats *out);
105
106/**
107 * @brief The PROTOCORE_EDGE_PROXY_BORROW bytes this module's state lives in.
108 *
109 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
110 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
111 * walks, so the state lasts the life of the program.
112 *
113 * @return the span.
114 */
116
117/** @brief Module namespace. */
127
129
130#endif // PROTOCORE_EDGE_CACHE_PROXY_H
proto_bool protocore_edge_proxy_purge(uint8_t *work, const char *canonical_key)
Invalidate a single canonical key. true if an entry was purged.
uint32_t protocore_edge_proxy_purge_prefix(uint8_t *work, const char *path_prefix)
Invalidate every entry whose request path begins with prefix. the .
PROTOCORE_NS EdgeProxyNs EdgeProxy PROTOCORE_UNUSED
Module namespace.
void protocore_edge_proxy_bind_sd(uint8_t *work, struct protocore_dbm *dbm)
Bind an L2 persistent tier: an opened dbm handle (on a mounted WAL .
void protocore_edge_proxy_stats(uint8_t *work, struct EdgeCacheStats *out)
Snapshot the cache counters.
void protocore_edge_proxy_enable(uint8_t *work)
Enable the edge cache on server: register the cache middleware + .
uint8_t * protocore_edge_cache_proxy_span(void)
The PROTOCORE_EDGE_PROXY_BORROW bytes this module's state lives in.
proto_bool protocore_edge_proxy_map(uint8_t *work, const char *path_prefix, const char *origin_base_url)
Map a request path prefix to an upstream origin (e.g. "/cdn/" -> .
void protocore_edge_proxy_reset(uint8_t *work)
Clear the L1 store, the L2 store (if bound), all route maps, and .
void protocore_edge_proxy_mesh_serve(uint8_t *work)
Serve sibling queries: register the PROTO_MESH handler so this node .
proto_bool protocore_edge_proxy_add_peer(uint8_t *work, const char *host, uint16_t port)
Add a sibling peer to query on a full local miss before hitting the .
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
Dispatch table. Addressed by offset, so the layout is asserted below.
void(* enable)(uint8_t *)
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97