Skip to content

feat: relay encrypted mobile sessions with bounded memory - #2014

Merged
yansfil merged 12 commits into
mainfrom
feat/relay-server
Nov 2, 2026
Merged

yansfil merged 12 commits into
mainfrom
feat/relay-server

Conversation

@yansfil

@yansfil yansfil commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Related: #2011

Summary

  • 기기 하나와 폰 여럿을 연결하는 독립 실행형 hide-relay 서버를 추가합니다.
  • 서버는 메모리에서 방을 관리하고 암호문을 그대로 전달하며, 재시작하면 모든 연결이 새로 입장합니다.
  • 연결·방·IP·프레임·일일 전송량 상한을 넘긴 연결에는 거부 사유를 보내고 내용 없는 기록을 남깁니다.
  • 느린 폰의 대기열이 차면 그 폰만 끊고 기기와 다른 폰의 통신은 유지합니다.

Review

  • 판단해 주세요: 서명·입장 재전송·봉투 형식은 서버가 검사하고, 암호문 변조·재전송은 종단이 검사한 뒤 해당 폰을 닫습니다.
  • 조심해서 볼 파일: hide-relay/src/state.rs, server.rs - 수신자 상한, 연결 소유권, 종료 사유 전달과 정리 경로.
  • 비용 검토: 프레임마다 짧은 잠금과 한 수신자 전달. 연결당 데이터 8개·제어 16개, 소켓 512개와 추가 HTTP 작업 32개, 종료 대기 16초입니다.
  • 예산 정책: 전송 실패·종료한 수신자로 향한 유효 프레임도 일일 예산에 포함해 수신 트래픽의 우회를 막습니다.
  • 운영 경계: TLS·로그 보관·알림은 배포가 담당하며, 신뢰할 프록시는 X-Real-IP를 덮어써야 합니다. IPv6는 /64 단위로 제한합니다.

Evidence

  • 확인한 것: 실제 loopback 암호화 클라이언트 19개 시나리오로 전달, 모든 상한, 변조·재전송, 느린 폰 격리와 재시작을 검사했습니다.
  • 확인한 것: 최대 256 KiB 메시지의 5개 프레임을 한꺼번에 보낸 뒤 정상 복원했고, 공격 burst·반복 입퇴장 격리, 유휴 종료와 불완전 HTTP 연결의 재시작을 확인했습니다.
  • 확인한 것: 현재 커밋의 전체 CI와 중계 서버 Linux·Windows·macOS CI가 통과했습니다.
  • 재실행 기록: 로컬 전체 Rust 실행은 기존 격리 테스트에서 실패했으나 같은 커밋의 단독 확인은 통과했습니다. Windows 데스크톱 CI는 테스트 준비 단계에서 시간 초과 후 한 번의 재실행으로 21개 테스트가 통과했습니다. 첫 실패는 모두 보존했습니다.
  • 확인하지 못한 것: 실제 폰·hided 통합, 운영 TLS·알림과 운영 부하 측정은 별도 범위입니다.
