From 1f592498b57ab7776b0068d333d60a57145185e1 Mon Sep 17 00:00:00 2001 From: saul Date: Thu, 11 Apr 2024 13:53:23 +1200 Subject: [PATCH] Update daemon to use new rpc package. --- package-lock.json | 16 +- packages/daemon/package.json | 2 +- packages/daemon/src/common/index.ts | 2 +- packages/daemon/src/common/interface.ts | 2 +- packages/daemon/src/common/rpc-server.ts | 146 ------------------ .../daemon/test/modules/downloader.spec.ts | 14 +- .../daemon/test/modules/filesystem.spec.ts | 42 ++--- packages/daemon/test/modules/groups.spec.ts | 26 ++-- packages/daemon/test/modules/network.spec.ts | 20 +-- .../daemon/test/modules/revisions.spec.ts | 14 +- packages/daemon/test/modules/rpc.spec.ts | 6 +- packages/daemon/tsconfig.json | 3 + 12 files changed, 68 insertions(+), 225 deletions(-) delete mode 100644 packages/daemon/src/common/rpc-server.ts diff --git a/package-lock.json b/package-lock.json index f6289024..0e3df1e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30737,9 +30737,9 @@ "@organicdesign/db-helia-pin-manager": "^0.1.0", "@organicdesign/db-key-manager": "^0.1.0", "@organicdesign/db-manual-block-broker": "^0.1.0", + "@organicdesign/db-rpc": "^0.1.0", "@organicdesign/db-rpc-interfaces": "^0.1.0", "@organicdesign/db-utils": "^0.1.0", - "@organicdesign/net-rpc": "^0.2.1", "any-signal": "^4.1.1", "blockstore-core": "^4.4.0", "blockstore-fs": "^1.1.10", @@ -30794,20 +30794,6 @@ "npm": ">=8.7.0" } }, - "packages/daemon/node_modules/@organicdesign/net-rpc": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/@organicdesign/net-rpc/-/net-rpc-0.2.1.tgz", - "integrity": "sha512-ztH6S/QP1iYDJdR0E4xcftYlmE9M5YrPVkDX5RwI+3mMrZ3vybxXsETTYov3CH+b97Mdwmvo8hAiTiSwQCK/RQ==", - "dependencies": { - "it-length-prefixed": "^9.0.4", - "it-pipe": "^3.0.1", - "it-pushable": "^3.2.3", - "json-rpc-2.0": "^1.7.0", - "streaming-iterables": "^8.0.1", - "ts-event-target": "^0.1.5", - "uint8arrays": "^5.0.3" - } - }, "packages/dag-walkers": { "name": "@organicdesign/db-dag-walkers", "version": "0.1.0", diff --git a/packages/daemon/package.json b/packages/daemon/package.json index 931dd9cd..cd4e447a 100644 --- a/packages/daemon/package.json +++ b/packages/daemon/package.json @@ -59,9 +59,9 @@ "@organicdesign/db-helia-pin-manager": "^0.1.0", "@organicdesign/db-key-manager": "^0.1.0", "@organicdesign/db-manual-block-broker": "^0.1.0", + "@organicdesign/db-rpc": "^0.1.0", "@organicdesign/db-rpc-interfaces": "^0.1.0", "@organicdesign/db-utils": "^0.1.0", - "@organicdesign/net-rpc": "^0.2.1", "any-signal": "^4.1.1", "blockstore-core": "^4.4.0", "blockstore-fs": "^1.1.10", diff --git a/packages/daemon/src/common/index.ts b/packages/daemon/src/common/index.ts index 90e12613..1489b0f0 100644 --- a/packages/daemon/src/common/index.ts +++ b/packages/daemon/src/common/index.ts @@ -4,6 +4,7 @@ import { unixfs as createUnixfs } from '@helia/unixfs' import { PinManager as HeliaPinManager } from '@organicdesign/db-helia-pin-manager' import { createKeyManager, type KeyManager } from '@organicdesign/db-key-manager' import { ManualBlockBroker } from '@organicdesign/db-manual-block-broker' +import { createRPCServer } from '@organicdesign/db-rpc' import { extendDatastore } from '@organicdesign/db-utils' import { MemoryBlockstore } from 'blockstore-core' import { FsBlockstore } from 'blockstore-fs' @@ -21,7 +22,6 @@ import handleEvents from './handle-events.js' import { Config, MEMORY_MAGIC, type Components } from './interface.js' import createLibp2p from './libp2p.js' import { PinManager } from './pin-manager/index.js' -import { createRPCServer } from './rpc-server.js' import { Sneakernet } from './sneakernet/index.js' import { createTick } from './tick.js' import type { KeyvalueDB } from '@/interface.js' diff --git a/packages/daemon/src/common/interface.ts b/packages/daemon/src/common/interface.ts index fc545f36..e3008697 100644 --- a/packages/daemon/src/common/interface.ts +++ b/packages/daemon/src/common/interface.ts @@ -4,7 +4,6 @@ import type { Downloader } from './downloader/index.js' import type { EntryTracker } from './entry-tracker.js' import type { Groups } from './groups.js' import type { PinManager } from './pin-manager/index.js' -import type { RPCServer } from './rpc-server.js' import type { Sneakernet } from './sneakernet/index.js' import type { Tick } from './tick.js' import type { KeyvalueDB } from '@/interface.js' @@ -13,6 +12,7 @@ import type { UnixFS } from '@helia/unixfs' import type { Libp2p } from '@libp2p/interface' import type { PinManager as HeliaPinManager } from '@organicdesign/db-helia-pin-manager' import type { KeyManager } from '@organicdesign/db-key-manager' +import type { RPCServer } from '@organicdesign/db-rpc' import type { Blockstore } from 'interface-blockstore' import type { Datastore } from 'interface-datastore' import type { Welo } from 'welo' diff --git a/packages/daemon/src/common/rpc-server.ts b/packages/daemon/src/common/rpc-server.ts deleted file mode 100644 index 9015420c..00000000 --- a/packages/daemon/src/common/rpc-server.ts +++ /dev/null @@ -1,146 +0,0 @@ -import * as net from 'net' -import * as cborg from 'cborg' -import * as lp from 'it-length-prefixed' -import { pipe } from 'it-pipe' -import { type Pushable, pushable } from 'it-pushable' -import { JSONRPCServer, type JSONRPCResponse, type JSONRPCRequest } from 'json-rpc-2.0' -import { map, writeToStream } from 'streaming-iterables' -import { Event, EventTarget } from 'ts-event-target' -import { z } from 'zod' -import type { AbortOptions } from 'interface-store' -import type { Socket } from 'net' -import type { Uint8ArrayList } from 'uint8arraylist' - -export class RPCEvent extends Event<'error'> { - readonly code: string - - constructor (code?: string) { - super('error') - - this.code = code ?? 'UNKNOWN_ERROR' - } -} - -export const createEventTarget = (): EventTarget<[RPCEvent]> => new EventTarget<[RPCEvent]>() - -interface Client { - socket: Socket - stream: Pushable - controllers: Map -} - -export class RPCServer { - readonly events = createEventTarget() - readonly rpc = new JSONRPCServer() - private readonly path: string - private readonly clients = new Map() - private readonly server = net.createServer(socket => { this.handleClient(socket) }) - private readonly genId: () => number - - constructor (path: string) { - this.path = path - - this.genId = ((): () => number => { - let id = 0 - - return () => id++ % 65536 - })() - } - - async start (): Promise { - await new Promise(resolve => this.server.listen(this.path, resolve)) - - this.rpc.addMethod('rpc-abort', (raw, { id }) => { - const params = z.object({ id: z.number() }).parse(raw) - const client = this.clients.get(id) - const controller = client?.controllers.get(params.id) - - controller?.abort() - }) - } - - async stop (): Promise { - await new Promise((resolve, reject) => { - this.server.close(error => { (error != null) ? reject(error) : resolve() }) - - for (const [id, { stream, socket }] of this.clients.entries()) { - stream.end() - socket.destroy() - this.clients.delete(id) - } - }) - } - - private handleClient (socket: Socket): void { - const id = this.genId() - const stream = pushable({ objectMode: true }) - const controllers = new Map() - - this.clients.set(id, { socket, stream, controllers }) - - // Send responses to the client - pipe( - stream, - map(i => cborg.encode(i)), - lp.encode, - writeToStream(socket) - ).catch(error => { - const code = (error as Record | null)?.code - - this.events.dispatchEvent(new RPCEvent(code)) - - socket.destroy(error) - stream.end(error) - }) - - ;(async () => { - const itr = pipe( - socket as AsyncIterable, - i => lp.decode(i), - map((value: Uint8Array | Uint8ArrayList) => value.subarray()), - map((i: Uint8Array) => cborg.decode(i) as JSONRPCRequest) - ) - - const promises: Array> = [] - - for await (const data of itr) { - if (data.id != null) { - controllers.set(data.id, new AbortController()) - } - - const signal = data.id == null ? undefined : controllers.get(data.id)?.signal - - promises.push(this.rpc.receive(data, { id, signal }).then(response => { - if (data.id != null) { - controllers.delete(data.id) - } - - if (response != null) { - stream.push(response) - } - })) - } - - await Promise.all(promises) - })().catch(error => { - // Ignore errors because we will close immediately after. - const code = (error as Record | null)?.code - - this.events.dispatchEvent(new RPCEvent(code)) - }).finally(() => { - // Socket was closed - stream.end() - socket.destroy() - - this.clients.delete(id) - }) - } -} - -export const createRPCServer = async (path: string): Promise => { - const rpcServer = new RPCServer(path) - - await rpcServer.start() - - return rpcServer -} diff --git a/packages/daemon/test/modules/downloader.spec.ts b/packages/daemon/test/modules/downloader.spec.ts index d96a5f6d..9ea14920 100644 --- a/packages/daemon/test/modules/downloader.spec.ts +++ b/packages/daemon/test/modules/downloader.spec.ts @@ -1,8 +1,8 @@ import assert from 'assert/strict' import fs from 'fs/promises' import Path from 'path' +import { createRPCClient } from '@organicdesign/db-rpc' import { createDag } from '@organicdesign/db-test-utils' -import { createNetClient } from '@organicdesign/net-rpc' import { MemoryBlockstore } from 'blockstore-core' import { CID } from 'multiformats/cid' import { mkTestPath } from '../utils/paths.js' @@ -32,7 +32,7 @@ describe('downloader', () => { const path = '/test.txt' const priority = 50 const { components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const key = Path.join('/', group, path) await components.pinManager.put(key, { priority: 1, cid: CID.parse(group) }) @@ -46,7 +46,7 @@ describe('downloader', () => { assert(pinData != null) assert.equal(pinData.priority, priority) - client.close() + client.stop() await components.stop() }) @@ -57,7 +57,7 @@ describe('downloader', () => { const group = 'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN' const path = '/test.txt' const age = 500 - const client = createNetClient(socket) + const client = createRPCClient(socket) const key = Path.join('/', group, path) await components.pinManager.put(key, { priority: 1, cid: dag[0] }) @@ -108,7 +108,7 @@ describe('downloader', () => { assert.equal(state3[0].size, values.reduce((a, c) => c.length + a, 0)) assert.equal(state3[0].blocks, values.length) - client.close() + client.stop() await components.stop() }) @@ -118,7 +118,7 @@ describe('downloader', () => { const dag = await createDag({ blockstore }, 2, 2) const group = 'QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN' const path = '/test.txt' - const client = createNetClient(socket) + const client = createRPCClient(socket) const key = Path.join('/', group, path) const status1 = await client.rpc.request('get-state', { @@ -182,7 +182,7 @@ describe('downloader', () => { status: 'COMPLETED' }]) - client.close() + client.stop() await components.stop() }) }) diff --git a/packages/daemon/test/modules/filesystem.spec.ts b/packages/daemon/test/modules/filesystem.spec.ts index 2814c161..f4959f74 100644 --- a/packages/daemon/test/modules/filesystem.spec.ts +++ b/packages/daemon/test/modules/filesystem.spec.ts @@ -2,10 +2,10 @@ import assert from 'assert/strict' import fs from 'fs/promises' import Path from 'path' import { unixfs } from '@helia/unixfs' +import { createRPCClient } from '@organicdesign/db-rpc' import { createDag } from '@organicdesign/db-test-utils' import * as testData from '@organicdesign/db-test-utils/data' import { importer } from '@organicdesign/db-utils/portation' -import { createNetClient } from '@organicdesign/net-rpc' import { MemoryBlockstore } from 'blockstore-core' import all from 'it-all' import { CID } from 'multiformats/cid' @@ -159,7 +159,7 @@ describe('filesystem', () => { it('rpc - delete (file)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const dag = await createDag(components.helia, 2, 2) @@ -182,13 +182,13 @@ describe('filesystem', () => { assert.equal(entry, null) - client.close() + client.stop() await components.stop() }) it('rpc - delete (directory)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const dag = await createDag(components.helia, 2, 2) @@ -214,13 +214,13 @@ describe('filesystem', () => { assert.deepEqual(entries, []) - client.close() + client.stop() await components.stop() }) it('rpc - edit priority', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const path = '/test' @@ -236,13 +236,13 @@ describe('filesystem', () => { assert.equal(localSettings.priority, priority) - client.close() + client.stop() await components.stop() }) it('rpc - export (file)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' @@ -276,13 +276,13 @@ describe('filesystem', () => { assert.equal(valid, true) } - client.close() + client.stop() await components.stop() }) it('rpc - export (directory)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' @@ -316,13 +316,13 @@ describe('filesystem', () => { assert.equal(valid, true) } - client.close() + client.stop() await components.stop() }) it('rpc - import (file)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' @@ -350,13 +350,13 @@ describe('filesystem', () => { assert.deepEqual(result.cid, data.cid) })) - client.close() + client.stop() await components.stop() }) it('rpc - import (directory)', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' @@ -393,13 +393,13 @@ describe('filesystem', () => { assert.deepEqual(r.value.cid, dataFile.cid) } - client.close() + client.stop() await components.stop() }) it('rpc - list', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const dag = await createDag(components.helia, 2, 2) @@ -439,13 +439,13 @@ describe('filesystem', () => { assert(entry.timestamp <= Date.now()) } - client.close() + client.stop() await components.stop() }) it('rpc - read', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const ufs = unixfs(components.helia) const path = '/test' @@ -476,13 +476,13 @@ describe('filesystem', () => { assert.deepEqual(read4, data.slice(1, 3 + 1)) - client.close() + client.stop() await components.stop() }) it('rpc - write', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const ufs = unixfs({ blockstore: new MemoryBlockstore() }) @@ -550,7 +550,7 @@ describe('filesystem', () => { assert.deepEqual(value4, uint8ArrayFromString('test-long-long')) - client.close() + client.stop() await components.stop() }) }) diff --git a/packages/daemon/test/modules/groups.spec.ts b/packages/daemon/test/modules/groups.spec.ts index f73ef728..365f3817 100644 --- a/packages/daemon/test/modules/groups.spec.ts +++ b/packages/daemon/test/modules/groups.spec.ts @@ -1,7 +1,7 @@ import assert from 'assert/strict' import fs from 'fs/promises' import Path from 'path' -import { createNetClient } from '@organicdesign/net-rpc' +import { createRPCClient } from '@organicdesign/db-rpc' import * as cborg from 'cborg' import all from 'it-all' import { CID } from 'multiformats/cid' @@ -164,19 +164,19 @@ describe('groups', () => { it('rpc - id returns the base58btc formatted welo id', async () => { const { components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const id = await client.rpc.request('id', {}) assert.equal(uint8ArrayToString(components.welo.identity.id, 'base58btc'), id) - client.close() + client.stop() await components.stop() }) it('rpc - create groups creates a group without other peers', async () => { const { components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const name = 'test' const cid = await client.rpc.request('create-group', { name, peers: [] }) @@ -187,13 +187,13 @@ describe('groups', () => { assert.equal(database.manifest.name, name) assert.deepEqual(database.manifest.access.config?.write, [components.welo.identity.id]) - client.close() + client.stop() await components.stop() }) it('rpc - create groups creates a group with other peers', async () => { const { components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const name = 'test' const otherPeer = 'GZsJqUjmbVqZCUMbJoe5ye4xfdKZVPVwBoFFQiyCZYesq6Us5b' @@ -208,13 +208,13 @@ describe('groups', () => { uint8ArrayFromString(otherPeer, 'base58btc') ]) - client.close() + client.stop() await components.stop() }) it('rpc - joins an external group', async () => { const components = await Promise.all([create(), create()]) - const client = createNetClient(components[0].socket) + const client = createRPCClient(components[0].socket) const name = 'test' const group = await createGroup(components[1].components, name) @@ -228,13 +228,13 @@ describe('groups', () => { assert(database) assert.equal(database.manifest.name, name) - client.close() + client.stop() await Promise.all(components.map(async c => c.components.stop())) }) it('rpc - list groups', async () => { const { components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const name = 'test' let groups = await client.rpc.request('list-groups', {}) @@ -247,14 +247,14 @@ describe('groups', () => { assert.deepEqual(groups, [{ group: group.toString(), name }]) - client.close() + client.stop() await components.stop() }) // This fails it github too - seems to think the `server-sync-groups` socket is in use? it.skip('rpc - sync groups', async () => { const components = await Promise.all([create(), create()]) - const client = createNetClient(components[0].socket) + const client = createRPCClient(components[0].socket) const key = '/test' const value = 'test-value' @@ -282,7 +282,7 @@ describe('groups', () => { assert.deepEqual(result, value) - client.close() + client.stop() await Promise.all(components.map(async c => c.components.stop())) }) }) diff --git a/packages/daemon/test/modules/network.spec.ts b/packages/daemon/test/modules/network.spec.ts index 330b6c57..ac924731 100644 --- a/packages/daemon/test/modules/network.spec.ts +++ b/packages/daemon/test/modules/network.spec.ts @@ -3,7 +3,7 @@ import fs from 'fs/promises' import Path from 'path' import { unixfs } from '@helia/unixfs' import { createKeyManager } from '@organicdesign/db-key-manager' -import { createNetClient } from '@organicdesign/net-rpc' +import { createRPCClient } from '@organicdesign/db-rpc' import { createHelia } from 'helia' import { Key } from 'interface-datastore' import all from 'it-all' @@ -208,19 +208,19 @@ describe('network', () => { it('rpc - addresses returns the peers addresses', async () => { const components = await setup({ socket, config: { private: false } }) - const client = createNetClient(socket) + const client = createRPCClient(socket) const addresses = await client.rpc.request('addresses', {}) assert.deepEqual(addresses, components.libp2p.getMultiaddrs().map(a => a.toString())) - client.close() + client.stop() await components.stop() }) it('rpc - connections returns the peers connections', async () => { const libp2p = await createLibp2p({}) const components = await setup({ socket, config: { private: false } }) - const client = createNetClient(socket) + const client = createRPCClient(socket) assert.deepEqual(await client.rpc.request('connections', {}), []) @@ -236,16 +236,16 @@ describe('network', () => { ) await libp2p.stop() - client.close() + client.stop() await components.stop() }) it('rpc - connection connects to another peer', async () => { const libp2p = await createLibp2p({}) const components = await setup({ socket, config: { private: false } }) - const client = createNetClient(socket) + const client = createRPCClient(socket) - await client.rpc.request('connect', { address: libp2p.getMultiaddrs()[0] }) + await client.rpc.request('connect', { address: libp2p.getMultiaddrs()[0].toString() }) const connections = components.libp2p.getConnections() @@ -254,7 +254,7 @@ describe('network', () => { await libp2p.stop() await components.stop() - client.close() + client.stop() }) // This should pass but sometimes github workflows can be a bit flakey in terms of peer discovery. @@ -264,7 +264,7 @@ describe('network', () => { const helia = await createHelia({ libp2p }) const ufs = unixfs(helia) const components = await setup({ socket, config: { private: false } }) - const client = createNetClient(socket) + const client = createRPCClient(socket) await components.libp2p.dial(helia.libp2p.getMultiaddrs()) @@ -278,6 +278,6 @@ describe('network', () => { await helia.stop() await libp2p.stop() await components.stop() - client.close() + client.stop() }) }) diff --git a/packages/daemon/test/modules/revisions.spec.ts b/packages/daemon/test/modules/revisions.spec.ts index 873239a3..78f5c1af 100644 --- a/packages/daemon/test/modules/revisions.spec.ts +++ b/packages/daemon/test/modules/revisions.spec.ts @@ -2,10 +2,10 @@ import assert from 'assert' import fs from 'fs/promises' import Path from 'path' import { unixfs } from '@helia/unixfs' +import { createRPCClient } from '@organicdesign/db-rpc' import { createDag } from '@organicdesign/db-test-utils' import * as testData from '@organicdesign/db-test-utils/data' import { importer } from '@organicdesign/db-utils/portation' -import { createNetClient } from '@organicdesign/net-rpc' import all from 'it-all' import { CID } from 'multiformats/cid' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' @@ -120,7 +120,7 @@ describe('revisions', () => { const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const path = '/test' - const client = createNetClient(socket) + const client = createRPCClient(socket) const sequence = 0 const dataFile = testData.files[0] const exportPath = dataFile.generatePath(testPath) @@ -168,7 +168,7 @@ describe('revisions', () => { const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' - const client = createNetClient(socket) + const client = createRPCClient(socket) const sequence = 0 const outPath = Path.join(testPath, 'export-directory') @@ -222,7 +222,7 @@ describe('revisions', () => { const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const path = '/test' - const client = createNetClient(socket) + const client = createRPCClient(socket) const dataFile = testData.files[0] assert(fs != null) @@ -274,7 +274,7 @@ describe('revisions', () => { const group = await createGroup(components, 'test') const fs = filesystem.getFileSystem(group) const rootPath = '/test' - const client = createNetClient(socket) + const client = createRPCClient(socket) assert(fs != null) @@ -335,7 +335,7 @@ describe('revisions', () => { it('rpc - read revision', async () => { const { filesystem, components, socket } = await create() - const client = createNetClient(socket) + const client = createRPCClient(socket) const group = await createGroup(components, 'test') const ufs = unixfs(components.helia) const path = '/test' @@ -383,7 +383,7 @@ describe('revisions', () => { assert.deepEqual(read4, data.slice(1, 3 + 1)) - client.close() + client.stop() await components.stop() }) }) diff --git a/packages/daemon/test/modules/rpc.spec.ts b/packages/daemon/test/modules/rpc.spec.ts index fffcbf57..1ed70122 100644 --- a/packages/daemon/test/modules/rpc.spec.ts +++ b/packages/daemon/test/modules/rpc.spec.ts @@ -1,7 +1,7 @@ import assert from 'assert/strict' import fs from 'fs/promises' import Path from 'path' -import { createNetClient } from '@organicdesign/net-rpc' +import { createRPCClient } from '@organicdesign/db-rpc' import { mkTestPath } from '../utils/paths.js' import setup from '@/common/index.js' @@ -23,7 +23,7 @@ describe('rpc', () => { const testData = { key: 'value' } const returnData = { return: 'return-value' } - const client = createNetClient(socket) + const client = createRPCClient(socket) const methodPromise = new Promise((resolve, reject) => { setTimeout(() => { reject(new Error()) }, 50) @@ -39,7 +39,7 @@ describe('rpc', () => { assert.deepEqual(returnResult, returnData) assert.deepEqual(await methodPromise, testData) - client.close() + client.stop() await components.stop() }) }) diff --git a/packages/daemon/tsconfig.json b/packages/daemon/tsconfig.json index f3691caf..38fd2c3f 100644 --- a/packages/daemon/tsconfig.json +++ b/packages/daemon/tsconfig.json @@ -29,6 +29,9 @@ { "path": "../rpc-interfaces" }, + { + "path": "../rpc" + }, { "path": "../manual-block-broker" },