Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(daemon): Various bug fixes #1835

Merged
merged 3 commits into from
Oct 18, 2023
Merged
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
27 changes: 18 additions & 9 deletions packages/daemon/src/daemon-node-powers.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,22 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {Promise<never>} args.cancelled
*/
const servePath = async ({ path, cancelled }) =>
serveListener(
server =>
new Promise(resolve =>
server.listen({ path }, () => resolve(undefined)),
),
cancelled,
);
serveListener(server => {
return new Promise((resolve, reject) =>
server.listen({ path }, error => {
if (error) {
if (path.length >= 104) {
console.warn(
`Warning: Length of path for domain socket or named path exceeeds common maximum (104, possibly 108) for some platforms (length: ${path.length}, path: ${path})`,
);
}
reject(error);
} else {
resolve(undefined);
}
}),
);
}, cancelled);

const connectionNumbers = (function* generateNumbers() {
let n = 0;
Expand All @@ -265,7 +274,7 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {string} sockPath
* @param {Promise<never>} cancelled
* @param {(error: Error) => void} exitWithError
* @returns {{ started: () => Promise<void>, stopped: Promise<void> }}
* @returns {{ started: Promise<void>, stopped: Promise<void> }}
*/
const makePrivatePathService = (
endoBootstrap,
Expand All @@ -288,7 +297,7 @@ export const makeNetworkPowers = ({ http, ws, net }) => {
* @param {(port: Promise<number>) => void} assignWebletPort
* @param {Promise<never>} cancelled
* @param {(error: Error) => void} exitWithError
* @returns {{ started: () => Promise<void>, stopped: Promise<void> }}
* @returns {{ started: Promise<void>, stopped: Promise<void> }}
*/
const makePrivateHttpService = (
endoBootstrap,
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ const makeEndoBootstrap = (
formula,
);

// Memoize provide.
// Memoize for lookup.
valuePromiseForFormulaIdentifier.set(formulaIdentifier, promiseForValue);

// Prepare an entry for reverse-lookup of formula for presence.
Expand Down
8 changes: 4 additions & 4 deletions packages/daemon/src/serve-private-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export const servePrivatePath = (
) => {
const connectionsP = servePath({ path: sockPath, cancelled });

const started = async () => {
const started = (async () => {
await connectionsP;
// Resolve a promise in the Endo CLI through the IPC channel:
console.log(
`Endo daemon listening for CapTP on ${q(
`Endo daemon listening for private CapTP on ${q(
sockPath,
)} ${new Date().toISOString()}`,
);
};
})();

const stopped = (async () => {
/** @type {Set<Promise<void>>} */
Expand All @@ -33,7 +33,7 @@ export const servePrivatePath = (
closed: connectionClosed,
} of connections) {
(async () => {
const connectionNumber = connectionNumbers.next();
const { value: connectionNumber } = connectionNumbers.next();
console.log(
`Endo daemon received domain connection ${connectionNumber} at ${new Date().toISOString()}`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/serve-private-port-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const servePrivatePortHttp = (
closed: connectionClosed,
} = connection;

const connectionNumber = connectionNumbers.next();
const { value: connectionNumber } = connectionNumbers.next();
console.log(
`Endo daemon received local web socket connection ${connectionNumber} at ${new Date().toISOString()}`,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ export type NetworkPowers = {
sockPath: string,
cancelled: Promise<never>,
exitWithError: (error: Error) => void,
) => { started: () => Promise<void>; stopped: Promise<void> };
) => { started: Promise<void>; stopped: Promise<void> };
makePrivateHttpService: (
endoBootstrap: FarRef<unknown>,
port: number,
assignWebletPort: (portP: Promise<number>) => void,
cancelled: Promise<never>,
exitWithError: (error: Error) => void,
) => { started: () => Promise<void>; stopped: Promise<void> };
) => { started: Promise<void>; stopped: Promise<void> };
};

// The return type here is almost an EndoReadable, but not quite. Should fix.
Expand Down