Verification record
  • Head: ecd7a43825e152b9a9da8f7147cbba95e9805ccd
  • Base: main; protocol feat: share encrypted mobile relay messages across native and web #2011 merged, then main merged into this branch without rewriting history.
  • Review follow-up: direction-specific backpressure isolation, eight-frame queue, /64 rate accounting, distinct timeout events, 16-second shutdown bound, non-panicking stderr, client-only dependency moved to development dependencies.
  • Current local service suite: 19 passed, 1 opt-in capacity test ignored; 6.01 seconds. The local CI-profile runner also passed all 19 in 6.113 seconds.
  • The earlier workspace CI exposed an OS-buffer-dependent control-queue saturation assertion. The fixture now lowers the real server control budget to four and holds admitted phones until their owned departure reservations force refusal, without changing the isolation or ordering assertions.
  • Data/control slots are independently reserved with permits and merged through one FIFO, preserving lifecycle/data ordering; each accepted phone reserves its departure notification.
  • A non-reading device with a small TCP receive window survives unauthenticated data bursts and repeated joins/leaves; only the attacker or excess joining phone is refused.
  • Pipelined refusal teardown sends FIN and drains at most one bounded frame; when that budget fills it keeps the socket only until the existing five-second deadline, preserving the readable refusal without unbounded draining.
  • Idle timeout injection keeps the production 90-second ceiling and exercises the real socket with a one-second setting.
  • Scoped clippy, formatting and dependency feature checks: PASS.
  • Current local checks at ecd7a43: lint PASS; web/desktop PASS (2,767 passed, 7 skipped). The original test-scoped command stopped at the unchanged own_devices test (3,924 passed, 1 failed, 20 ignored); that test passed one same-SHA confirmation in 0.26 seconds and is already tracked by with-hide/hide-private#430. The first failure is retained, and this is not a claim that the original full command passed. Checks ran under the shared lock. The full local sequence previously passed at ad5e56a (7,344 Rust passed/169 ignored).
  • Independent re-review: PASS at f3b6e48; the requested non-panicking invariant diagnostic and repeated peer_left documentation are included in ad5e56a, with no further review requested.
  • Current CI at ecd7a43: all three relay platform jobs and the full Rust job passed (7,327 + 20 tests, no retries). Windows desktop failed before tests in platform-fixture.ts:142 with powershell.exe spawnSync ETIMEDOUT. The first log is retained. One failed-job rerun passed all 21 Windows desktop tests with no flaky result; run 41424361290, attempt 2 finished successfully, including the final verify gate. All other planned jobs passed in the first attempt. At ad5e56a, the full Rust job found the saturation-fixture failure described above. The same run also recorded an unrelated core own_devices test failure that passed its configured retry. Previous reviews found backpressure isolation bugs; the follow-up and new caller tests address both directions and lifecycle capacity.
  • Earlier head d58982d7d: Linux/Windows/macOS relay CI passed; opt-in capacity test passed with 512 connections, 128 rooms, 384 encrypted sessions and 72 MiB exchanged in 95.36 seconds. This is functional capacity evidence, not a throughput guarantee for the current head.
  • Binary smoke at 8483ea6 also passed with its stderr pipe closed.
  • Earlier binary smoke: health 200, SIGTERM exit 0, released listener and content-free JSON lifecycle logs.
  • Retained first failures: full Rust run failed an unchanged plugin confirmation test; subsequent full run failed the terminal parser build during disk pressure; retry passed that build but failed the unchanged holder foreground-program assertion (sh versus cat).
  • Earlier pnpm 10 run reported ENOSPC and three timeouts. Its output is retained; neither timeout causality nor a source defect is established.
  • CI policy checks before the follow-up: selection 89, failure reporting 75, verification entrypoints 18, called-workflow permissions 3 passed.
  • First push merge-order result: Stay as you are.
  • Scope: memory-only service, local execution, server contract and CI; no hosting or client UI changes.

@yansfil
yansfil marked this pull request as ready for review November 2, 2026 08:21
Base automatically changed from feat/relay-protocol to main November 2, 2026 08:46
@yansfil
yansfil merged commit 4f60013 into main Nov 2, 2026
129 of 131 checks passed
@yansfil
yansfil deleted the feat/relay-server branch November 2, 2026 11:39
yansfil added a commit that referenced this pull request Nov 2, 2026
Related: #2011

## Summary

폰이 기본으로 Hide 중계를 통해 연결되고, 설정의 한 연결 줄에서 연결 상태와 다시 시도·업데이트·상한 거부를 확인합니다.
QR은 app.withhide.dev를 열며 5분 뒤 만료됩니다. Tailscale 직접 연결은 고급에서 고릅니다.
방법마다 페어링한 폰을 따로 유지하고, 끄기·해제 시 연결을 닫습니다.
폰 내용은 기기와 폰 사이에서 암호화합니다.
기존 Tailscale 설정은 그대로 이어 쓰고 새 설정은 중계로 시작합니다.

