Skip to content

feat(codework): add Iroh P2P listener, Door actor admission, and Relay authority checks - #196

Open
sanchitrk wants to merge 1 commit into
feat/iroh-p2p-slice-1from
feat/iroh-p2p-slice-2
Open

sanchitrk wants to merge 1 commit into
feat/iroh-p2p-slice-1from
feat/iroh-p2p-slice-2

Conversation

@sanchitrk

@sanchitrk sanchitrk commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds an Iroh P2P listener and client carrier alongside WebSockets in codework serve, extends Door with read-only actor admission and shared socket transport, and wires Relay-backed access verification with periodic refresh and fail-closed teardown.

Stacked on #195 (feat/iroh-p2p-slice-1).

@codeworksh/schema

  • Added @codeworksh/schema/iroh with ALPN = "codeworkrpc/1", frame caps (16 KiB first frame, 4 MiB data frames), and Hello / Reply wire schemas.
  • Extended Principal with the actor variant and included Forbidden in the Door middleware error union.
  • Extended device.pair response with endpointId and irohRelayUrl.

packages/codework

  • Iroh listener & client carrier (src/server/iroh.ts, src/server/iroh-binding.ts): Lazily loads optional @number0/[email protected] and binds the machine identity key on ALPN = "codeworkrpc/1" (degrading cleanly to WebSocket-only serving if unavailable). Implements 4-byte BE length-prefixed framing, handshake limits (10s deadline, 32 concurrent, max 2 per peer, 16 KiB first frame), three admissions (pair, device, actor), and client carrier helpers (bindClient, pair, connect, rpcLayer).
  • Door & read allowlist (src/server/door.ts, src/server/principal.ts): Shared RpcServer.Protocol + Door.Transport serving both WebSocket upgrades and Iroh streams, stripping client-supplied x-codework-connection headers, tracking actor connections (endAllActors), and restricting actor callers to read-only RPCs (server.info, index.sync, thread.sync, thread.page).
  • Authority (src/server/authority.ts): Verifies incoming actor connections against Relay's /v1/machines/check, refuses reserved root id/scope and unenrolled/leaving machines locally without contacting Relay, caches denials for 10s, refreshes standing answers every 15s, fails closed at 30s if Relay is unreachable, and clears local Relay registration plus closes all actor connections immediately on Relay.MachineRevoked.
  • Pairing, heartbeat & CLI (src/server/pairing.ts, src/server/handlers.ts, src/machine/, src/cli/cmd/handlers/service/pair.ts): Added Pairing.Service.admit(deviceId, key) for Iroh device connections, wired Iroh.Service home relay URL into machine heartbeats, ended actor connections on machine.disconnect, and updated codework service pair to print endpoint id (and iroh relay when configured).

Testing

  • Added E2E suite packages/codework/test/iroh.test.ts with __artifacts__/iroh.json — passed (1/1): covers Iroh pair/device/actor handshakes, device.revoke teardown, unenrolled/leaving & reserved-root local refusals, negative caching, read-only allowlist & header spoof blocking, live denial refresh, fail-closed on Relay outage while paired devices stay up, MachineRevoked clearing local Relay config, oversized frame rejection, and WebSocket-only fallback.
  • packages/codework: vp test test/door.test.ts (1/1 passed), vp test test/pair.test.ts (6/6 passed, updated pair.json for endpoint id).
  • apps/server: vp test test/door.test.ts test/link.test.ts test/paired.test.ts test/schema.test.ts (8/8 passed).
  • vp run verify (build, vp check, package typechecks, knip) — passed.
  • vp check apps/contract apps/server apps/web and app typechecks — passed.
  • Restarted local dev RPC server against .scratch/home and verified vp run dev:cli service pair prints endpoint id:.

Built with Antigravity (Gemini).


Prove it works
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

This branch has not been deployed

No deployments
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