Skip to content

Commit

Permalink
fix(daemon): fix rpc import problem with daemon command
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinse12 committed Nov 13, 2023
1 parent 0eea29c commit 5cadece
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 54 deletions.
46 changes: 0 additions & 46 deletions src/api/server.ts

This file was deleted.

Empty file removed src/api/types.ts
Empty file.
43 changes: 35 additions & 8 deletions src/cli/commands/daemon.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Flags, Command } from "@oclif/core";
import Logger from "@plebbit/plebbit-logger";
import { ChildProcessWithoutNullStreams } from "child_process";
import { startRpcServer } from "../../api/server.js";
import { seedSubplebbits } from "../../seeder";

import defaults from "../../common-utils/defaults.js";
import { startIpfsNode } from "../../ipfs/startIpfs.js";
import { PlebbitWsServer } from "@plebbit/plebbit-js/dist/node/rpc/src/index";
import lodash from "lodash";
import fetch from "node-fetch";
import path from "path";

export default class Daemon extends Command {
static override description =
Expand Down Expand Up @@ -91,12 +94,36 @@ export default class Daemon extends Command {
await keepIpfsUp();

process.on("exit", () => (mainProcessExited = true) && process.kill(<number>ipfsProcess.pid));
await startRpcServer(
flags.plebbitRpcApiPort,
`http://localhost:${flags.ipfsApiPort}/api/v0`,
`http://localhost:${flags.ipfsGatewayPort}`,
flags.plebbitDataPath,
subsToSeed
);

const ipfsApiEndpoint = `http://localhost:${flags.ipfsApiPort}/api/v0`;
const ipfsGatewayEndpoint = `http://localhost:${flags.ipfsGatewayPort}`;
const rpcServer = await PlebbitWsServer({
port: flags.plebbitRpcApiPort,
plebbitOptions: {
ipfsHttpClientsOptions: [ipfsApiEndpoint],
dataPath: flags.plebbitDataPath
}
});

const handleExit = async (signal: NodeJS.Signals) => {
log(`in handle exit (${signal})`);
await rpcServer.destroy();
process.exit();
};

["SIGINT", "SIGTERM", "SIGHUP", "beforeExit"].forEach((exitSignal) => process.on(exitSignal, handleExit));

console.log(`IPFS API listening on: ${ipfsApiEndpoint}`);
console.log(`IPFS Gateway listening on: ${ipfsGatewayEndpoint}`);
console.log(`Plebbit RPC API listening on: ws://localhost:${flags.plebbitRpcApiPort}`);
console.log(`Plebbit data path: ${path.resolve(<string>rpcServer.plebbit.dataPath)}`);
if (Array.isArray(subsToSeed)) {
const seedSubsLoop = () => {
// I think calling setTimeout constantly here will overflow memory. Need to check later
seedSubplebbits(<string[]>subsToSeed, rpcServer.plebbit).then(() => setTimeout(seedSubsLoop, 600000)); // Seed subs every 10 minutes
};
console.log(`Seeding subplebbits:`, subsToSeed);
seedSubsLoop();
}
}
}

0 comments on commit 5cadece

Please sign in to comment.