![Settings Mobile: encrypted relay connection, five-minute QR and
advanced
Tailscale](https://github.com/yansfil/pr-assets/blob/main/hide/feat-hided-relay/e8fa807/settings-qr.png?raw=true)

실제 Settings 컴포넌트의 격리 갤러리입니다.
연결 줄, QR 만료 안내, 접힌 고급 영역을 확인해 주세요.

![Settings Mobile: relay stays available when the old Tailscale setup
cannot be
removed](https://github.com/yansfil/pr-assets/blob/main/hide/feat-hided-relay/5eeb736/settings-cleanup.png?raw=true)

이전 Tailscale 연결을 정리할 CLI가 없어도 중계는 연결되고, 같은 한 줄에 정리 실패가 남습니다.

## Review

- **판단해 주세요**: 연결 상태와 암호화 설명의 길이, 고급 Tailscale의 발견성.
- **조심해서 볼 파일**: `hided/src/mobile/relay.rs`, `phone.rs` - 암호화 경계, 종료
순서, 취소와 큐 상한.
- **조심해서 볼 파일**: `mobile/mod.rs`, `phones.rs`, `store.rs` - 키 저장, 방식 전환과
기존 폰 보존, 재연결 후 요청 기록.
- **비용 검토**: 연결 1개, 폰 작업 8개, 폰당 수신 8프레임·공유 송신 32프레임; 상태 전환만 발행하며 core 잠금
안에서 네트워크 작업을 하지 않습니다.

## Evidence

- **확인한 것**: 실제 hided 중계 통합 6개가 macOS·Linux·Windows에서 암호화·재연결·방법별 폰
보존·해제·끄기·미인증 제한 시간을 확인합니다.
- **확인한 것**: 입력 중단 테스트가 연결을 끊고 같은 요청을 재시도할 때 영구 대기에 남지 않음을 확인합니다.
- **확인한 것**: Mobile UI 24개, 직접 연결 브라우저 5개와 격리 갤러리의 한글·영문·큰
글씨·dark/light·QR·고급 상태를 확인했습니다.
- **확인한 것**: 최신 커밋에서 로컬 lint·Rust 7,357개·web 2,471개·desktop 307개·빌드·디자인
계약과 GitHub CI가 통과했습니다.
- **재시도 이력**: 기존 기기 테스트 #430·#439는 최초 실패 후 로컬 단독 1회와 CI 작업 1회 재실행에서
통과했습니다. CI에는 기존 세션 복원 #419의 자동 재시도도 있습니다.
- **확인하지 못한 것**: 실제 폰·native 앱·운영 TLS와 실제 PTY 답장 재전송은 통합·배포 검증에 남아 있습니다.

<details><summary>Verification record</summary>

Head: `d75b9db7d9ef0287392452ad5fc77bfce605f26c`.
Base: `b1b25cde4`, including protocol #2011, Memory correction #2020,
relay server #2014 and hosted phone #2019.
Scope: mobile-relay B1-B10, hided B24, B28; hided transport, Settings
Mobile, owning architecture/UI guides.
The architecture merge preserves both the hosted phone WASM initiator
and the device responder/admission/authentication contract.
Cargo.lock and workspace-hack did not change in that merge; their shared
feature union was generated at `92620a992` and passes CI.
Caller tests use shared admission/routing types and real Noise sessions
without implementing a second relay service.
The interrupted-input test uses the real phone/Noise path and node
permission boundary; it does not claim an actual PTY write.
The original socket handler already detached its input task on
disconnect, so the original cancellation premise was not reproduced.
The follow-up additionally settles from the blocking operation with an
Uncertain drop guard; the caller test verifies disconnect/retry lifetime
rather than isolating that guard.
Independent re-review passed at `5eeb73668`; the additional live-peer
and unreaped-task bound at `744506a3e` was reviewed and accepted.
The QR screenshot was captured at `e8fa80774`; the cleanup screenshot
was captured at `5eeb73668`; the Settings product changes are unchanged
since that follow-up.
The five direct-mobile browser journeys passed at `6c2a6e338` without
weaker assertions or timeouts.
The Cursor fixture now explicitly selects Advanced > Use Tailscale
before enabling Mobile.

Current-head local verification ran on macOS under the shared mission
lock:

- `bash scripts/verify-cargo.sh lint`: PASS, 1m 10s.
- `bash scripts/verify-cargo.sh test-scoped`: core 3,929 passed, 1
failed, 20 ignored; stopped at the existing own_devices assertion in
`herdr-core/src/runtime/tests/own_devices.rs:158`.
- The only exact-test rerun on the same SHA passed in 0.27s; the initial
Kit/GuardrailPolicy assertion failure remains recorded, matching
[#430](with-hide/hide-private#430) and
[#439](with-hide/hide-private#439).
- `bash scripts/verify-cargo.sh test-scoped --workspace --exclude
herdr-core` then ran the crates the initial command had not reached:
3,427 passed, 149 ignored.
- Combined Rust coverage: 7,357 passed, 169 ignored, including the one
separately rerun test; this is a split completion after an initial
failure, not an uninterrupted green run.
- `bash scripts/verify-web.sh`: PASS; web 2,471 passed / 3 skipped,
desktop 307 passed / 4 skipped; type checks, lint and builds passed.
- `node scripts/check-design-contract.mjs`: PASS.

[GitHub CI run
41456834038](https://github.com/with-hide/hide/actions/runs/41456834038)
passed on attempt 2 after exactly one failed-job rerun:

- Attempt 1: Rust 7,338 passed / 1 failed / 166 skipped; own_devices
#430/#439 failed both automatic attempts.
- Attempt 2: Rust 7,339 passed / 166 skipped; own_devices passed on its
first attempt in 0.027s.
- Attempt 2 also includes one automatic retry of the existing
session-restore test
[#419](with-hide/hide-private#419); the first
failure remains in its job log.
- Linux and Windows each passed all six mobile_relay caller tests on
attempt 1; Windows job `125315707247` completed successfully.
- Linux browser shards and Windows E2E passed on attempt 1 without flaky
results.
- Cursor phone passed in shard 6 (`125317575438`, 6.6s); the
reopened-tab test tracked by #418 passed in shard 4 (`125317575230`,
3.3s), both on their first attempt.
- macOS desktop, protocol and packaging lanes passed; macOS hided mobile
evidence is the local run above.

Real phone/native-app interaction, production TLS and actual PTY replay
remain outside this PR's verified evidence.

</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant