8 MiB Window, Range & Relay Contracts
1. 8 MiB Windowed ISO Reading (BrowserFileLoader)
Loading a full 1.5 GB PSP ISO into Emscripten MEMFS exhausts 32-bit WASM linear memory. PPSSPW mounts a zero-byte read-only stub under /browser-games/<name> whose read() throws ErrnoError(29) (EIO), ensuring all disc reads pass through BrowserFileLoader::ReadAt.
deps/ppsspp-wasm/Core/FileLoaders/BrowserFileLoader.cppproxiesReadAtback towasm-page/public/browser-files.js(__proxy: 'sync',__async: 'auto').ReadAtimmediately returns0if called onemscripten_is_main_runtime_thread(). Thereforedeps/ppsspp-wasm/SDL/SDLMain.cpp(EmuThreadStart) dispatchesEmuThreadFunconto a dedicated pthread wheneverBrowserFileLoaderHasFiles()org_Config.bEnableWlanis active.browser-files.jsenforcesBLOCK_BYTES = 256 KiB,MAX_READ_BYTES = 1 MiB,CACHE_BYTES = 8 MiBLRU window, andREAD_CONCURRENCY = 4.
2. Manifest & HTTP Range Resume Contract
game-download.js, online-games.js, and Dedicated Worker download-worker.js enforce strict download integrity:
- Only
HTTP 206 Partial Contentresponses with empty/identityContent-Encodingand no cross-origin redirect are accepted. - Each chunk's SHA-256 is verified against the manifest (
schemaVersion: 1,64 KiB–16 MiBchunks) before writing via OPFScreateSyncAccessHandle()togame-downloads/<fingerprint>/game.binand flushing the payload before updating one byte inresume.bin. Existing version-one journals remain readable. - Concurrent downloads of the same fingerprint are serialized via Web Locks (
PpssppGameStorage.withShared+ exclusiveppsspp-download-<fingerprint>).
3. Ad Hoc WebSocket Relay Protocol (LOCAL_ONLY = true UI Gate)
While wasm-page/public/ppsspp-runtime.js:31 sets LOCAL_ONLY = true (hiding tabNetwork and tabDrive), the repository includes a full WebSocket relay implementation (server/relay.py, server/relay_auth.py, server/relay_admin.py, wasm-page/public/adhoc-transport.js):
- 3-byte binary framing headers:
PRO(registration/auth handshake),PU1(UDP packet relay),PT1(TCP stream relay). RELAY_AUTH_MODE=keysvalidatespsp_<16hex>.<43urlsafe>tokens by constant-time comparison (secrets.compare_digest) of SHA-256 digests in/data/relay-auth.sqlite3managed solely viarelay_admin.pyCLI (issue,list,revoke).RELAY_LATENCY_MSandRELAY_JITTER_MSallow reproducible fault-injection testing alongsideserver/tests/test_relay*.pyandwasm-page/tests/adhoc-transport.test.mjs.