Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/kernel-test/src/remote-comms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
PlatformServices,
RemoteMessageHandler,
RemoteCommsOptions,
RemoteMessageBase,
} from '@metamask/ocap-kernel';
import { NodejsPlatformServices } from '@ocap/nodejs';
import { describe, it, expect, beforeEach } from 'vitest';
Expand Down Expand Up @@ -77,11 +78,13 @@ class DirectNetworkService {
return Promise.resolve();
},

async sendRemoteMessage(to: string, message: string) {
async sendRemoteMessage(to: string, messageBase: RemoteMessageBase) {
const fromPeer = actualPeerId ?? tempPeerId;
// Route message directly to the target peer's handler
const targetHandler = self.peerRegistry.get(to);
if (targetHandler) {
// Stringify the message object for transmission
const message = JSON.stringify(messageBase);
const response = await targetHandler(fromPeer, message);
// If there's a response, send it back
if (response) {
Expand All @@ -95,6 +98,15 @@ class DirectNetworkService {
}
},

async handleAck(_peerId: string, _ackSeq: number) {
// Mock implementation - direct network doesn't need ACK handling
return Promise.resolve();
},

updateReceivedSeq(_peerId: string, _seq: number) {
// Mock implementation - direct network doesn't need sequence tracking
},

async initializeRemoteComms(
keySeed: string,
_options: RemoteCommsOptions,
Expand Down
5 changes: 3 additions & 2 deletions packages/ocap-kernel/src/Kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,11 @@ describe('Kernel', () => {
mockKernelDatabase,
);
const remoteManagerInstance = mocks.RemoteManager.lastInstance;
await kernel.sendRemoteMessage('peer-123', 'hello');
const messageBase = { method: 'deliver' as const, params: ['hello'] };
await kernel.sendRemoteMessage('peer-123', messageBase);
expect(remoteManagerInstance.sendRemoteMessage).toHaveBeenCalledWith(
'peer-123',
'hello',
messageBase,
);
});
});
Expand Down
10 changes: 7 additions & 3 deletions packages/ocap-kernel/src/Kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { KernelRouter } from './KernelRouter.ts';
import { KernelServiceManager } from './KernelServiceManager.ts';
import type { KernelService } from './KernelServiceManager.ts';
import { OcapURLManager } from './remotes/OcapURLManager.ts';
import type { RemoteMessageBase } from './remotes/RemoteHandle.ts';
import { RemoteManager } from './remotes/RemoteManager.ts';
import type { RemoteCommsOptions } from './remotes/types.ts';
import { kernelHandlers } from './rpc/index.ts';
Expand Down Expand Up @@ -261,11 +262,14 @@ export class Kernel {
* Send a message to a remote kernel.
*
* @param to - The peer ID of the remote kernel.
* @param message - The message to send.
* @param messageBase - The message to send (without seq/ack).
* @returns a promise for the result of the message send.
*/
async sendRemoteMessage(to: string, message: string): Promise<void> {
await this.#remoteManager.sendRemoteMessage(to, message);
async sendRemoteMessage(
to: string,
messageBase: RemoteMessageBase,
): Promise<void> {
await this.#remoteManager.sendRemoteMessage(to, messageBase);
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/ocap-kernel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type {
StopRemoteComms,
RemoteCommsOptions,
} from './remotes/types.ts';
export type { RemoteMessageBase } from './remotes/RemoteHandle.ts';
export {
isVatId,
VatIdStruct,
Expand Down
Loading
Loading