Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(p2p): relay p2p_promote / p2p_promote_ack so the TURN-to-direct cutover completes

0xken15634a01d0e0d1
diff --git a/backend/src/lib/p2pSignaling.test.ts b/backend/src/lib/p2pSignaling.test.ts
index a18392928..e86172226 100644
--- a/backend/src/lib/p2pSignaling.test.ts
+++ b/backend/src/lib/p2pSignaling.test.ts
@@ -1,12 +1,19 @@
import { describe, expect, it } from 'vitest'
import {
isEncryptedP2pFrame,
+ P2P_DOWN_TYPES,
P2P_SIGNAL_MAX_FRAMES_PER_MINUTE,
+ P2P_UP_TYPES,
p2pFrameBytes,
P2pSignalRateGuard,
} from './p2pSignaling.js'
describe('P2P signaling relay guard', () => {
+ it('routes the whole exchange, the TURN-to-direct cutover included', () => {
+ expect([...P2P_DOWN_TYPES].sort()).toEqual(['p2p_abort', 'p2p_ice_candidate', 'p2p_offer', 'p2p_promote'])
+ expect([...P2P_UP_TYPES].sort()).toEqual(['p2p_abort', 'p2p_answer', 'p2p_ice_candidate', 'p2p_promote_ack'])
+ })
+
it('accepts only opaque pairwise E2EE envelopes', () => {
const encrypted = {
type: 'p2p_offer',
diff --git a/backend/src/lib/p2pSignaling.ts b/backend/src/lib/p2pSignaling.ts
index 5cd86abdb..167d64729 100644
--- a/backend/src/lib/p2pSignaling.ts
+++ b/backend/src/lib/p2pSignaling.ts
@@ -8,8 +8,12 @@ export const P2P_SIGNAL_MAX_BYTES = 128 * 1024
export const P2P_SIGNAL_MAX_FRAMES_PER_MINUTE = 240
export const P2P_SIGNAL_MAX_BYTES_PER_MINUTE = 4 * 1024 * 1024
-export const P2P_DOWN_TYPES = new Set(['p2p_offer', 'p2p_ice_candidate', 'p2p_abort'])
-export const P2P_UP_TYPES = new Set(['p2p_answer', 'p2p_ice_candidate', 'p2p_abort'])
+// p2p_promote / p2p_promote_ack: the client's TURN-to-direct upgrade cutting a live session over to a
+// shadow one it negotiated beside it (the CLI's remoteRelay.ts promoteToDirect(), and the phone's port of
+// it). They ride the same sealed signaling channel as the offer/answer they follow; without them here
+// the cutover's promote was rejected as P2P_TYPE_REJECTED and every upgrade timed out on its ack.
+export const P2P_DOWN_TYPES = new Set(['p2p_offer', 'p2p_ice_candidate', 'p2p_abort', 'p2p_promote'])
+export const P2P_UP_TYPES = new Set(['p2p_answer', 'p2p_ice_candidate', 'p2p_abort', 'p2p_promote_ack'])
export function p2pFrameBytes(frame: Frame): number {
return Buffer.byteLength(JSON.stringify(frame), 'utf8')