Files
Mateusz Najdek 5efa45a655 Release v1.2.0 (#5)
* ws: direct-install streaming over WebSocket (RAM-only, no disk spool)

Browser pushes .pkg bytes over ws://:8846 while the PS5 installer pulls
ranges over :8845 concurrently through a demand-paged 1MB-segment ring
(64 slots, seg 0 pinned). Install can start at header_ready, mid-upload.

Backend (src/ws_stream.c, src/ws_upload.c):
- ws_live_* ring with waiter shielding, served-past / waited+acked /
  peak>0+acked LRU eviction, single store_seg_locked() truth shared by
  blocking write and non-blocking try_write (0/-1/-2 busy).
- Conn worker never blocks on storage (busy reply, browser retries);
  socket idle kill suppressed while readers are parked; stall
  diagnostics when a write parks.
- http_server.c: guarded /api/upload/* REST branch; multipart.c live:
  scheme adapter (frozen pull path untouched); installer_start_live.

Frontend: DirectInstallView + useDirectUpload pusher (FIFO seek queue
for parallel installer workers, busy requeue+retry, demand-paging
standby until install finalizes, silent-socket watchdog), wired into
the history router (#/direct-install, Circle-back closes it).

Parser: pkg_parser_parse_mem reuses in-file sub-parsers for live
header parsing (differential-tested).

Tests: ring unit (test_ws_stream), far-seek/pivot/busy/waiter unit
(test_ws_stream_far), transport (test_ws_upload, incl. socket
busy->retry), concurrent e2e incl. 90MB/64-slot parallel-pivot replay
of the production capture (test_direct_install_e2e), PS5 pull-replay
simulator (ps5_sim) + CLI tools.

Proven on console: 1GB PKG installs at status='playable' with zero
idle kills. Full host suite (13 binaries + CSS) green.

* perf(smb): pipeline reads for faster package streaming

Use a private SMB session per stream connection and keep up to eight credit-aware reads in flight, with requests up to 512 KiB. Reduce each request to the credits available in the current SMB2 window, including queued requests, so libsmb2 cannot silently shorten a request and leave a gap in the stream. Increase stream and socket buffers, and leave signing optional while still honoring servers that require it.

Add SMB timing and throughput logs plus negotiated session diagnostics to separate SMB read latency from HTTP streaming overhead. Include the SMB logger in PS5 and host builds and update the mock async API used by tests.

* fix(ws): harden direct install sessions and package preview

Tie uploads to a browser owner and one authenticated WebSocket. Resume from acknowledged segments so cache eviction does not lose progress.

Move Direct Install into media sources, show local PKG title and icon before installation, and warn before leaving an active transfer. Pass package metadata to the live installer and cover ownership and metadata parsing with tests.

* fix(smb): honor package install debug setting

Gate SMB debug file creation and per-read diagnostics behind pkg_install_debug, matching WebSocket stream logging behavior. Keep regular SMB package streaming unchanged.

* fix(ui): return direct install to drives route

Make the Direct Install Back to drives action replace the current route and restore the media source view directly. This prevents browsers that opened the page from leaving the app for an unrelated previous history entry.

* fix(ui): restore deep-linked pages on reload

Apply the initial hash route to the visible view during startup, including storage media and package details. Load package data for the linked drive so a direct package URL opens its detail page after a reload.

* fix(ui): accept package drops across the app

Handle package drops at the application level, open Direct Install, and pass the file through the existing package preview flow. Keep active uploads and installations protected from replacement.

* fix(direct): check package eligibility before install

Share the scanner's installed state and version rules with Direct Install. Check selected package metadata before enabling Install and again before starting a new transfer, while preserving resumed sessions. Show storage and active install blockers on the direct install page.

* fix(direct): share live install icon across browsers

Upload the parsed package icon once to the active direct install session and serve it from RAM through the existing icon API. Other browsers can resolve the live session path shown in installer status. Clear icon data when the session is canceled or replaced.

* fix(direct): cancel install when uploader closes

Use sendBeacon during browser teardown to call the authenticated Direct Install cancel endpoint for the sending session. Keep observer browsers unaffected and avoid duplicate cancellation requests.

* fix(direct): cancel when uploader socket closes

Treat an unexpected close of the authenticated uploader WebSocket before the final finish message as an install cancellation. Preserve normal completed sessions and reduce repetitive seek, eviction, and read-short logging in the main log.

* bump version to 1.1.1

* fix(ui): stop duplicate direct upload polling

Keep the observer watchdog stable across renders, disable it for the owning upload tab, and prevent overlapping status requests in both polling paths.

* Add PS4 and PS5 package badges

* feat: support platform-aware install storage

* fix: preserve catalog during provisional scans

* bump version to 1.2.0

* docs: add changelog for 1.2.0

* chore: remove stale refactor references

* feat: move streaming services to dedicated ports

* docs: update 1.2.0 documentation
2026-09-22 02:48:57 +02:00

197 lines
7.6 KiB
C

/*
* PS5 Installer Stream Simulator — command-line client half.
*
* Points the same PS5 installer request-pattern replay (ps5_sim.c) at a live
* stream server. Used two ways:
*
* 1. Standalone against an already-running server on the host:
* tools/ps5_installer_sim --no-server --host 127.0.0.1 --port 18841
*
* 2. Self-contained: build a fixture PKG, start the real stream_server.c on
* the host, replay the PS5 pattern, and print a reference-format replay
* log + summary (the "mock the PS5 on the PC" setup, no PS5 required).
*
* This is the shape a future websocket / remote install method needs: swap the
* raw-socket client for a websocket client and the same request sequence runs.
*/
#include "ps5_sim.h"
#include "stream_server.h"
#include "test_fixture.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define DEFAULT_SESSION "package-test-1.pkg"
#define DEFAULT_CONTENT_ID "EP9000-PPSA90012_00-TESTSIM00000001"
#define FIX_DIR "/tmp/ps5_installer_sim"
#define FIX_PKG FIX_DIR "/pkg.pkg"
#define DEFAULT_SIZE (5ULL * 1024 * 1024) /* 5 MiB: header + bulk chunks */
typedef struct {
const char *pkg; /* fixture path; NULL => build default fixture */
const char *host;
int port;
const char *session;
const char *content_id;
int header_repeats;
int reqs_per_header;
int parallel;
uint64_t chunk_size;
uint64_t size;
int no_server; /* connect to an existing server, don't start one */
int demo; /* write a reference-format replay log */
const char *replay_path; /* replay log path (NULL => derive) */
} opts_t;
static void usage(const char *prog) {
fprintf(stderr,
"PS5 Installer Stream Simulator\n"
"usage: %s [options]\n"
" --pkg FILE PKG to serve (built as a fixture if omitted)\n"
" --host HOST Stream server host (default 127.0.0.1)\n"
" --port PORT Stream server port (default %d)\n"
" --session NAME Session name (default %s)\n"
" --content-id ID Content id for the .crc sidecar probe\n"
" --header-repeats N Header-phase connections (default 5)\n"
" --reqs-per-header Requests per header connection (default 2)\n"
" --parallel N Bulk parallel connections (default 2)\n"
" --chunk-size N Bulk chunk size in bytes (default 16 MiB)\n"
" --size N Fixture size in bytes (default 5 MiB)\n"
" --no-server Connect to an existing server instead of starting one\n"
" --demo Write a reference-format replay log\n"
" --replay PATH Replay log path (default ./replay.log)\n",
prog, STREAM_SERVER_PORT, DEFAULT_SESSION);
}
/* Build a small synthetic PS5 PKG fixture so there is something to stream. */
static void build_fixture(const char *path, uint64_t size) {
char dir[512];
snprintf(dir, sizeof(dir), "%.*s", (int)(sizeof(dir) - 1), path);
char *slash = strrchr(dir, '/');
if (slash) {
*slash = '\0';
} else {
snprintf(dir, sizeof(dir), "%s", FIX_DIR);
}
char cmd[700];
snprintf(cmd, sizeof(cmd), "rm -rf %s && mkdir -p %s", dir, dir);
if (system(cmd) != 0) {
fprintf(stderr, "WARNING: failed to prepare fixture dir %s\n", dir);
}
assert(fixture_write_ps5_pkg(path, "PPSA90012", "SimGame", "gd",
"01.000.000", 1) == 0);
assert(fixture_grow_file(path, size) == 0);
}
int main(int argc, char **argv) {
opts_t o;
memset(&o, 0, sizeof(o));
o.host = "127.0.0.1";
o.port = STREAM_SERVER_PORT;
o.session = DEFAULT_SESSION;
o.content_id = DEFAULT_CONTENT_ID;
o.header_repeats = 5;
o.reqs_per_header = 2;
o.parallel = 2;
o.chunk_size = PS5_SIM_DEFAULT_CHUNK;
o.size = DEFAULT_SIZE;
o.pkg = NULL;
o.demo = 0;
o.replay_path = "replay.log";
for (int i = 1; i < argc; i++) {
#define STRCMP_OPT(name) (strcmp(argv[i], name) == 0)
if (STRCMP_OPT("--help") || STRCMP_OPT("-h")) { usage(argv[0]); return 0; }
else if (STRCMP_OPT("--no-server")) { o.no_server = 1; }
else if (STRCMP_OPT("--demo")) { o.demo = 1; }
else if (STRCMP_OPT("--host") && i + 1 < argc) { o.host = argv[++i]; }
else if (STRCMP_OPT("--port") && i + 1 < argc) { o.port = atoi(argv[++i]); }
else if (STRCMP_OPT("--session") && i + 1 < argc) { o.session = argv[++i]; }
else if (STRCMP_OPT("--content-id") && i + 1 < argc) { o.content_id = argv[++i]; }
else if (STRCMP_OPT("--header-repeats") && i + 1 < argc) { o.header_repeats = atoi(argv[++i]); }
else if (STRCMP_OPT("--reqs-per-header") && i + 1 < argc) { o.reqs_per_header = atoi(argv[++i]); }
else if (STRCMP_OPT("--parallel") && i + 1 < argc) { o.parallel = atoi(argv[++i]); }
else if (STRCMP_OPT("--chunk-size") && i + 1 < argc) { o.chunk_size = strtoull(argv[++i], NULL, 10); }
else if (STRCMP_OPT("--size") && i + 1 < argc) { o.size = strtoull(argv[++i], NULL, 10); }
else if (STRCMP_OPT("--pkg") && i + 1 < argc) { o.pkg = argv[++i]; }
else if (STRCMP_OPT("--replay") && i + 1 < argc) { o.replay_path = argv[++i]; }
else { fprintf(stderr, "unknown option: %s\n", argv[i]); usage(argv[0]); return 2; }
#undef STRCMP_OPT
}
const char *path = o.pkg ? o.pkg : FIX_PKG;
if (!o.no_server) {
if (!o.pkg) build_fixture(path, o.size);
printf("=== PS5 Installer Stream Simulator ===\n");
printf("serving %s (%llu bytes) -> session '%s' on %s:%d\n",
path, (unsigned long long)o.size, o.session, o.host, o.port);
assert(stream_server_session_start_ex(path, o.session) == 0);
assert(stream_server_is_running() == 1);
} else {
printf("=== PS5 Installer Stream Simulator (no local server) ===\n");
printf("replaying against %s:%d session '%s'\n", o.host, o.port, o.session);
}
FILE *replay = NULL;
if (o.demo) {
replay = fopen(o.replay_path, "w");
if (!replay) { perror("fopen replay.log"); return 1; }
}
char pathbuf[512];
snprintf(pathbuf, sizeof(pathbuf), "/stream/install/%s", o.session);
ps5_sim_target_t base;
memset(&base, 0, sizeof(base));
base.host = o.host;
base.port = o.port;
base.path = pathbuf;
base.content_id = o.content_id;
base.check_crc = 1;
base.header_repeats = o.header_repeats;
base.reqs_per_header = o.reqs_per_header;
base.parallel = o.parallel;
base.chunk_size = o.chunk_size;
ps5_sim_stats_t st;
int rc = ps5_sim_replay(&base, &st, replay);
if (replay) fclose(replay);
if (o.demo) {
printf("\n----- replay log (%s) -----\n", o.replay_path);
FILE *fp = fopen(o.replay_path, "r");
if (fp) {
char line[1024];
while (fgets(line, sizeof(line), fp)) fputs(line, stdout);
fclose(fp);
} else {
perror("fopen replay.log (read)");
}
}
printf("\n----- summary -----\n");
printf("replay_rc=%d connections=%d requests=%u bytes_delivered=%llu\n",
rc, st.conns_opened, (unsigned)st.requests_made,
(unsigned long long)st.total_delivered);
printf("header_ok=%d bulk_ok=%d crc_404=%d failures=%d\n",
st.header_ok, st.bulk_ok, st.crc_404, st.failures);
if (!o.no_server) {
stream_server_session_stop();
assert(stream_server_is_running() == 0);
}
if (rc == 0 && st.failures == 0) {
printf("\n>>> SIM COMPLETE: PS5 request pattern served cleanly <<<\n");
return 0;
}
printf("\n>>> SIM FAILED <<<\n");
return 1;
}