合并 0.4.7 双向并发传输封版

# Conflicts:
#	README.md
#	android/app/src/main/java/com/qft/optical/DownloadClient.kt
#	android/app/src/main/java/com/qft/optical/UploadClient.kt
#	docs/PROTOCOL.md
#	windows/src/sender.rs
This commit is contained in:
zhy
2026-08-11 14:27:30 +08:00
18 changed files with 407 additions and 74 deletions
+8 -11
View File
@@ -1,4 +1,4 @@
# QFT protocol notes — v0.4.6
# QFT protocol notes — v0.4.7
## 1. Windows → Android optical: QFT2
@@ -36,7 +36,7 @@ senderLen 2 u16 BE
senderDevice N UTF-8
```
### Optical parameters in v0.4.6
### Optical parameters in v0.4.7
- one QR per display frame;
- DATA payload: **450 B**;
@@ -75,7 +75,7 @@ The overlay is derived from the same ROI used by the decoder, so the green/yello
Discovery order includes QR hint, UDP `QFTDISC2`, gateway/direct candidates and bounded current-subnet fallback.
## 4. Android → Windows upload
## 4. 扫码本地直传(Android ↔ Windows)
Parallel v2 flow:
@@ -85,19 +85,16 @@ POST /qft/upload/chunk (parallel, offset based)
POST /qft/upload/finish
```
Windows preallocates a `.qftpart`, writes chunks at explicit offsets, verifies SHA-256, then renames to the final file. Per-file worker count is capped at 8; chunk size is selected from 4/8/16 MiB by file size.
Windows preallocates a `.qftpart`, writes chunks at explicit offsets, verifies SHA-256, then renames to the final file. Uploads target 8 workers per file (bounded by the usable chunks and device capacity); the requested chunk size is derived from the file size and clamped to **64 KiB–16 MiB**. Repeated `init` requests carrying the same `X-QFT-Upload-Key` resume the matching active upload session; repeated chunk and finish requests are idempotent so a lost response can be retried safely. Chunk completion is recorded only after the positioned write reaches stable storage.
Repeated `init` requests carrying the same `X-QFT-Upload-Key` resume the matching active upload session. The response may include a `missing` chunk-index array; the client sends only those chunks. Chunk completion is recorded only after the positioned write reaches stable storage.
## 5. Windows → Android download
## 5. Windows → Android direct download
Files of at least 32 MiB use up to 8 parallel bounded range requests:
The same QFTPAIR2 local session can declare the download direction. Android discovers and verifies the Windows sender, then downloads `GET /qft/download` with exact single-range requests:
```text
GET /qft/download
Range: bytes=<start>-<end>
```
Android preallocates an app-private `.qftpart`, writes each range at its fixed offset and persists a separate completion bitmap. A reconnect or process restart downloads only missing ranges. After every range is present, Android verifies the QR-carried SHA-256 before publishing the file to `Downloads/QFT`.
The sender returns `206 Partial Content`, the matching `Content-Range`, and the exact requested body length. Android splits the file toward 8 workers with **64 KiB–16 MiB** chunks, stores each completed chunk in a `.qftpart.map` ledger, and resumes only missing chunks after a reconnect. Each range retries with the currently available `Network`; the complete partial file must pass SHA-256 before it is published to `Downloads/QFT`.
The Android `WifiNetworkSpecifier` request remains registered for the entire transfer page. It is released when the user returns to the home page (or the Activity is destroyed); a replacement `Network` delivered after a brief radio loss is adopted by subsequent chunk/range retries.
For both direct-transfer directions, the Windows listener may accept connections non-blockingly for shutdown responsiveness, but each accepted file socket is switched to blocking I/O with explicit timeouts before reading or writing request bodies. This prevents `WSAEWOULDBLOCK (10035)` from turning an in-progress parallel transfer into an HTTP 500 failure.