diff options
| author | eunhhu <[email protected]> | 2026-10-04 12:46:34 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-04 12:46:34 +0100 |
| commit | 9fd2e16b68e1a83e2605e8a9cbd9b6d04a4da2f6 (patch) | |
| tree | 2ae9aaf2cc5f3e5d4eef0209d013ac8332c02984 /benchmarks/http/load.c | |
| parent | 1ff4fd3b1ae2b2ada273d7ffaee8501c9d43d5c0 (diff) | |
| download | pure-9fd2e16b68e1a83e2605e8a9cbd9b6d04a4da2f6.tar.gz pure-9fd2e16b68e1a83e2605e8a9cbd9b6d04a4da2f6.zip | |
Take an app's requests only with a token its tokens file grants (017, 3b)
An app given a tokens file (tokens=FILE in --apps, --tokens FILE for the
one app of a host) answers a request only when it bears a token
(Authorization: Bearer) whose SHA-256 the file lists with a grant: read
for its views, queries and documents, write for all, input=NAME for
those inputs alone; 401 unauthorized (WWW-Authenticate: Bearer) without
one, 403 forbidden past its grant. A delivery sealed by a key --sender
names needs none. The digests are compared in constant time; a
connection keeps its last token's digest, so the same token is hashed
once. SHA-256 is the host's own (serve/sha256.c), no OpenSSL loaded. A
reading puts a changed tokens file in place with the app running on; a
file that is not one stops the app. pure-serve --make-token GRANT makes
a token and its line. load takes PURE_LOAD_TOKEN.
Diffstat (limited to 'benchmarks/http/load.c')
| -rw-r--r-- | benchmarks/http/load.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/benchmarks/http/load.c b/benchmarks/http/load.c index c589979..721b36e 100644 --- a/benchmarks/http/load.c +++ b/benchmarks/http/load.c @@ -17,7 +17,9 @@ * the scale (100,000 accounts, 10 tellers and a branch each) and delta in * [-5000, 5000], as pgbench picks them. * PREFIX goes before every path: /NAME for an app of a host of apps - * (pure-serve --apps, docs/design/017-apps-on-one-host.md). + * (pure-serve --apps, docs/design/017-apps-on-one-host.md). With + * PURE_LOAD_TOKEN in the environment each request bears it + * (Authorization: Bearer, docs/design/017's 3b). * Prints one JSON line: requests/s, statuses, latency percentiles (µs). */ #include <arpa/inet.h> #include <errno.h> @@ -89,8 +91,9 @@ static uint64_t next_random(uint64_t *state) { return *state = x; } +static char closing[512]; /* the head's last lines: Connection: close, the token's */ + static void prepare(Connection *c) { - const char *closing = keep_alive ? "" : "Connection: close\r\n"; if (method == TRANSFER) { unsigned scale = keys / 100000 ? (unsigned)(keys / 100000) : 1; char json[128]; @@ -134,7 +137,7 @@ static void prepare(Connection *c) { } c->request_size = (size_t)snprintf(c->request, sizeof(c->request), "%s %s/objects/k%d HTTP/1.1\r\nHost: localhost\r\nContent-Length: %zu\r\n%s%s\r\n", - put ? "PUT" : "GET", prefix, c->key, put ? body_bytes + 8 : 0, condition, keep_alive ? "" : "Connection: close\r\n"); + put ? "PUT" : "GET", prefix, c->key, put ? body_bytes + 8 : 0, condition, closing); c->sent = c->received = c->body_sent = 0; c->body_size = put ? body_bytes + 8 : 0; c->started = now_us(); @@ -195,6 +198,10 @@ int main(int argc, char **argv) { keep_alive = argc > 6 && !strcmp(argv[6], "keep-alive"); body_bytes = argc > 7 ? strtoul(argv[7], NULL, 10) : 16; prefix = argc > 8 ? argv[8] : ""; + const char *token = getenv("PURE_LOAD_TOKEN"); + if (token && strlen(token) > 256) return 2; + snprintf(closing, sizeof(closing), "%s%s%s%s", keep_alive ? "" : "Connection: close\r\n", token ? "Authorization: Bearer " : "", + token ? token : "", token ? "\r\n" : ""); body = calloc(body_bytes + 32, 1); memset(body + 8, 'x', body_bytes); if (method == JSON) { |
