refactor(daemon): Split read and write streams
MODIFY
packages/daemon/src/client.js
packages/daemon/src/client.js
// @ts-check
import net from 'net';
-import { makeCapTPWithConnection } from './connection.js';
+import { makeNodeNetstringCapTP } from './connection.js';
/**
* @template TBootstrap
@@ -15,5 +15,5 @@ export const makeEndoClient = async (name, sockPath, bootstrap) => {
conn.on('connect', resolve);
conn.on('error', reject);
});
- return makeCapTPWithConnection(name, conn, bootstrap);
+ return makeNodeNetstringCapTP(name, conn, conn, bootstrap);
};

MODIFY
packages/daemon/src/connection.js
packages/daemon/src/connection.js
@@ -57,16 +57,17 @@ const bytesToMessage = bytes => {
/**
* @template TBootstrap
* @param {string} name
- * @param {import('net').Socket} conn
+ * @param {import('stream').Writable} nodeWriter
+ * @param {import('stream').Readable} nodeReader
* @param {TBootstrap} bootstrap
*/
-export const makeCapTPWithConnection = (name, conn, bootstrap) => {
+export const makeNodeNetstringCapTP = (name, nodeWriter, nodeReader, bootstrap) => {
const writer = mapWriter(
- makeNetstringWriter(makeNodeWriter(conn)),
+ makeNetstringWriter(makeNodeWriter(nodeWriter)),
messageToBytes,
);
const reader = mapReader(
- makeNetstringReader(makeNodeReader(conn)),
+ makeNetstringReader(makeNodeReader(nodeReader)),
bytesToMessage,
);
return makeCapTPWithStreams(name, writer, reader, bootstrap);

MODIFY
packages/daemon/src/daemon.js
packages/daemon/src/daemon.js
@@ -12,8 +12,7 @@ import net from 'net';
import fs from 'fs';
import { Far } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
-
-import { makeCapTPWithConnection } from './connection.js';
+import { makeNodeNetstringCapTP } from './connection.js';
const { quote: q } = assert;
@@ -88,7 +87,7 @@ export const main = async () => {
process.exit(-1);
});
server.on('connection', conn => {
- const { drained } = makeCapTPWithConnection('Endo', conn, endoFacets);
+ const { drained } = makeNodeNetstringCapTP('Endo', conn, conn, endoFacets);
drained.catch(sinkError);
});

refactor(daemon): Split read and write streams