feat(p2p): remote session pairing — relay, replication, co-host model#34
Merged
feat(p2p): remote session pairing — relay, replication, co-host model#34
Conversation
|
Milestone 1 — Remote Session Pairing: - relay/relay-server.mjs: persistent ed25519 key across restarts; stable peer ID required since it is baked into invite links - relay/package.json: add @libp2p/crypto for key serialization - app/package.json: add @libp2p/dcutr for direct connection upgrade (relay is bootstrap only; DCUtR hole-punches to WebRTC when NAT allows) - relay-config-store.ts: new — user-persisted relay addresses in userData JSON, no hardcoded relay in source (sovereignty thesis) - p2p-config.ts: remove static RELAY.ADDRESSES array; now runtime-loaded - relay-manager.ts: new — retry-with-backoff relay connection manager - p2p-service.ts: wire RelayManager + DCUtR service; add pull-request bridge via pendingPullRequests Map; add getInviteData(); fix getDiscoveredPeers() and getConnectedPeers() stubs; fix disconnectFromPeer - ipc-protocol.ts: new channels and payload types (relay, presence, pull-request bridge, invite URL) - protocol.ts: session param in createConnectUrl; generateShortCode() - main.ts: relay config IPC handlers; invite URL generation; deep-link protocol handler; replication pull-request bridge - preload.ts: expose getInviteUrl, joinSession, relay CRUD, onRelayStatus, onPeerPresence, respondToPullRequest, onPullRequest - P2PSettings.tsx: new — relay management UI with live status dots - ShareSessionPanel.tsx: new — shows whtnxt:// invite URL + short code; join-session input accepting URL or short code Milestone 2 — Replication wired to sessions: - useSessionReplication.ts: new hook — subscribes to RxDB change streams, pushes local changes to peers, applies incoming REPLICATION_CHANGES, responds to REPLICATION_PULL_REQUEST events with RxDB data - SessionView: activate hook on isActiveSession Milestone 3 — Co-host model + playback mutex: - session-interfaces.ts: add coHostIds + playbackOwnerId to SessionState; optional coHostIds in StartSessionConfig - schemas.ts: add coHostIds to PlaylistDocType; bump to version 2 - database.ts: v1→v2 migration for coHostIds - navigation-store.ts: handOffPlayback(toUserId) and takePlayback(userId) - SessionView: playback controls gated on isPlaybackOwner; hand-off UI libp2p v2 Stream API fixes (pre-existing errors resolved): - handshake.ts, replication.ts, ping.ts: source/sink → stream.send + stream.close; StreamHandler signature corrected; peerStore.all() is Promise not AsyncIterator; serviceName → serviceTag for mDNS https://claude.ai/code/session_01D1Vy5htbEpWnWcce1JdVSp
- docs_md/01 concepts/libp2p.md: new sections on Circuit Relay v2 +
DCUtR (relay-as-user-infrastructure, persistent key, RelayManager,
invite URL format) and libp2p v2 Stream API breaking changes
(AsyncIterable, send/close, StreamHandler, peerStore.all)
- docs_md/01 concepts/Circuit-Relay.md: update relay config to dynamic
store pattern; mark persistent-key pitfall as resolved; add
@libp2p/rendezvous pitfall (package does not exist on npm)
- docs_md/04 architecture/adr/adr-260315-p2p-session-pairing.md: new —
five decisions: relay+DCUtR over DHT, user-configured relay, invite
URL over rendezvous, pull-request bridge correlation pattern, playback
mutex
- docs_md/08 specs/p2p-session-pairing-spec.md: new — full M1–M3 spec
covering relay config store, ping protocol, IPC channels, share UI,
useSessionReplication hook, pull-request bridge, co-host model,
schema v2 migration, libp2p v2 API notes, file inventory
- docs_md/index.md + 00 index/{ADR,CONCEPTS,SPECS}.md: updated indexes
https://claude.ai/code/session_01D1Vy5htbEpWnWcce1JdVSp
c60b9d5 to
47d5064
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements MVP 0.1.0 remote session pairing across three milestones:
whtnxt://invite URLs with short codes, relay management UI (P2PSettings), and share/join panel (ShareSessionPanel). Relay addresses stored in userData JSON — no hardcoded relay in source.useSessionReplicationhook subscribes to RxDB change streams, pushes local changes to peers, applies incomingREPLICATION_CHANGES, and handlesREPLICATION_PULL_REQUESTvia a correlation-ID bridge between renderer and utility process.coHostIdson playlist schema (v5 migration),playbackOwnerIdon session state, hand-off/take-playback actions in navigation store, playback controls gated on ownership inSessionView.Also fixes pre-existing libp2p v2 Stream API type errors in handshake, replication, and ping protocols (
source/sink→stream.send+stream.close).Key files
relay/relay-server.mjs(persistent ed25519 key),relay-manager.ts,relay-config-store.tsp2p-service.ts,protocols/ping.ts(new)ipc-protocol.ts,main.ts,preload.tshooks/useSessionReplication.ts(new)ShareSessionPanel.tsx,P2PSettings.tsx,SessionView.tsxschemas.ts(playlist v5),database.ts(migration 5: coHostIds)CI status
@libp2p/dcutrmodule resolution, vite/rollup types,PlaylistViewcontext menu)needs-p2p-reviewlabel appliedTest plan
cd relay && node relay-server.mjs), confirm persistent peer ID across restartswhtnxt://URL and short code