From 7fd12ca190c3411e7a1432c66f93a54f3e6c590c Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 17 Mar 2026 16:50:38 +0100 Subject: [PATCH 1/3] feat(ocap-kernel): add allowedWsHosts param to initializeRemoteComms Allow platform services to pass an allowedWsHosts list through the initializeRemoteComms RPC method to the remote comms options. Co-Authored-By: Claude Opus 4.6 --- .../initializeRemoteComms.test.ts | 65 +++++++++++++++++++ .../initializeRemoteComms.ts | 5 ++ 2 files changed, 70 insertions(+) diff --git a/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.test.ts b/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.test.ts index 1e839ce5c4..61012777b5 100644 --- a/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.test.ts +++ b/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.test.ts @@ -70,6 +70,42 @@ describe('initializeRemoteComms', () => { expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true); }); + it('should accept params with allowedWsHosts', () => { + const validParams = { + keySeed: '0x1234567890abcdef', + allowedWsHosts: ['localhost', 'example.com'], + }; + + expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true); + }); + + it('should accept params with empty allowedWsHosts array', () => { + const validParams = { + keySeed: '0x1234567890abcdef', + allowedWsHosts: [], + }; + + expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true); + }); + + it('should reject params with non-array allowedWsHosts', () => { + const invalidParams = { + keySeed: '0x1234567890abcdef', + allowedWsHosts: 'not-an-array', + }; + + expect(is(invalidParams, initializeRemoteCommsSpec.params)).toBe(false); + }); + + it('should reject params with non-string elements in allowedWsHosts', () => { + const invalidParams = { + keySeed: '0x1234567890abcdef', + allowedWsHosts: ['localhost', 123], + }; + + expect(is(invalidParams, initializeRemoteCommsSpec.params)).toBe(false); + }); + it('should accept params with incarnationId', () => { const validParams = { keySeed: '0x1234567890abcdef', @@ -562,6 +598,31 @@ describe('initializeRemoteComms', () => { ); }); + it('should pass allowedWsHosts to hook when provided', async () => { + const mockInitializeRemoteComms: InitializeRemoteComms = vi.fn( + async () => null, + ); + + const hooks = { + initializeRemoteComms: mockInitializeRemoteComms, + }; + + const params = { + keySeed: '0xtestseed', + allowedWsHosts: ['localhost', 'example.com'], + }; + + await initializeRemoteCommsHandler.implementation(hooks, params); + + expect(mockInitializeRemoteComms).toHaveBeenCalledWith( + '0xtestseed', + { + allowedWsHosts: ['localhost', 'example.com'], + }, + undefined, + ); + }); + it('should pass all options when all are provided', async () => { const mockInitializeRemoteComms: InitializeRemoteComms = vi.fn( async () => null, @@ -576,6 +637,7 @@ describe('initializeRemoteComms', () => { relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'], maxRetryAttempts: 5, maxQueue: 100, + allowedWsHosts: ['localhost'], }; await initializeRemoteCommsHandler.implementation(hooks, params); @@ -586,6 +648,7 @@ describe('initializeRemoteComms', () => { relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'], maxRetryAttempts: 5, maxQueue: 100, + allowedWsHosts: ['localhost'], }, undefined, ); @@ -620,6 +683,7 @@ describe('initializeRemoteComms', () => { expect(options).not.toHaveProperty('relays'); expect(options).not.toHaveProperty('maxRetryAttempts'); expect(options).not.toHaveProperty('maxQueue'); + expect(options).not.toHaveProperty('allowedWsHosts'); return null; }, ); @@ -641,6 +705,7 @@ describe('initializeRemoteComms', () => { relays: ['/dns4/relay.example/tcp/443/wss/p2p/relay'], maxRetryAttempts: 5, maxQueue: 100, + allowedWsHosts: ['localhost'], }; expect(is(validParams, initializeRemoteCommsSpec.params)).toBe(true); diff --git a/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.ts b/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.ts index faf6e6f61e..849c457d4f 100644 --- a/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.ts +++ b/packages/ocap-kernel/src/rpc/platform-services/initializeRemoteComms.ts @@ -15,6 +15,7 @@ const initializeRemoteCommsParamsStruct = object({ relays: optional(array(string())), maxRetryAttempts: optional(number()), maxQueue: optional(number()), + allowedWsHosts: optional(array(string())), incarnationId: optional(string()), }); @@ -23,6 +24,7 @@ type InitializeRemoteCommsParams = { relays?: string[]; maxRetryAttempts?: number; maxQueue?: number; + allowedWsHosts?: string[]; incarnationId?: string; }; @@ -69,6 +71,9 @@ export const initializeRemoteCommsHandler: InitializeRemoteCommsHandler = { if (params.maxQueue !== undefined) { options.maxQueue = params.maxQueue; } + if (params.allowedWsHosts !== undefined) { + options.allowedWsHosts = params.allowedWsHosts; + } return await initializeRemoteComms( params.keySeed, options, From 26ffdc6cec8b012da54ea8d0f561ba7643f9d090 Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 17 Mar 2026 17:06:07 +0100 Subject: [PATCH 2/3] feat(ocap-kernel): enable relay discovery in circuit relay transport Configure circuitRelayTransport with discoverRelays: 1 so the client actively seeks and maintains a relay reservation. Co-Authored-By: Claude Opus 4.6 --- .../src/remotes/platform/connection-factory.test.ts | 11 ++++++++++- .../src/remotes/platform/connection-factory.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts b/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts index a8e94c9486..bc13bab00b 100644 --- a/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts +++ b/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts @@ -28,8 +28,9 @@ const libp2pState: { vi.mock('@chainsafe/libp2p-noise', () => ({ noise: () => ({}) })); vi.mock('@chainsafe/libp2p-yamux', () => ({ yamux: () => ({}) })); vi.mock('@libp2p/bootstrap', () => ({ bootstrap: () => ({}) })); +const circuitRelayTransport = vi.fn(() => ({})); vi.mock('@libp2p/circuit-relay-v2', () => ({ - circuitRelayTransport: () => ({}), + circuitRelayTransport, })); vi.mock('@libp2p/identify', () => ({ identify: () => ({}) })); vi.mock('@libp2p/webrtc', () => ({ webRTC: () => ({}) })); @@ -316,6 +317,14 @@ describe('ConnectionFactory', () => { expect(callArgs.transports).toHaveLength(4); // webSockets, webTransport, webRTC, circuitRelay }); + it('configures circuit relay transport with relay discovery', async () => { + factory = await createFactory(); + + expect(circuitRelayTransport).toHaveBeenCalledWith({ + discoverRelays: 1, + }); + }); + it('uses provided key seed for key generation', async () => { factory = await createFactory(); diff --git a/packages/ocap-kernel/src/remotes/platform/connection-factory.ts b/packages/ocap-kernel/src/remotes/platform/connection-factory.ts index f9fd2baef2..21f81b6272 100644 --- a/packages/ocap-kernel/src/remotes/platform/connection-factory.ts +++ b/packages/ocap-kernel/src/remotes/platform/connection-factory.ts @@ -225,7 +225,7 @@ export class ConnectionFactory { ], }, }), - circuitRelayTransport(), + circuitRelayTransport({ discoverRelays: 1 }), ...this.#directTransports.map( (dt) => dt.transport as ReturnType, ), From f99cce385964794a652804b8f9a6450df9da6e83 Mon Sep 17 00:00:00 2001 From: Dimitris Marlagkoutsos Date: Tue, 17 Mar 2026 17:12:10 +0100 Subject: [PATCH 3/3] Revert "feat(ocap-kernel): enable relay discovery in circuit relay transport" This reverts commit 26ffdc6cec8b012da54ea8d0f561ba7643f9d090. --- .../src/remotes/platform/connection-factory.test.ts | 11 +---------- .../src/remotes/platform/connection-factory.ts | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts b/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts index bc13bab00b..a8e94c9486 100644 --- a/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts +++ b/packages/ocap-kernel/src/remotes/platform/connection-factory.test.ts @@ -28,9 +28,8 @@ const libp2pState: { vi.mock('@chainsafe/libp2p-noise', () => ({ noise: () => ({}) })); vi.mock('@chainsafe/libp2p-yamux', () => ({ yamux: () => ({}) })); vi.mock('@libp2p/bootstrap', () => ({ bootstrap: () => ({}) })); -const circuitRelayTransport = vi.fn(() => ({})); vi.mock('@libp2p/circuit-relay-v2', () => ({ - circuitRelayTransport, + circuitRelayTransport: () => ({}), })); vi.mock('@libp2p/identify', () => ({ identify: () => ({}) })); vi.mock('@libp2p/webrtc', () => ({ webRTC: () => ({}) })); @@ -317,14 +316,6 @@ describe('ConnectionFactory', () => { expect(callArgs.transports).toHaveLength(4); // webSockets, webTransport, webRTC, circuitRelay }); - it('configures circuit relay transport with relay discovery', async () => { - factory = await createFactory(); - - expect(circuitRelayTransport).toHaveBeenCalledWith({ - discoverRelays: 1, - }); - }); - it('uses provided key seed for key generation', async () => { factory = await createFactory(); diff --git a/packages/ocap-kernel/src/remotes/platform/connection-factory.ts b/packages/ocap-kernel/src/remotes/platform/connection-factory.ts index 21f81b6272..f9fd2baef2 100644 --- a/packages/ocap-kernel/src/remotes/platform/connection-factory.ts +++ b/packages/ocap-kernel/src/remotes/platform/connection-factory.ts @@ -225,7 +225,7 @@ export class ConnectionFactory { ], }, }), - circuitRelayTransport({ discoverRelays: 1 }), + circuitRelayTransport(), ...this.#directTransports.map( (dt) => dt.transport as ReturnType, ),