Files
proxy-suite-flake/windows/DESIGN.md
T
faumarayandClaude Opus 5.5 c837db1c18 windows: workspace, dev shell and the config model
Start of the native Windows port. windows/ holds a Rust workspace; this
first piece is ps-core's model of the services.proxy-suite option tree,
with upstream's names and defaults, Windows-only additions documented,
validation ported from the module's assertions, and the derived tags and
loopback ports the tunnels add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 22:28:10 +03:00

89 lines
6.1 KiB
Markdown

# Proxy Suite for Windows: design
The Linux tree (`modules/`, `pkgs/`, `scripts/`) stays as upstream has it, so `main` keeps
merging from FUFSoB/proxy-suite-flake. Everything Windows-specific lives under `windows/`.
## Why a rewrite and not a port
Upstream's logic sits in Nix: the module evaluates `services.proxy-suite` into bash + jq start
scripts, systemd units, nftables rules and polkit rules. None of that runs on Windows, and Nix
does not either. What carries over is the *behaviour* (option semantics, link parsing, config
shape, routing order, group/detour resolution, CLI verbs, GUI tabs), not the code. The Python
pieces (`scripts/proxy_url_parsers.py`, `proxy_parsing.py`, …) are the reference
implementation: the Rust port is tested against them differentially.
## Shape
One Rust workspace, four binaries, one library:
| Crate | Binary | Role |
|---|---|---|
| `ps-core` | — | Config model (the `services.proxy-suite` tree as serde types, same names), validation, link and subscription parsing, sing-box / XRay config rendering, zapret strategy rendering, AmneziaWG/WARP config handling, share links. Pure: no I/O beyond what callers hand it. |
| `ps-ipc` | — | The service API: request/response types and the framed-JSON transport (named pipe on Windows, Unix socket elsewhere, so the stack runs on Linux for development). |
| `ps-service` | `proxy-suite-service.exe` | Runs as a Windows service (LocalSystem). Owns the config and state, renders backend configs, supervises the backend processes (a Job Object kills them with it), runs the timers (subscriptions, rule sets, autoProxy), talks to sing-box's Clash API, applies the kill switch, serves the API. `--console` runs it in the foreground. |
| `ps-ctl` | `proxy-ctl.exe` | Upstream's CLI verbs over the API. |
| `ps-gui` | `proxy-suite.exe` | GPUI window and tray icon. Every setting is editable here; it never writes files itself, it sends edits to the service, which validates them. |
### Config and state
- `%ProgramData%\ProxySuite\config.json`: the whole option tree, **with upstream's exact
camelCase names** (`proxy.listener.port`, `zapret.zapret2.autoHostlist.failThreshold` …), so
`docs/options/*.md` stays the reference and differential tests compare like with like. Written only by the service,
after validation, atomically. The GUI and `proxy-ctl config get/set/edit` go through the API.
Upstream's split between *declared* (Nix) and *runtime* additions disappears: everything is
runtime-editable. Secrets (`urlFile`, `passwordFile` …) become plain fields kept in a
separate `secrets.json` readable only by SYSTEM and Administrators (and the API returns them
only to callers with the `secrets` scope).
- `%ProgramData%\ProxySuite\state\`: pins, disabled outbounds, route-mode override, subscription
caches, rule-set downloads, autoProxy results, AWG/WARP registrations, inbound users' traffic.
- `%ProgramData%\ProxySuite\bin\<component>\<version>\`: backend binaries, fetched by the
component manager from pinned release URLs with pinned SHA-256s (see below).
- `%ProgramData%\ProxySuite\logs\`: one rotating log per unit, also tailed over the API.
### Units
The service keeps upstream's unit names so `proxy-ctl status`/`logs` read the same:
| Unit | Windows process | Notes |
|---|---|---|
| `proxy-suite-socks` | `sing-box.exe` (or `xray.exe`) | mixed inbound on `listener`; Clash API on loopback |
| `proxy-suite-tun` | `sing-box.exe` | TUN through wintun, `auto_route`, `strict_route` |
| `proxy-suite-xray-sidecar` | `xray.exe` | hybrid backend's XRay-only outbounds |
| `proxy-suite-zapret` | `winws.exe` / `winws2.exe` | a child with the exact arguments Flowseal's / bol-van's Windows strategies use; never their `service.bat`, which would register a competing `zapret` service. zapret v1 and zapret2 are mutually exclusive, and other WinDivert users (GoodbyeDPI) conflict: validation says so |
| `proxy-suite-awg-<p>` | AmneziaWG tunnel | global VPN profile; amneziawg-windows installs each tunnel as its own Windows service, so this unit kind is a *managed service*, not a child (decided once the AWG research is in) |
| `proxy-suite-awg-ob-<p>` | `wireproxy-awg.exe` | AWG as a SOCKS outbound |
| `proxy-suite-tor` | `tor.exe` (+ lyrebird/snowflake) | outbound tagged `tor` |
| `proxy-suite-ssh-proxy` | `ssh.exe -D` (Windows OpenSSH) | outbound tagged `ssh-proxy` |
| `proxy-suite-tg-ws-proxy` | `tg-ws-proxy.exe` | |
| `proxy-suite-wl-<name>` | whitelist-bypass | creators/joiners |
| `proxy-suite-inbounds` | `xray.exe` | server listeners |
| `proxy-suite-killswitch` | in-service | sing-box `strict_route` first if it holds on Windows; WFP filters as the follow-up |
TProxy, cgroup/netns per-app routing and proxychains have no Windows counterpart. Per-app
routing becomes sing-box `process_name` / `process_path` rules on the TUN, plus a
`proxy-ctl apps run` that sets `HTTP(S)_PROXY`/`ALL_PROXY` for programs that honour them.
The system proxy (WinINet, per user) is set by the GUI for its user, not by the service.
### Who may change things
"Everything editable in the app" means no UAC prompt per edit: the API pipe grants SYSTEM and
Administrators full access and, by default, the interactive user (`S-1-5-4`). `userControl`
maps onto this: `userControl.enable = false` keeps the pipe to Administrators, and
`userControl.scopes` limit what non-admin callers may do, as upstream's do.
### Component manager
Binaries are not vendored into git. `ps-core::components` holds a manifest: name, version,
URL, SHA-256, archive layout, files to keep. The service downloads into `bin\`, verifies, and
switches atomically; the GUI's Components page shows versions and offers updates. Each manifest
entry follows its project's own Windows release (zapret's WinDivert driver and files exactly
as Flowseal / bol-van ship them).
### Testing on the Linux dev box
- `ps-core` unit tests, plus differential tests against upstream's Python parsers.
- Rendered configs are checked with `sing-box check` and `xray run -test` (from nixpkgs).
- `ps-service --console` runs on Linux against Linux sing-box/xray, so the API, supervisor,
timers and CLI are exercised end to end without Windows.
- Windows binaries are cross-compiled (see `README.md` for the toolchain).