Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
wip: adding polykey nodes join command
[ci skip]
  • Loading branch information
aryanjassal committed Jul 22, 2025
commit 11a4b18410100e902dc34474595f4d63c3dec113
64 changes: 64 additions & 0 deletions src/nodes/CommandJoin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type PolykeyClient from 'polykey/PolykeyClient.js';
import CommandPolykey from '../CommandPolykey.js';
import * as binUtils from '../utils/index.js';
import * as binOptions from '../utils/options.js';
import * as binProcessors from '../utils/processors.js';
import * as errors from '../errors.js';

class CommandJoin extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('join');
this.description('Join a network');
this.argument('<network>', 'Name of the network to join');
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (network: string, options) => {
const { default: PolykeyClient } = await import(
'polykey/PolykeyClient.js'
);
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
options.clientHost,
options.clientPort,
this.fs,
this.logger.getChild(binProcessors.processClientOptions.name),
);
const auth = await binProcessors.processAuthentication(
options.passwordFile,
this.fs,
);

let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
});
try {
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.nodesSyncGraph({
network,
metadata: auth,
}),
auth,
);
process.stdout.write(`Switched to network ${network}`);
} finally {
if (pkClient! != null) await pkClient.stop();
}
});
}
}

export default CommandJoin;
2 changes: 2 additions & 0 deletions src/nodes/CommandNodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CommandAdd from './CommandAdd.js';
import CommandClaim from './CommandClaim.js';
import CommandFind from './CommandFind.js';
import CommandJoin from './CommandJoin.js';
import CommandPing from './CommandPing.js';
import CommandGetAll from './CommandGetAll.js';
import CommandConnections from './CommandConnections.js';
Expand All @@ -14,6 +15,7 @@ class CommandNodes extends CommandPolykey {
this.addCommand(new CommandAdd(...args));
this.addCommand(new CommandClaim(...args));
this.addCommand(new CommandFind(...args));
this.addCommand(new CommandJoin(...args));
this.addCommand(new CommandPing(...args));
this.addCommand(new CommandGetAll(...args));
this.addCommand(new CommandConnections(...args));
Expand Down