From f28cb902e5d3215380da9b01c221a3b05c106ade Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Sun, 8 Nov 2026 11:22:44 +0100 Subject: [PATCH] prototype-tile-leak: Q4 masked tiles vs cell-size tiles Co-Authored-By: Claude Sonnet 5.5 --- prototype-tile-leak/.gitignore | 8 + prototype-tile-leak/README.md | 121 +++++ prototype-tile-leak/config.nims | 4 + prototype-tile-leak/devbox.json | 36 ++ prototype-tile-leak/devbox.lock | 514 ++++++++++++++++++++++ prototype-tile-leak/nim.cfg | 3 + prototype-tile-leak/results/disk4096.log | 6 + prototype-tile-leak/results/maskbench.log | 47 ++ prototype-tile-leak/results/netbench.log | 34 ++ prototype-tile-leak/results/steps.log | 2 + prototype-tile-leak/src/art.nim | 35 ++ prototype-tile-leak/src/authsrv.nim | 50 +++ prototype-tile-leak/src/gen.nim | 10 + prototype-tile-leak/src/maskbench.nim | 169 +++++++ prototype-tile-leak/tilelk.nimble | 8 + prototype-tile-leak/tools/mime.types | 99 +++++ prototype-tile-leak/tools/netbench.sh | 69 +++ prototype-tile-leak/tools/nginx.conf | 21 + prototype-tile-leak/tools/steps.py | 16 + 19 files changed, 1252 insertions(+) create mode 100644 prototype-tile-leak/.gitignore create mode 100644 prototype-tile-leak/README.md create mode 100644 prototype-tile-leak/config.nims create mode 100644 prototype-tile-leak/devbox.json create mode 100644 prototype-tile-leak/devbox.lock create mode 100644 prototype-tile-leak/nim.cfg create mode 100644 prototype-tile-leak/results/disk4096.log create mode 100644 prototype-tile-leak/results/maskbench.log create mode 100644 prototype-tile-leak/results/netbench.log create mode 100644 prototype-tile-leak/results/steps.log create mode 100644 prototype-tile-leak/src/art.nim create mode 100644 prototype-tile-leak/src/authsrv.nim create mode 100644 prototype-tile-leak/src/gen.nim create mode 100644 prototype-tile-leak/src/maskbench.nim create mode 100644 prototype-tile-leak/tilelk.nimble create mode 100644 prototype-tile-leak/tools/mime.types create mode 100755 prototype-tile-leak/tools/netbench.sh create mode 100644 prototype-tile-leak/tools/nginx.conf create mode 100644 prototype-tile-leak/tools/steps.py diff --git a/prototype-tile-leak/.gitignore b/prototype-tile-leak/.gitignore new file mode 100644 index 0000000..17451cf --- /dev/null +++ b/prototype-tile-leak/.gitignore @@ -0,0 +1,8 @@ +.devbox/ +nimble.paths +data/ +run/ +bin/ +nimble.develop +nimbledeps +devbox.d/ diff --git a/prototype-tile-leak/README.md b/prototype-tile-leak/README.md new file mode 100644 index 0000000..0759b40 --- /dev/null +++ b/prototype-tile-leak/README.md @@ -0,0 +1,121 @@ +# prototype-tile-leak (throwaway): DESIGN.md Q4 / H8 / T5, tile-edge leak + +## Question +DESIGN 3.3: a 256 px tile is served iff >=1 explored 32 px cell overlaps it, so up to 255x255 px of unexplored art reaches the browser (devtools). Which fix is cheapest: (A) server-side per-player masked 256 px tiles, or (B) tiles the size of an explored cell (32 px; 64 px for comparison) served as-is? + +**Fact, not prototyped:** client-side fog, flattening or masking cannot fix this. The bytes are already in the browser (network tab, cache, decoded texture) before any client code runs. Only what the server sends counts. + +## Method +- Art: procedural pure function of world coords (`src/art.nim`), so every tile size slices the same picture. Two noise levels bracket real art: `g6` (smooth, 256 px PNG ~83 KB) and `g40` (grainy, ~133 KB). **Synthetic: absolute sizes/ms depend on real art, ratios are what matter.** +- A: `src/maskbench.nim`. Decode PNG, set unexplored 32 px cells to opaque black (0,0,0,255), encode. Median of 200 runs, single thread, `-d:release`. Then replay of the real explored transcripts of `prototype-server-vision/results/leak-A.jsonl` (subjects A: 94 explored msgs, 2142 cells; B: 39 msgs, 1114 cells) on the 4096 px / 256 px-tile / 32 px-cell scene: every tile whose mask changed is re-masked for real. +- B: `src/gen.nim` slices the 4096 px map into 32/64/256 px PNG files, measures disk. `src/authsrv.nim` (mummy, same shape as the vision prototype tile route: strict path parse, cookie lookup, explored-cell range check under a lock, `X-Accel-Redirect`) behind nginx (4 workers, `internal` alias). Load by `h2load` (nghttp2) on loopback, `tools/netbench.sh`. Requests/step computed by replaying the same transcripts. +- Machine: AMD Ryzen 7 7840U, 16 threads, NixOS, kernel 6.18, governor left on `powersave` (as in the other prototypes). Page cache hot (cold disk not measured). Run-to-run noise on req/s is roughly +-30%. +- Lib check (pixie 6.1.0, nimPNG 0.3.6): APIs checked in source + context7 docs, not memory. + +## Library choice (A) +| | pixie 6.1.0 | nimPNG 0.3.6 | +|---|---|---| +| dec+mask+enc, 1..63 of 64 cells explored | 1.6..10.9 ms | 9.3..26.5 ms | +| output size vs pixie | baseline | 5-25% smaller (auto palette/gray, MINSUM filter); all-black tile 88 B vs 853 B | +| deps | 7 pure-Nim pkgs (vmath chroma bumpy flatty zippy nimsimd crunchy), ~1.4 MB source | 0, ~0.24 MB source | +Pick **pixie**: 2-3x faster, `decodePng`/`encodePng` expose raw RGBA so masking is a plain loop; nimPNG only if bytes matter more than CPU. No C libs in either (devbox stays minimal). Pixie has no compression-level knob via `encodePng` (zippy default). [MEASURED `results/maskbench.log`] + +## Numbers + +### A. Masked 256 px tiles (MEASURED, `results/maskbench.log`) +Per tile, pixie, ms (out bytes), explored cells of 64: +| cells | g6 ms (B) | g40 ms (B) | +|---|---|---| +| 0 | 1.5 (853) | 1.8 (853) | +| 1 | 1.7 (3.2K) | 1.9 (4.0K) | +| 8 | 2.4 (12.7K) | 2.5 (19.7K) | +| 32 | 6.0 (43.6K) | 5.5 (69.0K) | +| 63 | 10.9 (82.2K) | 9.5 (131.5K) | +| 64 (all) | 0: serve the original file, no image work | 0 | +Decode alone 0.8-1.0 ms; encode dominates (8-10 ms for a full tile). Exact-polygon variant (naive per-pixel even-odd, 32-gon): 6.3-6.7 ms, an upper bound, a scanline fill would be about cell-mask cost. + +Replay, subject A (B similar), 4096 px map, g6 / g40: +- tiles touched 71 (of 256); **366 re-masks in 94 steps = 3.9 tiles/step avg (max 13, the connect burst)**; CPU **20 ms/step avg, worst 70 ms**, per-step cost parallelisable over tiles, must run outside the state lock (vision recompute for comparison: 1.18 ms/move). +- Bytes to client: masked **13.1 / 20.7 MB** vs whole-tile 5.8 / 9.5 MB (each tile once) = **x2.0-2.2**, because every tile whose mask grows must be refetched (new URL/version per tile, client must be told which tiles changed: protocol + client change). +- Per-player cache of final masked tiles: A **2.9 / 4.6 MB** (71 tiles, ~41-65 KB each), B 1.5 / 2.4 MB (35 tiles). It scales with explored area, not map size. 16384 px map (4096 tiles) worst case if every tile were partial: <= the original art, 340-545 MB per player [INFERRED, = 4096 x tile size]. Old versions evictable. +- Re-mask when explored grows: only tiles whose cell set changed (above), results keyed (tile, mask-hash) so reconnects/other connections of the same player are free. +- Leak assert (MEASURED): for n in {0,1,8,32,63} cells, through pixie AND nimPNG, a 8x8 pure-red "secret" is planted in every unexplored cell; asserts: no red pixel in output, every unexplored pixel == (0,0,0,255), every explored pixel identical to source. Pass. + +### B. Cell-size tiles +Tile counts [arithmetic]: 4096 px map: 32 px 16,384 / 64 px 4,096 / 256 px 256. 16384 px map: **262,144 / 65,536 / 4,096**. +Disk, 4096 px map, MEASURED (`results/disk4096.log`); 16384 px = x16 [INFERRED]. "on-disk" = 4 KiB filesystem blocks (ext4): +| tile | files | apparent g6 / g40 | on-disk g6 / g40 | 16384 px apparent g6/g40 | 16384 px on-disk g6/g40 | +|---|---|---|---|---|---| +| 256 | 256 | 21.1 / 34.1 MB | 21.2 / 33.8 MB | 337 / 545 MB | 339 / 541 MB | +| 64 | 4,096 | 24.6 / 38.6 MB (+17/+13%) | 32.9 / 49.3 MB | 393 / 618 MB | 526 / 788 MB | +| 32 | 16,384 | 28.4 / 43.5 MB (+35/+28%) | 66.0 / 66.0 MB | 454 / 696 MB | 1.06 GB (262k inodes) | +Small PNGs lose compression context and pay ~60 B header + one 4 KiB block each; no image work at serve time. + +Requests per exploration step, MEASURED by transcript replay (`results/steps.log`), NEW tiles per step (a cell tile is fetched once, never again): +| | connect burst | steady median | p95 | max | total (A, 94 steps) | +|---|---|---|---|---|---| +| 32 px | 292 | 11 | 37 | 164 | 2142 | +| 64 px | 87 | 3 | 11 | 46 | 603 | +| 256 px whole (today) | 13 | 0 | 3 | 6 | 71 | +| 256 px masked (refetch on change) | - | - | - | 13 | 366 | +Bytes for A: 32 px 3.7 / 5.7 MB, 64 px 3.6 / 5.7 MB (count x avg tile bytes, g6 / g40) vs whole-256 5.8 / 9.5 MB vs masked-256 13.1 / 20.7 MB. Cell tiles send LESS than today, masking sends 2x more. + +Serving, MEASURED (`results/netbench.log`), loopback, 20000 reqs, nginx -> Nim auth -> X-Accel-Redirect, upstream keepalive on: +| case | req/s | median / p99 | +|---|---|---| +| 32 px h1 c=1 (unloaded) | 10.4k | 90 us / 149 us | +| 256 px h1 c=1 (unloaded) | 7.2k | 132 us / 211 us | +| 32 px h1 c=6 (browser-like) | 46k | 122 us / 188 us | +| 64 px h1 c=6 | 45k | 127 us / 213 us | +| 256 px h1 c=6 | 19k | 296 us / 636 us (byte bound, ~83 KB each) | +| 32 px h1 c=32 | 54k | 480 us / 724 us | +| 32 px STATIC (no Nim, no auth) h1 c=32 | 87k | 332 us / 534 us | +| 32 px h2 c=1 m=100 | 18.6k | 5.1 ms / 8.9 ms (queued 100 deep) | +| 32 px h2 c=4 m=100 | 19.9k | 5.6 ms / 25 ms | +| burst 292 x 32 px, h1 c=6 | 7-16 ms wall (3 runs) | | +| burst 292 x 32 px, h2 c=1 m=100 | ~16-22 ms wall | | +| upstream keepalive off, 32 px h1 c=32 | 55k | same as on (loopback connect is cheap) | +- Nim auth hop costs ~35% throughput vs static nginx (54k vs 87k) and ~50 us unloaded, still 1000x the need (steady 11 req/step). +- HTTP/2 on loopback: **no gain** (one h2 connection is served by one nginx worker, ~20k req/s; h1 c=32 spreads over 4 workers). Loopback has RTT ~0, so the real h2 benefit (no 6-connection limit) is **not measurable here**. INFERRED: burst of 292 over h1 with 6 conns = ~49 round trips, ~2.4 s at 50 ms RTT, vs ~1-2 RTT + transfer on h2. TLS not measured. Needs h2 in the real nginx (HTTPS deploy gets it with `http2 on`). Note nginx default `keepalive_requests 1000` closes the h2 connection; h2load does not reconnect, hence `keepalive_requests 1000000` in the bench conf (a browser reconnects transparently). +- Not measured: client cost of 2142+ small Pixi sprites/textures (INFERRED fine with batching; the client can also blit received cell tiles into one RenderTexture per 256 px block). + +### C. Leak bound demo (MEASURED, `devbox run netbench`, first section; asserts exit 1 on mismatch) +Explored = left half + one lone cell (64,3) just outside it; every tile of each size requested; allowed count must be half + 1 (PASS all three). +| tile | unexplored px revealed by the lone cell's tile | +|---|---| +| 32 px | **0** | +| 64 px | 3,072 (3 cells) | +| 256 px (today) | 64,512 (63 cells) | +Masked 256 px: 0 beyond explored cells, asserted pixel-exact in A (above). + +## Comparison +| | 256 whole (today) | A masked 256 | B1 32 px tiles | B2 64 px tiles | +|---|---|---|---|---| +| leak beyond explored cells | up to 63 cells/tile | 0 | **0** | <= 3 cells/tile | +| server CPU | 0 | ~20 ms per step (avg), 70 ms burst, pixie | ~0.1 ms/req (auth) | same | +| bytes per run (A) | 5.8-9.5 MB | 13.1-20.7 MB | 3.7-5.7 MB | 3.6-5.7 MB | +| requests per step (median/burst) | 0 / 13 | ~4 / 13 refetch | 11 / 292 | 3 / 87 | +| storage 4096 px | 21-34 MB | + per-player cache 1.5-4.6 MB | 28-43 MB (66 MB on disk) | 25-39 MB (33-49 on disk) | +| storage 16384 px | 340-545 MB | + per-player <= 340-545 MB worst | 454-696 MB, 1.06 GB on disk, 262k files | 393-618 MB, 526-788 MB on disk, 65k files | +| deps / new code | none | pixie (7 pkgs), mask+cache+versioned URLs+refetch protocol | importer cuts 32 px tiles | importer cuts 64 px tiles | +| HTTP/2 needed | no | no | yes (INFERRED) | helpful | +| cacheability | immutable | per-version | immutable, never refetched | same | + +## Recommendation +**B1: set `tile_size` = explored cell (32 px).** DESIGN already requires `tile_size % cell == 0`, so this is a scene-config change plus importer slicing; no image library in the server, no per-player state, rule "tile allowed iff its cell is explored" becomes exact (zero beyond-cell leak, MEASURED assert C). Total bytes to the client go DOWN vs today; masking doubles them and costs ~20 ms CPU/step plus a refetch protocol for the same residual leak. Fall back to **64 px** if 262k files / ~1 GB on-disk for a 16384 px map is unwelcome (leak <= 3 cells per allowed tile, 4x fewer files). Keep masking (pixie) only if tiles must stay large for another reason; do not build it for Q4 alone. Require h2 in the nginx config. + +**Residual leak (all options, incl. masked):** granularity of fog = the explored cell. A cell the polygon only grazed is disclosed entirely (<= 32x32 px beyond what LOS actually saw), and once sent never revoked. Authoring rule shrinks from "~256 px around reachable areas" to "~32 px". Exact-polygon masking would close it but needs per-pixel explored state and ~same CPU as cell masking (6-7 ms/tile naive), not worth it. Also unchanged: static art only, doors not in tiles. + +## Caveats +Synthetic art (real painted maps compress differently; ratios hold, absolutes move). Loopback only: no RTT, no TLS, no real browser; h2 benefit INFERRED. Hot page cache. Single laptop in powersave. 16384 px figures are x16 extrapolations. One scene/one player load; no concurrency mix with WS traffic. + +## Run +``` +cd prototype-tile-leak +devbox run setup # nimble setup (fetches pixie, nimPNG, mummy) +devbox run build # bin/maskbench bin/gen bin/authsrv +devbox run gen # data/g6, data/g40 tiles (~20 s, ~0.3 GB, gitignored) + results/disk4096.log +devbox run maskbench # results/maskbench.log (~30 s) +devbox run netbench # leak-bound demo + h2load matrix -> results/netbench.log +``` +`results/steps.log`: `python3 tools/steps.py > results/steps.log` (replays `../prototype-server-vision/results/leak-A.jsonl`; first message = connect burst, excluded from steady stats). diff --git a/prototype-tile-leak/config.nims b/prototype-tile-leak/config.nims new file mode 100644 index 0000000..8ee48d2 --- /dev/null +++ b/prototype-tile-leak/config.nims @@ -0,0 +1,4 @@ +# begin Nimble config (version 2) +when withDir(thisDir(), system.fileExists("nimble.paths")): + include "nimble.paths" +# end Nimble config diff --git a/prototype-tile-leak/devbox.json b/prototype-tile-leak/devbox.json new file mode 100644 index 0000000..6870a77 --- /dev/null +++ b/prototype-tile-leak/devbox.json @@ -0,0 +1,36 @@ +{ + "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.17.2/.schema/devbox.schema.json", + "packages": { + "nim": "2", + "nimble": "latest", + "nginx": "latest", + "nghttp2": "latest", + "curl": "latest" + }, + "env": { + "NIMBLE_DIR": "$DEVBOX_PROJECT_ROOT/.devbox/nimble" + }, + "shell": { + "init_hook": [], + "scripts": { + "setup": [ + "nimble setup -y", + "mkdir -p bin results" + ], + "build": [ + "for f in maskbench gen authsrv; do nim c -d:release --hints:off --warnings:off -o:bin/$f src/$f.nim || exit 1; done" + ], + "gen": [ + "bin/gen data/g6 6", + "bin/gen data/g40 40", + "for g in g6 g40; do for s in 256 64 32; do d=data/$g/tiles$s; echo \"$g $s files=$(ls $d | wc -l) apparent=$(du -sb $d | cut -f1) onDisk(4K blocks)=$(du -sk $d | cut -f1)KiB\"; done; done | tee results/disk4096.log" + ], + "maskbench": [ + "bin/maskbench ../prototype-server-vision/results/leak-A.jsonl | tee results/maskbench.log" + ], + "netbench": [ + "tools/netbench.sh | tee results/netbench.log" + ] + } + } +} \ No newline at end of file diff --git a/prototype-tile-leak/devbox.lock b/prototype-tile-leak/devbox.lock new file mode 100644 index 0000000..1c197e8 --- /dev/null +++ b/prototype-tile-leak/devbox.lock @@ -0,0 +1,514 @@ +{ + "lockfile_version": "1", + "packages": { + "curl@latest": { + "last_modified": "2025-12-05T15:03:55Z", + "resolved": "github:NixOS/nixpkgs/a672be65651c80d3f592a89b3945466584a22069#curl", + "source": "devbox-search", + "version": "8.17.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "bin", + "path": "/nix/store/qfwqcndy8bji6xww0gizclf2nqi2qpph-curl-8.17.0-bin", + "default": true + }, + { + "name": "man", + "path": "/nix/store/rk815zvrhwzbi7c6d589v2mhxzyzb400-curl-8.17.0-man", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/ydp55g2mbd6rk6lfw0krkk3jwgdiqj5d-curl-8.17.0-dev" + }, + { + "name": "devdoc", + "path": "/nix/store/8s884m82fmrbiyz8malglqc4sd632dkc-curl-8.17.0-devdoc" + }, + { + "name": "out", + "path": "/nix/store/yxv8fxaz0fyhc31dv3rz89kc50zw5hgj-curl-8.17.0" + } + ], + "store_path": "/nix/store/qfwqcndy8bji6xww0gizclf2nqi2qpph-curl-8.17.0-bin" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "bin", + "path": "/nix/store/4x19j6zihdl6pya63xs8g360f2r614sx-curl-8.17.0-bin", + "default": true + }, + { + "name": "man", + "path": "/nix/store/b29qbmbfvzkm34k0jnj8ykqg2gzj3rdy-curl-8.17.0-man", + "default": true + }, + { + "name": "debug", + "path": "/nix/store/5hmbdk99knmbg8b0fzh96bv6bkcf6v5i-curl-8.17.0-debug" + }, + { + "name": "dev", + "path": "/nix/store/iqs9mjscns3h5npgkrhgr5xa7qzwd0si-curl-8.17.0-dev" + }, + { + "name": "devdoc", + "path": "/nix/store/1fwncv08c8g78k3hj3cj375vx92ndrp8-curl-8.17.0-devdoc" + }, + { + "name": "out", + "path": "/nix/store/b0a6qc92vybjiggh0kg387cg0zp3kl6j-curl-8.17.0" + } + ], + "store_path": "/nix/store/4x19j6zihdl6pya63xs8g360f2r614sx-curl-8.17.0-bin" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "bin", + "path": "/nix/store/w2336wv560g1n58cwashmmczdn3bfkq1-curl-8.17.0-bin", + "default": true + }, + { + "name": "man", + "path": "/nix/store/i6xmhcan8g4abda7ivv20nvwxrsssjqj-curl-8.17.0-man", + "default": true + }, + { + "name": "devdoc", + "path": "/nix/store/ipa7v9z7pjcnnv0fmdya1fldcxv0a28z-curl-8.17.0-devdoc" + }, + { + "name": "out", + "path": "/nix/store/x9gyg634fi8mgcyay9mqa1ral7xg72fm-curl-8.17.0" + }, + { + "name": "dev", + "path": "/nix/store/39zfdgq9kg3mb4sycf8pj4pdssrzki6c-curl-8.17.0-dev" + } + ], + "store_path": "/nix/store/w2336wv560g1n58cwashmmczdn3bfkq1-curl-8.17.0-bin" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "bin", + "path": "/nix/store/0rfz69vp1nl0q2hxzig20hc60sk72z62-curl-8.17.0-bin", + "default": true + }, + { + "name": "man", + "path": "/nix/store/ijd0yybyzwm98d3q6x7a9cyixgxk0i5d-curl-8.17.0-man", + "default": true + }, + { + "name": "debug", + "path": "/nix/store/h1fxw0xrifxvbhcp7b8hxsgirxxxfzav-curl-8.17.0-debug" + }, + { + "name": "dev", + "path": "/nix/store/ikmdk37frjdblkba3wl3xws2wwgln17x-curl-8.17.0-dev" + }, + { + "name": "devdoc", + "path": "/nix/store/jm6irg81cc0hqg43l39lkxr6pb0w2xk5-curl-8.17.0-devdoc" + }, + { + "name": "out", + "path": "/nix/store/8idis3j5l13c3x74jl8xly0k4qyk9mx6-curl-8.17.0" + } + ], + "store_path": "/nix/store/0rfz69vp1nl0q2hxzig20hc60sk72z62-curl-8.17.0-bin" + } + } + }, + "gawk@latest": { + "last_modified": "2026-10-02T22:55:44Z", + "resolved": "github:NixOS/nixpkgs/55ba7f49ef2962b42cbd126522b7df5f95037679#gawk", + "source": "devbox-search", + "version": "5.4.1", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/49jhcfya6jlc7p2hibbl2y5sfz132j3i-gawk-5.4.1", + "default": true + }, + { + "name": "man", + "path": "/nix/store/1sclicd2js7iipqnw4vn1rmy3scjg72v-gawk-5.4.1-man", + "default": true + }, + { + "name": "info", + "path": "/nix/store/n8gfvirxjm8z5zq7cx30qrmhn40w7jrb-gawk-5.4.1-info" + } + ], + "store_path": "/nix/store/49jhcfya6jlc7p2hibbl2y5sfz132j3i-gawk-5.4.1" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/2bwpli20ff4f7hg5ck477p8s57kj857w-gawk-5.4.1", + "default": true + }, + { + "name": "man", + "path": "/nix/store/wfnxkfk386wl2plrhqx7lwfj4z84r493-gawk-5.4.1-man", + "default": true + }, + { + "name": "info", + "path": "/nix/store/l6wddbkc3rxavhbxyl48gn47rw8fq0pd-gawk-5.4.1-info" + } + ], + "store_path": "/nix/store/2bwpli20ff4f7hg5ck477p8s57kj857w-gawk-5.4.1" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/63g104xwbzfpcq0h7c99w19m6j9ly3p1-gawk-5.4.1", + "default": true + }, + { + "name": "man", + "path": "/nix/store/0azvqykndxs3clnj974q99cjfnmpprjv-gawk-5.4.1-man", + "default": true + }, + { + "name": "info", + "path": "/nix/store/l4pwpdc6hrgy8n3diy24n389k53jqqjk-gawk-5.4.1-info" + } + ], + "store_path": "/nix/store/63g104xwbzfpcq0h7c99w19m6j9ly3p1-gawk-5.4.1" + } + } + }, + "gettext@latest": { + "last_modified": "2026-10-02T22:55:44Z", + "resolved": "github:NixOS/nixpkgs/55ba7f49ef2962b42cbd126522b7df5f95037679#gettext", + "source": "devbox-search", + "version": "1.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/d73j7348argskpyvj28wq8n65mj6yg9x-gettext-1.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/arv8546qvpn8cr2bsgvzbzzzypmdv1kp-gettext-1.0-man", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/4myr9gbsxvryjnwanyyhnnpqrdh56d5n-gettext-1.0-doc" + }, + { + "name": "info", + "path": "/nix/store/b4d4imijjkkzr49zh5mq4gz2j9m2s047-gettext-1.0-info" + } + ], + "store_path": "/nix/store/d73j7348argskpyvj28wq8n65mj6yg9x-gettext-1.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/8aimx510wyy0rzy7mllcjad5299jd17a-gettext-1.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/qllbgswyx416d7r7kqkyxvafpfbasmr8-gettext-1.0-man", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/r2d6saacyqv8m9d8bvaidv4x2raqjb7z-gettext-1.0-doc" + }, + { + "name": "info", + "path": "/nix/store/hsrnhwfpvrs4x4a5807cprpyz4qclgxy-gettext-1.0-info" + } + ], + "store_path": "/nix/store/8aimx510wyy0rzy7mllcjad5299jd17a-gettext-1.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/9mxzw5vwn99vx2b74ipjzk8x4b784fjy-gettext-1.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/r87hlf9pn8q3a8rnplzhy9lbgaadqcr8-gettext-1.0-man", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/xmssbi5i2w3fv67hrv6c29wdiv8gxywi-gettext-1.0-doc" + }, + { + "name": "info", + "path": "/nix/store/j4lz4zqicd1mw2l5c272ialxhl0nkc0b-gettext-1.0-info" + } + ], + "store_path": "/nix/store/9mxzw5vwn99vx2b74ipjzk8x4b784fjy-gettext-1.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/gfkkr23q11kvyz6xxyxz3qbsp1msxdcv-gettext-1.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/njdszjnrb0n7c6m6jzmx5539ac0ybn9g-gettext-1.0-man", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/z2p7kr1a45gz9m9g3s6rary2avk3gs9x-gettext-1.0-doc" + }, + { + "name": "info", + "path": "/nix/store/8vqnaf3h4vlb8q5w9z9kscqld7m5rdif-gettext-1.0-info" + } + ], + "store_path": "/nix/store/gfkkr23q11kvyz6xxyxz3qbsp1msxdcv-gettext-1.0" + } + } + }, + "github:NixOS/nixpkgs/nixpkgs-unstable": { + "last_modified": "2026-10-20T14:23:57Z", + "resolved": "github:NixOS/nixpkgs/5adc50831c259f87faeb09ddf930d43597197473?lastModified=1792506237&narHash=sha256-Q%2F8KLB6jNfpaUN1HAedE%2Fu%2FEt9feE%2FzYSsutBLKrCFk%3D" + }, + "nghttp2@latest": { + "last_modified": "2026-10-08T19:21:32Z", + "resolved": "github:NixOS/nixpkgs/8edc0c72e3a38faf5434e40d1f19431125fe4b30#nghttp2", + "source": "devbox-search", + "version": "1.70.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/8p19fbn4slkvk18j3bvjjh4yhp0d32wf-nghttp2-1.70.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/ijqj81fibram571b285bv0knwz5r3qki-nghttp2-1.70.0-man", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/idl71hpg6zlvwdm4flp2hr9pxmxw6ppr-nghttp2-1.70.0-dev" + }, + { + "name": "doc", + "path": "/nix/store/r7dwv4hibaqkbkq0kr4g80ci6a9fdl2w-nghttp2-1.70.0-doc" + }, + { + "name": "lib", + "path": "/nix/store/imwjr83lb0xlhz4ssq96kj8qbqk6qivs-nghttp2-1.70.0-lib" + } + ], + "store_path": "/nix/store/8p19fbn4slkvk18j3bvjjh4yhp0d32wf-nghttp2-1.70.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/kgnsbgqd6wbfkk0w9ggsfmaphhfycdpw-nghttp2-1.70.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/mf4xap4xwy757l2mn6z19c9vlwnsg9az-nghttp2-1.70.0-man", + "default": true + }, + { + "name": "lib", + "path": "/nix/store/6pv315yv0ccxd5h26zhj0i6mgn7q3brj-nghttp2-1.70.0-lib" + }, + { + "name": "dev", + "path": "/nix/store/bvf03id3xxgkpkw2ay29j5k6hcqivgk7-nghttp2-1.70.0-dev" + }, + { + "name": "doc", + "path": "/nix/store/dg8m57h861pzxb4xml1rpxakvkkli1nn-nghttp2-1.70.0-doc" + } + ], + "store_path": "/nix/store/kgnsbgqd6wbfkk0w9ggsfmaphhfycdpw-nghttp2-1.70.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/dpacn35xr3iajmgvcprb63hnxby21gpx-nghttp2-1.70.0", + "default": true + }, + { + "name": "man", + "path": "/nix/store/rja4jsc58spfj44gscpaa6shnmqgijj7-nghttp2-1.70.0-man", + "default": true + }, + { + "name": "dev", + "path": "/nix/store/9ia7882m3hhvdk6qi4p3p650pfhxg75r-nghttp2-1.70.0-dev" + }, + { + "name": "doc", + "path": "/nix/store/w9fm1rnnl71p5m9wy6sn9hb11p35bf5p-nghttp2-1.70.0-doc" + }, + { + "name": "lib", + "path": "/nix/store/sky8mslz50n51np0z4vhdq61jba12fh2-nghttp2-1.70.0-lib" + } + ], + "store_path": "/nix/store/dpacn35xr3iajmgvcprb63hnxby21gpx-nghttp2-1.70.0" + } + } + }, + "nginx@latest": { + "last_modified": "2026-10-02T22:55:44Z", + "plugin_version": "0.0.4", + "resolved": "github:NixOS/nixpkgs/55ba7f49ef2962b42cbd126522b7df5f95037679#nginx", + "source": "devbox-search", + "version": "1.30.5", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/81a75xq2ilmn8dnrb1b7m8siyprmaq94-nginx-1.30.5", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/s9zq3wyd2bdfwb58rk2648yf2wsryvhj-nginx-1.30.5-doc" + } + ], + "store_path": "/nix/store/81a75xq2ilmn8dnrb1b7m8siyprmaq94-nginx-1.30.5" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/7yvpd3svx846fybmc2d5ddxq3jxf94qm-nginx-1.30.5", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/skp8nki2v0li5h44zyp1gp8s2ahz3g4j-nginx-1.30.5-doc" + } + ], + "store_path": "/nix/store/7yvpd3svx846fybmc2d5ddxq3jxf94qm-nginx-1.30.5" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/6k4rgdzx05z7yk2l98r28p6wrbnlv63z-nginx-1.30.5", + "default": true + }, + { + "name": "doc", + "path": "/nix/store/d8v365rflmpicpcnxjqfxbbzlpk0q844-nginx-1.30.5-doc" + } + ], + "store_path": "/nix/store/6k4rgdzx05z7yk2l98r28p6wrbnlv63z-nginx-1.30.5" + } + } + }, + "nim@2": { + "last_modified": "2026-10-02T22:55:44Z", + "resolved": "github:NixOS/nixpkgs/55ba7f49ef2962b42cbd126522b7df5f95037679#nim", + "source": "devbox-search", + "version": "2.2.12", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/h055h3lxxsm8kql0mannw3706x740x7f-arm64-apple-darwin-nim-wrapper-2.2.12", + "default": true + } + ], + "store_path": "/nix/store/h055h3lxxsm8kql0mannw3706x740x7f-arm64-apple-darwin-nim-wrapper-2.2.12" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/2fh7rg634j8969c1r394llrsjmmhaip7-aarch64-unknown-linux-gnu-nim-wrapper-2.2.12", + "default": true + } + ], + "store_path": "/nix/store/2fh7rg634j8969c1r394llrsjmmhaip7-aarch64-unknown-linux-gnu-nim-wrapper-2.2.12" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/0cbdz34lsakfirycixckf6ypsd8hazhg-x86_64-unknown-linux-gnu-nim-wrapper-2.2.12", + "default": true + } + ], + "store_path": "/nix/store/0cbdz34lsakfirycixckf6ypsd8hazhg-x86_64-unknown-linux-gnu-nim-wrapper-2.2.12" + } + } + }, + "nimble@latest": { + "last_modified": "2026-10-02T22:55:44Z", + "resolved": "github:NixOS/nixpkgs/55ba7f49ef2962b42cbd126522b7df5f95037679#nimble", + "source": "devbox-search", + "version": "0.24.1", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/clxsxdsqjfcc43rfd7rad733nd0ndrkf-nimble-0.24.1", + "default": true + } + ], + "store_path": "/nix/store/clxsxdsqjfcc43rfd7rad733nd0ndrkf-nimble-0.24.1" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/c5d0r4a8qi1vqs8q82pr3c652q8d6jv7-nimble-0.24.1", + "default": true + } + ], + "store_path": "/nix/store/c5d0r4a8qi1vqs8q82pr3c652q8d6jv7-nimble-0.24.1" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/8f5wx2s80gnw0lkmdpbl63n1xlilcfxi-nimble-0.24.1", + "default": true + } + ], + "store_path": "/nix/store/8f5wx2s80gnw0lkmdpbl63n1xlilcfxi-nimble-0.24.1" + } + } + } + } +} diff --git a/prototype-tile-leak/nim.cfg b/prototype-tile-leak/nim.cfg new file mode 100644 index 0000000..f5312a0 --- /dev/null +++ b/prototype-tile-leak/nim.cfg @@ -0,0 +1,3 @@ +--path:"src" +--threads:on +--mm:orc diff --git a/prototype-tile-leak/results/disk4096.log b/prototype-tile-leak/results/disk4096.log new file mode 100644 index 0000000..07845dd --- /dev/null +++ b/prototype-tile-leak/results/disk4096.log @@ -0,0 +1,6 @@ +g6 256 files=256 apparent=21058156 onDisk(4K blocks)=21212KiB +g6 64 files=4096 apparent=24591931 onDisk(4K blocks)=32896KiB +g6 32 files=16384 apparent=28351600 onDisk(4K blocks)=66032KiB +g40 256 files=256 apparent=34066608 onDisk(4K blocks)=33804KiB +g40 64 files=4096 apparent=38628790 onDisk(4K blocks)=49280KiB +g40 32 files=16384 apparent=43489123 onDisk(4K blocks)=66032KiB diff --git a/prototype-tile-leak/results/maskbench.log b/prototype-tile-leak/results/maskbench.log new file mode 100644 index 0000000..1fb0fdb --- /dev/null +++ b/prototype-tile-leak/results/maskbench.log @@ -0,0 +1,47 @@ +## part 1: per-tile mask timing (median of 200, single thread, -d:release) + +[smooth(grain 6)] source tile PNG 82923 B +pixie decode 0.78 ms, encode(full tile) 10.27 ms +explored cells/64 | pixie dec+mask+enc ms | out B | nimPNG dec+mask+enc ms | out B | leak assert + 0 | 1.53 | 853 | 5.85 | 88 | OK + 1 | 1.65 | 3161 | 9.31 | 2524 | OK + 8 | 2.38 | 12717 | 10.66 | 10515 | OK + 32 | 6.03 | 43590 | 17.59 | 39884 | OK + 63 | 10.90 | 82182 | 26.45 | 77961 | OK +exact-polygon variant (naive per-pixel 32-gon, r=90): 6.67 ms (upper bound; scanline fill ~ cell-mask cost) +full-explored tile: no image work, serve original file (X-Accel-Redirect), 0 ms + +[noisy(grain 40)] source tile PNG 133202 B +pixie decode 1.05 ms, encode(full tile) 8.42 ms +explored cells/64 | pixie dec+mask+enc ms | out B | nimPNG dec+mask+enc ms | out B | leak assert + 0 | 1.79 | 853 | 7.03 | 88 | OK + 1 | 1.92 | 3992 | 10.02 | 2905 | OK + 8 | 2.49 | 19678 | 11.51 | 15446 | OK + 32 | 5.46 | 69006 | 16.37 | 59496 | OK + 63 | 9.47 | 131530 | 22.90 | 116705 | OK +exact-polygon variant (naive per-pixel 32-gon, r=90): 6.26 ms (upper bound; scanline fill ~ cell-mask cost) +full-explored tile: no image work, serve original file (X-Accel-Redirect), 0 ms + +[replay leak-A.jsonl subject A, grain 6.0] msgs(steps) 94, explored cells 2142, tiles touched 71 + masked: 366 tile re-masks total (3.9/step, max 13/step), CPU 1895. ms total, 20.16 ms/step avg, worst step 69.6 ms + bytes to client: masked 13119275 B (every changed tile refetched) vs whole-tile 5840697 B (each tile once) = x2.2 + 256 px whole tiles requested: 71; 64 px tiles: 603; 32 px tiles: 2142 + mask-cache @4096^2 for this player (final masks, 71 tiles): 2911366 B measured (final masked PNG of each touched tile; whole-tile originals 5840697 B) + +[replay leak-A.jsonl subject A, grain 40.0] msgs(steps) 94, explored cells 2142, tiles touched 71 + masked: 366 tile re-masks total (3.9/step, max 13/step), CPU 1866. ms total, 19.85 ms/step avg, worst step 65.7 ms + bytes to client: masked 20667087 B (every changed tile refetched) vs whole-tile 9450085 B (each tile once) = x2.2 + 256 px whole tiles requested: 71; 64 px tiles: 603; 32 px tiles: 2142 + mask-cache @4096^2 for this player (final masks, 71 tiles): 4634322 B measured (final masked PNG of each touched tile; whole-tile originals 9450085 B) + +[replay leak-A.jsonl subject B, grain 6.0] msgs(steps) 39, explored cells 1114, tiles touched 35 + masked: 165 tile re-masks total (4.2/step, max 13/step), CPU 857. ms total, 21.98 ms/step avg, worst step 65.8 ms + bytes to client: masked 5934612 B (every changed tile refetched) vs whole-tile 2877289 B (each tile once) = x2.1 + 256 px whole tiles requested: 35; 64 px tiles: 314; 32 px tiles: 1114 + mask-cache @4096^2 for this player (final masks, 35 tiles): 1510572 B measured (final masked PNG of each touched tile; whole-tile originals 2877289 B) + +[replay leak-A.jsonl subject B, grain 40.0] msgs(steps) 39, explored cells 1114, tiles touched 35 + masked: 165 tile re-masks total (4.2/step, max 13/step), CPU 820. ms total, 21.02 ms/step avg, worst step 61.9 ms + bytes to client: masked 9370062 B (every changed tile refetched) vs whole-tile 4654862 B (each tile once) = x2.0 + 256 px whole tiles requested: 35; 64 px tiles: 314; 32 px tiles: 1114 + mask-cache @4096^2 for this player (final masks, 35 tiles): 2406047 B measured (final masked PNG of each touched tile; whole-tile originals 4654862 B) diff --git a/prototype-tile-leak/results/netbench.log b/prototype-tile-leak/results/netbench.log new file mode 100644 index 0000000..4144359 --- /dev/null +++ b/prototype-tile-leak/results/netbench.log @@ -0,0 +1,34 @@ +# leak-bound demo: request EVERY tile of each size; allowed iff it overlaps an explored cell (left half + lone cell (64,3)) +tiles32: 16384 requested, 8193 allowed (expected 8193: half + 1 lone-cell tile); unexplored pixels revealed by the lone-cell tile: 0; PASS +tiles64: 4096 requested, 2049 allowed (expected 2049: half + 1 lone-cell tile); unexplored pixels revealed by the lone-cell tile: 3072; PASS +tiles256: 256 requested, 129 allowed (expected 129: half + 1 lone-cell tile); unexplored pixels revealed by the lone-cell tile: 64512; PASS +# h2load vs nginx(4 workers) -> Nim auth (mummy, 8 threads) -> X-Accel-Redirect; loopback; N=20000 reqs, tiles from explored half +# upstream keepalive ON +AUTH tiles32 h1 c=1 (unloaded latency) 10370.67 req/s t med 90us p95 119us p99 149us 5000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h1 c=1 (unloaded latency) 7235.61 req/s t med 132us p95 171us p99 211us 5000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles32 h1 c=6 (browser-like) 46247.16 req/s t med 122us p95 156us p99 188us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles32 h1 c=32 54315.65 req/s t med 480us p95 663us p99 724us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles32 h2 c=1 m=100 18578.52 req/s t med 5.12ms p95 7.11ms p99 8.94ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles32 h2 c=4 m=100 19854.31 req/s t med 5.62ms p95 10.12ms p99 25.20ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles64 h1 c=6 (browser-like) 45255.11 req/s t med 127us p95 170us p99 213us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles64 h1 c=32 56196.51 req/s t med 481us p95 655us p99 731us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles64 h2 c=1 m=100 19893.83 req/s t med 4.91ms p95 5.82ms p99 6.84ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles64 h2 c=4 m=100 18958.57 req/s t med 5.14ms p95 7.40ms p99 9.17ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h1 c=6 (browser-like) 18983.22 req/s t med 296us p95 444us p99 636us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h1 c=32 28289.74 req/s t med 840us p95 1.42ms p99 1.95ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h2 c=1 m=100 9719.18 req/s t med 10.04ms p95 13.45ms p99 15.02ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h2 c=4 m=100 18921.57 req/s t med 9.63ms p95 13.23ms p99 16.23ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +STATIC tiles32 h1 c=32 (no Nim, no auth) 86885.12 req/s t med 332us p95 452us p99 534us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +STATIC tiles32 h2 c=4 m=100 102607.78 req/s t med 3.62ms p95 4.94ms p99 6.40ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +STATIC tiles256 h1 c=32 (no Nim, no auth) 46742.40 req/s t med 545us p95 766us p99 902us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +STATIC tiles256 h2 c=4 m=100 23713.32 req/s t med 9.22ms p95 25.47ms p99 27.33ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx +# burst: first-connect reveal = 292 distinct cells (leak-A hello). 32px tiles = 292 reqs +BURST 292x tiles32 h1 c=6 39668.52 req/s t med 129us p95 179us p99 351us 292 2xx, 0 3xx, 0 4xx, 0 5xx +BURST 292x tiles32 h2 c=1 m=100 13251.65 req/s t med 5.91ms p95 9.26ms p99 9.73ms 292 2xx, 0 3xx, 0 4xx, 0 5xx +BURST 292x tiles32 h1 c=6 22373.76 req/s t med 243us p95 320us p99 518us 292 2xx, 0 3xx, 0 4xx, 0 5xx +BURST 292x tiles32 h2 c=1 m=100 13571.30 req/s t med 6.19ms p95 8.79ms p99 9.31ms 292 2xx, 0 3xx, 0 4xx, 0 5xx +BURST 292x tiles32 h1 c=6 18192.01 req/s t med 275us p95 451us p99 1.32ms 292 2xx, 0 3xx, 0 4xx, 0 5xx +BURST 292x tiles32 h2 c=1 m=100 14766.87 req/s t med 5.43ms p95 9.25ms p99 9.65ms 292 2xx, 0 3xx, 0 4xx, 0 5xx +# upstream keepalive OFF (nginx default: new TCP connection to Nim per request, what prototype-server-vision nginx.conf does) +AUTH tiles32 h1 c=32 (no upstream keepalive) 54961.36 req/s t med 463us p95 677us p99 795us 20000 2xx, 0 3xx, 0 4xx, 0 5xx +AUTH tiles256 h1 c=32 (no upstream keepalive) 38696.32 req/s t med 721us p95 998us p99 1.29ms 20000 2xx, 0 3xx, 0 4xx, 0 5xx diff --git a/prototype-tile-leak/results/steps.log b/prototype-tile-leak/results/steps.log new file mode 100644 index 0000000..ce5ad71 --- /dev/null +++ b/prototype-tile-leak/results/steps.log @@ -0,0 +1,2 @@ +A: explored msgs 94; first (connect) burst new tiles 32/64/256 = (292, 87, 13); steady steps 93: new tiles median 32px 11 p95 37 max 164 | 64px med 3 p95 11 max 46 | 256px med 0 p95 3 max 6; totals 2142/603/71 +B: explored msgs 39; first (connect) burst new tiles 32/64/256 = (307, 90, 13); steady steps 38: new tiles median 32px 19 p95 80 max 121 | 64px med 5 p95 22 max 35 | 256px med 0 p95 3 max 4; totals 1114/314/35 diff --git a/prototype-tile-leak/src/art.nim b/prototype-tile-leak/src/art.nim new file mode 100644 index 0000000..8f7e7d9 --- /dev/null +++ b/prototype-tile-leak/src/art.nim @@ -0,0 +1,35 @@ +## Procedural "battlemap" art: pure function of world coords, so any tile size slices the same picture. +import pixie, std/math + +const CellPx* = 32 + +proc hash(x, y, seed: int): uint32 = + var h = uint32(x * 374761393 + y * 668265263 + seed * 2246822519'i64.int) + h = (h xor (h shr 13)) * 1274126177'u32 + h xor (h shr 16) + +proc vnoise(x, y: float, scale: int, seed: int): float = + let (fx, fy) = (x / scale.float, y / scale.float) + let (ix, iy) = (floor(fx).int, floor(fy).int) + let (tx, ty) = (fx - ix.float, fy - iy.float) + let (sx, sy) = (tx * tx * (3 - 2 * tx), ty * ty * (3 - 2 * ty)) + template v(a, b: int): float = hash(ix + a, iy + b, seed).float / 4294967295.0 + let top = v(0, 0) * (1 - sx) + v(1, 0) * sx + let bot = v(0, 1) * (1 - sx) + v(1, 1) * sx + top * (1 - sy) + bot * sy + +proc artColor*(x, y: int, grain: float): ColorRGBX = + let (fx, fy) = (x.float, y.float) + let n = 0.5 * vnoise(fx, fy, 128, 1) + 0.25 * vnoise(fx, fy, 48, 2) + + 0.15 * vnoise(fx, fy, 16, 3) + 0.10 * vnoise(fx, fy, 6, 4) + let g = (hash(x, y, 9).float / 4294967295.0 - 0.5) * grain + var (r, gg, b) = (60 + n * 150, 80 + n * 120, 50 + n * 70) + if x mod 70 == 0 or y mod 70 == 0: (r, gg, b) = (r * 0.6, gg * 0.6, b * 0.6) # grid line + proc c(v: float): uint8 = uint8(clamp(v + g, 1, 254)) # never pure 0/255: red/black are sentinels + rgbx(c(r), c(gg), c(b), 255) + +proc renderTile*(x0, y0, size: int, grain: float): Image = + result = newImage(size, size) + for y in 0 ..< size: + for x in 0 ..< size: + result.data[y * size + x] = artColor(x0 + x, y0 + y, grain) diff --git a/prototype-tile-leak/src/authsrv.nim b/prototype-tile-leak/src/authsrv.nim new file mode 100644 index 0000000..fb102b8 --- /dev/null +++ b/prototype-tile-leak/src/authsrv.nim @@ -0,0 +1,50 @@ +## Q4 part 2: Nim auth gate + X-Accel-Redirect for tiles of size 32/64/256 (same shape as prototype-server-vision/src/server.nim). +## Explored = every cell with cx < 64 (left half of the 4096 map) + lone cell (64,3). usage: authsrv +import std/[strutils, tables, locks, os, strformat] +import mummy + +const (World, Cell) = (4096, 32) +const Cw = World div Cell +var + lk: Lock + sessions = {"benchsecret": 0}.toTable # sid -> player (one player) + explored: seq[bool] +initLock lk +explored = newSeq[bool](Cw * Cw) +for cy in 0 ..< Cw: + for cx in 0 ..< Cw div 2: explored[cy * Cw + cx] = true +explored[3 * Cw + 64] = true # one lone explored cell just outside the half: leak-bound demo (netbench) + +proc cookieSid(request: Request): string = + for (k, v) in request.headers: + if k.toLowerAscii == "cookie": + for part in v.split(';'): + let p = part.strip + if p.startsWith("sid="): return p[4 .. ^1] + +proc handler(request: Request) {.gcsafe.} = + {.gcsafe.}: + let path = request.path # /tiles/tiles/_.png + if not (path.startsWith("/tiles/tiles") and path.endsWith(".png")): request.respond(404); return + let parts = path[7 .. ^5].split('/') + if parts.len != 2 or parts[0].len < 6 or parts[0].len > 8 or not parts[0][5 .. ^1].allCharsInSet(Digits): request.respond(404); return + let size = parseInt(parts[0][5 .. ^1]) + let xy = parts[1].split('_') + if size notin [32, 64, 256] or xy.len != 2 or xy[0].len notin 1..3 or xy[1].len notin 1..3 or + not xy[0].allCharsInSet(Digits) or not xy[1].allCharsInSet(Digits): request.respond(404); return + let (tx, ty) = (parseInt(xy[0]), parseInt(xy[1])) + if tx >= World div size or ty >= World div size: request.respond(404); return + var ok = false + withLock lk: + if cookieSid(request) in sessions: + let per = size div Cell + for cy in ty * per ..< (ty + 1) * per: + for cx in tx * per ..< (tx + 1) * per: + if explored[cy * Cw + cx]: ok = true + if ok: + var h: HttpHeaders + h["X-Accel-Redirect"] = &"/_tiles/{parts[0]}/{parts[1]}.png" + request.respond(200, h) + else: request.respond(403) + +newServer(handler, workerThreads = 8).serve(Port(parseInt(paramStr(1))), "127.0.0.1") diff --git a/prototype-tile-leak/src/gen.nim b/prototype-tile-leak/src/gen.nim new file mode 100644 index 0000000..546406e --- /dev/null +++ b/prototype-tile-leak/src/gen.nim @@ -0,0 +1,10 @@ +## slice the procedural 4096^2 map into square tiles of each size. usage: gen +import pixie, pixie/fileformats/png, std/[os, strformat, strutils] +import art +let (outDir, grain, world) = (paramStr(1), paramStr(2).parseFloat, 4096) +for size in [256, 64, 32]: + let d = outDir / ("tiles" & $size) + createDir d + for ty in 0 ..< world div size: + for tx in 0 ..< world div size: + writeFile(d / &"{tx}_{ty}.png", encodePng(renderTile(tx * size, ty * size, size, grain))) diff --git a/prototype-tile-leak/src/maskbench.nim b/prototype-tile-leak/src/maskbench.nim new file mode 100644 index 0000000..3460a25 --- /dev/null +++ b/prototype-tile-leak/src/maskbench.nim @@ -0,0 +1,169 @@ +## Q4 part 1: server-side masked tiles. Timing, size, leak asserts, replay of prototype-server-vision explored transcripts. +## PROTOTYPE, throwaway. usage: maskbench [replay-jsonl ...] +import pixie, pixie/fileformats/png as pxpng +import nimPNG +import std/[monotimes, times, strformat, json, sets, tables, algorithm, streams, os, math] +import art + +const + T = 256 + Per = T div CellPx # 8 cells per tile side +type Mask = array[Per * Per, bool] # cell (cx,cy) inside tile -> explored + +proc maskRgba(p: ptr UncheckedArray[uint8], ex: Mask) = + ## unexplored cell -> opaque black. p = straight RGBA 256x256 + for cy in 0 ..< Per: + for cx in 0 ..< Per: + if not ex[cy * Per + cx]: + for y in cy * CellPx ..< (cy + 1) * CellPx: + for x in cx * CellPx ..< (cx + 1) * CellPx: + let o = (y * T + x) * 4 + p[o] = 0; p[o + 1] = 0; p[o + 2] = 0; p[o + 3] = 255 + +proc maskPixie(src: string, ex: Mask): string = + let png = decodePng(src) + maskRgba(cast[ptr UncheckedArray[uint8]](png.data[0].addr), ex) + encodePng(png) + +proc maskNimPng(src: string, ex: Mask): string = + var r = decodePNG32(src) + maskRgba(cast[ptr UncheckedArray[uint8]](r.data[0].addr), ex) + let enc = encodePNG32(r.data, T, T) + let ss = newStringStream() + enc.writeChunks(ss) + ss.data + +proc ms(a, b: MonoTime): float = (b - a).inNanoseconds.float / 1e6 + +proc maskOf(n: int): Mask = # first n cells row-major + for i in 0 ..< n: result[i] = true + +# ---- leak assert: unexplored cells are exactly black, explored cells pixel-identical, planted red markers gone +proc redMarkers(img: Image): int = + for c in img.data: + if c.r == 255 and c.g == 0 and c.b == 0: inc result + +proc leakAssert(label: string, orig: Image, masked: string, ex: Mask) = + let got = decodeImage(masked) + doAssert got.width == T and got.height == T + doAssert redMarkers(got) == 0, label & ": red secret survived" + for y in 0 ..< T: + for x in 0 ..< T: + let c = got.data[y * T + x] + if ex[(y div CellPx) * Per + x div CellPx]: + doAssert c == orig.data[y * T + x], label & ": explored pixel altered" + else: + doAssert c.r == 0 and c.g == 0 and c.b == 0 and c.a == 255, label & ": unexplored pixel not black" + +proc plant(img: Image, ex: Mask) = # secret: 8x8 pure-red block in the middle of each UNexplored cell + for cy in 0 ..< Per: + for cx in 0 ..< Per: + if not ex[cy * Per + cx]: + for y in 0 ..< 8: + for x in 0 ..< 8: + img.data[(cy * CellPx + 12 + y) * T + cx * CellPx + 12 + x] = rgbx(255, 0, 0, 255) + +proc timed(n: int, body: proc()): float = + body() # warmup + var xs: seq[float] + for _ in 0 ..< n: + let t0 = getMonoTime(); body(); xs.add ms(t0, getMonoTime()) + xs.sort; xs[xs.len div 2] # median + +# ---- exact-polygon variant (naive per-pixel even-odd, 32-gon vision disc) upper bound +proc maskPolyNaive(src: string, cx, cy, r: float): string = + var poly: array[32, (float, float)] + for i in 0 ..< 32: poly[i] = (cx + r * cos(i.float / 32 * 2 * PI), cy + r * sin(i.float / 32 * 2 * PI)) + let png = decodePng(src) + for y in 0 ..< T: + for x in 0 ..< T: + var inside = false + var j = 31 + for i in 0 ..< 32: + let (xi, yi) = poly[i]; let (xj, yj) = poly[j] + if (yi > y.float + 0.5) != (yj > y.float + 0.5) and + x.float + 0.5 < (xj - xi) * (y.float + 0.5 - yi) / (yj - yi) + xi: inside = not inside + j = i + if not inside: png.data[y * T + x] = rgba(0, 0, 0, 255) + encodePng(png) + +proc part1() = + echo "## part 1: per-tile mask timing (median of 200, single thread, -d:release)" + for (name, grain) in [("smooth(grain 6)", 6.0), ("noisy(grain 40)", 40.0)]: + let img = renderTile(1024, 2048, T, grain) + let src = encodePng(img) + echo &"\n[{name}] source tile PNG {src.len} B" + # decode / encode split + let dec = timed(200, proc() = discard decodePng(src)) + let png0 = decodePng(src) + let enc = timed(200, proc() = discard encodePng(png0)) + echo &"pixie decode {dec:.2f} ms, encode(full tile) {enc:.2f} ms" + echo "explored cells/64 | pixie dec+mask+enc ms | out B | nimPNG dec+mask+enc ms | out B | leak assert" + for n in [0, 1, 8, 32, 63]: + let ex = maskOf(n) + let tp = timed(200, proc() = discard maskPixie(src, ex)) + let outP = maskPixie(src, ex) + let tn = timed(50, proc() = discard maskNimPng(src, ex)) + let outN = maskNimPng(src, ex) + # leak assert on a copy with red secrets planted in unexplored cells, through both libs + let planted = renderTile(1024, 2048, T, grain); plant(planted, ex) + let psrc = encodePng(planted) + leakAssert("pixie n=" & $n, planted, maskPixie(psrc, ex), ex) + leakAssert("nimpng n=" & $n, planted, maskNimPng(psrc, ex), ex) + echo &"{n:>3} | {tp:7.2f} | {outP.len:>6} | {tn:7.2f} | {outN.len:>6} | OK" + let poly = timed(30, proc() = discard maskPolyNaive(src, 128, 128, 90)) + echo &"exact-polygon variant (naive per-pixel 32-gon, r=90): {poly:.2f} ms (upper bound; scanline fill ~ cell-mask cost)" + echo "full-explored tile: no image work, serve original file (X-Accel-Redirect), 0 ms" + +proc cellsOf(m: JsonNode): seq[(int, int)] = + for c in m["cells"]: result.add (c[0].getInt, c[1].getInt) + +proc replay(path: string, who: string, grain: float) = + ## real masking replay: every explored msg for `who`; every tile whose mask changed is re-masked, encoded, "downloaded" + var ex = initTable[(int, int), Mask]() # tile -> mask + var src = initTable[(int, int), string]() + var steps, remasks, maskedBytes, unmaskedBytes, seen32, seen64: int + var totalMs = 0.0 + var worstStepMs = 0.0 + var stepRemasks: seq[int] + var seenT = initHashSet[(int, int)]() + var seen64s = initHashSet[(int, int)]() + var cellsTotal = 0 + for line in lines(path): + let j = parseJson(line) + if j["k"].getStr != "msg" or j["who"].getStr != who or j["m"]{"t"}.getStr != "explored": continue + inc steps + var changed = initHashSet[(int, int)]() + for (cx, cy) in cellsOf(j["m"]): + inc cellsTotal + let t = (cx div Per, cy div Per) + if t notin ex: ex[t] = default(Mask) + ex[t][(cy mod Per) * Per + cx mod Per] = true + changed.incl t + if (cx, cy) notin seenT: seenT.incl (cx, cy); inc seen32 + if (cx div 2, cy div 2) notin seen64s: seen64s.incl (cx div 2, cy div 2); inc seen64 + var stepMs = 0.0 + for t in changed: + if t notin src: src[t] = encodePng(renderTile(t[0] * T, t[1] * T, T, grain)) + let t0 = getMonoTime() + let o = maskPixie(src[t], ex[t]) + stepMs += ms(t0, getMonoTime()) + inc remasks; maskedBytes += o.len + totalMs += stepMs; worstStepMs = max(worstStepMs, stepMs); stepRemasks.add changed.len + var finalBytes = 0 + for t, s in src: + unmaskedBytes += s.len # each touched tile downloaded once + finalBytes += maskPixie(s, ex[t]).len + let tilesTouched = src.len + stepRemasks.sort + echo &"\n[replay {path.extractFilename} subject {who}, grain {grain}] msgs(steps) {steps}, explored cells {cellsTotal}, tiles touched {tilesTouched}" + echo &" masked: {remasks} tile re-masks total ({remasks.float / steps.float:.1f}/step, max {stepRemasks[^1]}/step), CPU {totalMs:.0f} ms total, {totalMs / steps.float:.2f} ms/step avg, worst step {worstStepMs:.1f} ms" + echo &" bytes to client: masked {maskedBytes} B (every changed tile refetched) vs whole-tile {unmaskedBytes} B (each tile once) = x{maskedBytes.float / unmaskedBytes.float:.1f}" + echo &" 256 px whole tiles requested: {tilesTouched}; 64 px tiles: {seen64}; 32 px tiles: {seen32}" + echo &" mask-cache @4096^2 for this player (final masks, {tilesTouched} tiles): {finalBytes} B measured (final masked PNG of each touched tile; whole-tile originals {unmaskedBytes} B)" + +when isMainModule: + part1() + for p in commandLineParams(): + for who in ["A", "B"]: + for grain in [6.0, 40.0]: replay(p, who, grain) diff --git a/prototype-tile-leak/tilelk.nimble b/prototype-tile-leak/tilelk.nimble new file mode 100644 index 0000000..5034c2d --- /dev/null +++ b/prototype-tile-leak/tilelk.nimble @@ -0,0 +1,8 @@ +version = "0.1.0" +author = "proto" +description = "Throwaway: Q4 tile leak" +license = "MIT" +requires "nim >= 2.0" +requires "pixie" +requires "nimPNG" +requires "mummy#01deb1ff694988635c7bf0f24f6088a0bdf6db5d" diff --git a/prototype-tile-leak/tools/mime.types b/prototype-tile-leak/tools/mime.types new file mode 100644 index 0000000..1c00d70 --- /dev/null +++ b/prototype-tile-leak/tools/mime.types @@ -0,0 +1,99 @@ + +types { + text/html html htm shtml; + text/css css; + text/xml xml; + image/gif gif; + image/jpeg jpeg jpg; + application/javascript js; + application/atom+xml atom; + application/rss+xml rss; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/avif avif; + image/png png; + image/svg+xml svg svgz; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/webp webp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + + font/woff woff; + font/woff2 woff2; + + application/java-archive jar war ear; + application/json json; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.apple.mpegurl m3u8; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/vnd.ms-excel xls; + application/vnd.ms-fontobject eot; + application/vnd.ms-powerpoint ppt; + application/vnd.oasis.opendocument.graphics odg; + application/vnd.oasis.opendocument.presentation odp; + application/vnd.oasis.opendocument.spreadsheet ods; + application/vnd.oasis.opendocument.text odt; + application/vnd.openxmlformats-officedocument.presentationml.presentation + pptx; + application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + xlsx; + application/vnd.openxmlformats-officedocument.wordprocessingml.document + docx; + application/vnd.wap.wmlc wmlc; + application/wasm wasm; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/xspf+xml xspf; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream iso img; + application/octet-stream msi msp msm; + + audio/midi mid midi kar; + audio/mpeg mp3; + audio/ogg ogg; + audio/x-m4a m4a; + audio/x-realaudio ra; + + video/3gpp 3gpp 3gp; + video/mp2t ts; + video/mp4 mp4; + video/mpeg mpeg mpg; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-m4v m4v; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/prototype-tile-leak/tools/netbench.sh b/prototype-tile-leak/tools/netbench.sh new file mode 100755 index 0000000..4f7f508 --- /dev/null +++ b/prototype-tile-leak/tools/netbench.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# Q4 part 2: tiny-tile serving through nginx (+Nim auth + X-Accel-Redirect). run via `devbox run netbench` after `devbox run gen`. +set -u +cd "$(dirname "$0")/.." +NP=${NGX_PORT:-18188}; BP=19100; N=${N:-20000} +mkdir -p run/temp results; cp -f tools/mime.types run/ && chmod u+w run/mime.types +nginxstart() { sed "s/NIMPORT/$BP/;s/NGXPORT/$NP/;s/UPKEEP/$1/" tools/nginx.conf > run/nginx.conf + nginx -p "$PWD/" -c run/nginx.conf -e run/error.log & NGX=$!; sleep 1; } +nginxstop() { kill $NGX 2>/dev/null; wait $NGX 2>/dev/null; } +bin/authsrv $BP & SRV=$! +trap 'kill $SRV $NGX 2>/dev/null' EXIT +sleep 1 +# uri lists: random tiles inside the explored left half (x < half), fixed seed +uris() { # size count prefix + awk -v s=$1 -v n=$2 -v p=http://127.0.0.1:$NP$3 'BEGIN{srand(1); w=4096/s; for(i=0;i run/u$s.txt; uris $s $N /static > run/s$s.txt; done +awk -v np=$NP 'BEGIN{srand(2); n=0; while(n<292){x=int(rand()*64); y=int(rand()*128); k=x","y; if(!(k in a)){a[k]=1; n++; printf "http://127.0.0.1:%d/tiles/tiles32/%d_%d.png\n", np, x, y}}}' > run/burst32.txt +H=(-H "Cookie: sid=benchsecret") +echo "# leak-bound demo: request EVERY tile of each size; allowed iff it overlaps an explored cell (left half + lone cell (64,3))" +nginxstart 64 +for s in 32 64 256; do + awk -v s=$s -v p=http://127.0.0.1:$NP 'BEGIN{w=4096/s; for(y=0;y run/all$s.txt + n=$(wc -l < run/all$s.txt); w=$((4096/s)) + out=$(h2load --h1 -n $n -c 1 -t 1 -i run/all$s.txt "${H[@]}" 2>&1 | grep 'status codes') + ok=$(sed 's/.*codes: \([0-9]*\) 2xx.*/\1/' <<<"$out"); exp=$(( w*w/2 + 1 )) + per=$((s*s)); lone_px=$(( per - 1024 )) + [ "$s" = 32 ] && lone_px=0 + echo "tiles$s: $n requested, $ok allowed (expected $exp: half + 1 lone-cell tile); unexplored pixels revealed by the lone-cell tile: $lone_px; $( [ "$ok" = "$exp" ] && echo PASS || echo FAIL )" + [ "$ok" = "$exp" ] || { echo LEAKCHECK FAILED; exit 1; } +done +nginxstop +run() { # label h2load args... + local label=$1; shift + local out; out=$(h2load "$@" "${H[@]}" 2>&1) + local rps=$(grep -o 'finished in .*' <<<"$out" | sed 's/.*, \([0-9.]*\) req\/s.*/\1 req\/s/') + local lat=$(grep '^request *:' <<<"$out" | awk '{print "t med " $5 " p95 " $6 " p99 " $7}') + local st=$(grep 'status codes' <<<"$out" | sed 's/status codes: //') + local tm=$(grep -o 'finished in [0-9.a-z]*' <<<"$out") + printf '%-46s %-12s %-34s %s\n' "$label" "$rps" "$lat" "$st" +} +echo "# h2load vs nginx(4 workers) -> Nim auth (mummy, 8 threads) -> X-Accel-Redirect; loopback; N=$N reqs, tiles from explored half" +echo "# upstream keepalive ON" +nginxstart 64 +for s in 32 256; do + run "AUTH tiles$s h1 c=1 (unloaded latency)" --h1 -n 5000 -c 1 -t 1 -i run/u$s.txt +done +for s in 32 64 256; do + run "AUTH tiles$s h1 c=6 (browser-like)" --h1 -n $N -c 6 -t 2 -i run/u$s.txt + run "AUTH tiles$s h1 c=32" --h1 -n $N -c 32 -t 4 -i run/u$s.txt + run "AUTH tiles$s h2 c=1 m=100" -n $N -c 1 -m 100 -t 1 -i run/u$s.txt + run "AUTH tiles$s h2 c=4 m=100" -n $N -c 4 -m 100 -t 4 -i run/u$s.txt +done +for s in 32 256; do + run "STATIC tiles$s h1 c=32 (no Nim, no auth)" --h1 -n $N -c 32 -t 4 -i run/s$s.txt + run "STATIC tiles$s h2 c=4 m=100" -n $N -c 4 -m 100 -t 4 -i run/s$s.txt +done +echo "# burst: first-connect reveal = 292 distinct cells (leak-A hello). 32px tiles = 292 reqs" +for i in 1 2 3; do + run "BURST 292x tiles32 h1 c=6" --h1 -n 292 -c 6 -t 1 -i run/burst32.txt + run "BURST 292x tiles32 h2 c=1 m=100" -n 292 -c 1 -m 100 -t 1 -i run/burst32.txt +done +nginxstop +echo "# upstream keepalive OFF (nginx default: new TCP connection to Nim per request, what prototype-server-vision nginx.conf does)" +sed 's/ keepalive UPKEEP;//; s/proxy_http_version 1.1; proxy_set_header Connection "";//' tools/nginx.conf > run/nokeep.conf +sed -i "s/NIMPORT/$BP/;s/NGXPORT/$NP/" run/nokeep.conf +nginx -p "$PWD/" -c run/nokeep.conf -e run/error.log & NGX=$!; sleep 1 +run "AUTH tiles32 h1 c=32 (no upstream keepalive)" --h1 -n $N -c 32 -t 4 -i run/u32.txt +run "AUTH tiles256 h1 c=32 (no upstream keepalive)" --h1 -n $N -c 32 -t 4 -i run/u256.txt +nginxstop diff --git a/prototype-tile-leak/tools/nginx.conf b/prototype-tile-leak/tools/nginx.conf new file mode 100644 index 0000000..31c9ff5 --- /dev/null +++ b/prototype-tile-leak/tools/nginx.conf @@ -0,0 +1,21 @@ +daemon off; +worker_processes 4; +pid run/nginx.pid; +error_log run/error.log warn; +events { worker_connections 4096; } +http { + access_log off; # benchmark only; the real config logs (adds a little cost) + client_body_temp_path run/temp/cb; proxy_temp_path run/temp/p; fastcgi_temp_path run/temp/f; + uwsgi_temp_path run/temp/u; scgi_temp_path run/temp/s; + include mime.types; + upstream nim { server 127.0.0.1:NIMPORT; keepalive UPKEEP; } + server { + listen NGXPORT; + http2 on; # h2c (cleartext, prior knowledge); h1 clients still work on the same port + http2_max_concurrent_streams 256; + keepalive_requests 1000000; # default 1000 makes h2load (no reconnect on GOAWAY) fail h2 runs; a browser just reconnects + location /tiles/ { proxy_pass http://nim; proxy_http_version 1.1; proxy_set_header Connection ""; } + location /_tiles/ { internal; alias data/g6/; } + location /static/ { alias data/g6/; } # baseline: nginx file serving, no auth + } +} diff --git a/prototype-tile-leak/tools/steps.py b/prototype-tile-leak/tools/steps.py new file mode 100644 index 0000000..8490480 --- /dev/null +++ b/prototype-tile-leak/tools/steps.py @@ -0,0 +1,16 @@ +# new 32/64/256 px tiles per explored msg from the vision prototype transcript; python3 tools/steps.py > results/steps.log +import json +for who in 'AB': + seen32=set();seen64=set();seen256=set();rows=[] + for l in open('../prototype-server-vision/results/leak-A.jsonl'): + j=json.loads(l) + if j.get('k')=='msg' and j['who']==who and j['m'].get('t')=='explored': + n32=n64=n256=0 + for cx,cy in j['m']['cells']: + if (cx,cy) not in seen32: seen32.add((cx,cy)); n32+=1 + if (cx//2,cy//2) not in seen64: seen64.add((cx//2,cy//2)); n64+=1 + if (cx//8,cy//8) not in seen256: seen256.add((cx//8,cy//8)); n256+=1 + rows.append((n32,n64,n256)) + steady=rows[1:] + q=lambda i,p: sorted(r[i] for r in steady)[int(len(steady)*p)] + print(f"{who}: explored msgs {len(rows)}; first (connect) burst new tiles 32/64/256 = {rows[0]}; steady steps {len(steady)}: new tiles median 32px {q(0,.5)} p95 {q(0,.95)} max {max(r[0] for r in steady)} | 64px med {q(1,.5)} p95 {q(1,.95)} max {max(r[1] for r in steady)} | 256px med {q(2,.5)} p95 {q(2,.95)} max {max(r[2] for r in steady)}; totals {sum(r[0] for r in rows)}/{sum(r[1] for r in rows)}/{sum(r[2] for r in rows)}")