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

86 lines
4.0 KiB
C

/*
* PS5 Installer Stream Simulator — shared definitions.
*
* Models the request pattern that the PlayStation 5 background package
* installer (libSceAppInstUtil / ShellCore downloader) sends to the PKG
* Manager virtual stream server (stream_server.c, TCP :18841).
*
* The pattern, reverse-engineered from the captured logs in
* .for_reference/stream_debug/, has three phases:
*
* 1. Header acquisition — a burst of short-lived connections, each
* re-reading the first 64 KiB (Range: bytes=0-65535) so the installer
* can parse / re-validate the package header.
* 2. Sidecar CRC probe — a single Range-less GET of
* "<content_id>.crc" that the installer expects to 404 when we have no
* companion file; a 206 of PKG bytes here would poison chunk checks.
* 3. Bulk transfer — two parallel long-lived connections serving
* contiguous 16 MiB byte-ranges across [65536, end) in an A/B ping-pong
* until the whole package has been delivered.
*
* Every request carries the query the console appends:
* ?product=0287&serverIpAddr=127.0.0.1&r=00000000
*
* This header is the pure-client half of the model; the end-to-end test
* (test_stream_sim.c) pairs it against the real stream_server.c. The CLI
* (tools/ps5_installer_sim.c) points the same client at any live server,
* which is exactly the shape a future websocket / remote install method
* needs.
*/
#ifndef PS5_SIM_H
#define PS5_SIM_H
#include <stdio.h>
#include <stdint.h>
/* Observed request query string (ShellCore appends these params). */
#define PS5_SIM_DEFAULT_QUERY "?product=0287&serverIpAddr=127.0.0.1&r=00000000"
/* First-chunk header read size the console re-fetches repeatedly. */
#define PS5_SIM_HEADER_END (64 * 1024)
/* Bulk chunk size observed in every capture (16 MiB). */
#define PS5_SIM_DEFAULT_CHUNK (16 * 1024 * 1024)
/* Tunables — all default to values seen in the reference captures. */
typedef struct {
const char *host; /* e.g. "127.0.0.1" or real PS5 IP later */
int port; /* e.g. 18841 */
const char *path; /* /stream/install/package-<ts>-<n>.pkg */
const char *content_id; /* for the .crc sidecar probe; NULL/"" = skip */
const char *query; /* query string; NULL => default */
int header_repeats; /* header-phase connections (observed 2..7) */
int reqs_per_header; /* requests per header connection (observed 1..2)*/
int parallel; /* bulk parallel connections (observed 1..2) */
uint64_t chunk_size; /* bulk chunk size */
uint64_t total_size; /* total pkg size; 0 => learn from server */
int check_crc; /* 1 => probe <content_id>.crc, expect 404 */
} ps5_sim_target_t;
/* Per-run accounting so callers (and the replay log) can see what happened. */
typedef struct {
int conns_opened;
int requests_made;
uint64_t bytes_received;
int header_ok; /* every header read returned 206 w/ full body */
int bulk_ok; /* bulk covered [65536, total) with no gaps */
int crc_404; /* sidecar CRC returned 404 (or check disabled) */
int total_bytes_expected; /* == total_size if all delivered */
int failures; /* response mismatches (non-206, short body, ...) */
uint64_t total_delivered; /* bytes received across the whole run */
} ps5_sim_stats_t;
/*
* Replay the PS5 pattern against the target stream server.
* Returns 0 when every phase behaved as the model expects (all 206s with
* full bodies, CRC sidecar 404, whole file delivered), non-zero otherwise.
* The replay log (tab-separated, identical shape to the captured
* .for_reference logs) is written to `log_fp` when non-NULL.
*/
int ps5_sim_replay(const ps5_sim_target_t *t, ps5_sim_stats_t *out, FILE *log_fp);
#endif /* PS5_SIM_H */