Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import fs from 'fs-extra'
import named from 'named-regexp'
import S from 'string'
import util from 'util'
import got from 'got'
import request from 'request'
import rp from 'request-promise'
import FormData from 'form-data'
import crypto from 'crypto'
import through2 from 'through2'
import shelljs from 'shelljs'
Promise.promisifyAll(fs)
import ipc from 'node-ipc'
const ipcDaemon = new ipc.IPC()
// process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"
//
// let options = {
// method: "POST",
// url: "https://localhost:8443/engine/job/1468042466879",
// form: {
// action: "launch"
// },
// auth: {
// username: "lorem",
// password: "ipsum",
// sendImmediately: false
// },
// rejectUnauthorized: false,
// resolveWithFullResponse: true,
module.exports = fp((fastify, options, next) => {
fastify.decorate('cache', new DacCache());
const ipc = new IPC();
ipc.config.appspace = 'eosdac.';
ipc.connectTo('eosdacprocessor', () => {
ipc.of.eosdacprocessor.on('action', async (a) => {
// console.log(dac_directory.msig_accounts());
if (a.action && a.action.name === 'stprofile'){
// invalidate profile cache
let cache_name = `/v1/eosdac/profile?account=${a.action.data.cand}`;
fastify.cache.set(a.action.data.dac_id, cache_name);
}
else if (a.action && a.action.account === 'dacmultisigs' && a.action.data.dac_id){
fastify.cache.removePrefix(a.action.data.dac_id, `/v1/eosdac/msig_proposals`);
}
});
});
}
});
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
});
const sub = new IPC();
sub.config.silent = true;
sub.config.maxRetries = 1;
sub.connectTo('crosscode-map-editor', () => {
sub.of['crosscode-map-editor'].on('connect', () => {
sub.disconnect('crosscode-map-editor');
app.quit();
});
sub.of['crosscode-map-editor'].on('error', () => {
sub.disconnect('crosscode-map-editor');
const master = new IPC();
master.config.silent = true;
master.config.id = 'crosscode-map-editor'
master.serve(() => {
master.server.on('connect', () => openWindow());
});
async start() {
await this.connectAmq();
await this.connectDb();
this.delta_handler = new DeltaHandler({config: this.config, queue: this.amq});
this.dac_directory = new DacDirectory({config: this.config, db:this.db});
await this.dac_directory.reload();
if (cluster.isMaster) {
this.logger.info(`Starting processor with ${this.config.clusterSize} threads...`);
// start ipc server that clients can subscribe to for api cache updates
this.ipc = new IPC();
this.ipc.config.appspace = 'eosdac.';
this.ipc.config.id = 'eosdacprocessor';
this.ipc.serve(() => {
this.logger.info(`Started IPC`);
});
this.ipc.server.start();
for (let i = 0; i < this.config.clusterSize; i++) {
const worker = cluster.fork();
worker.on('message', this.worker_message.bind(this));
}
} else {
this.amq.listen('contract_row', this.processContractRow.bind(this));
// amq.listen('generated_transaction', self.processTransactionRow.bind(self));
this.amq.listen('action', this.processActionJob.bind(this));
constructor (config, { dialogHandler, contextMenuHandler, windowHandler }) {
this.id = config.clientId;
this.serverId = config.serverId;
this.ipc = new IPC();
this.client = null;
this.dialogHandler = dialogHandler;
this.contextMenuHandler = contextMenuHandler;
this.windowHandler = windowHandler;
}
constructor (config) {
this.id = config.serverId;
this.ipc = new IPC();
this.server = null;
this.socket = null;
this.socketPromise = null;
this.injectingStatus = null;
this.injectingStatusPromise = null;
}
const startIPCServer = () => {
const ipc = new IPC();
ipc.config.appspace = 'eosdac.';
ipc.config.id = 'livenotifications';
ipc.serve(() => {
console.log(`Started IPC Server`);
ipc.server.on('notification', receiveIPCMessage(ipc, 'notification'));
});
ipc.server.start();
};
sub.of['crosscode-map-editor'].on('error', () => {
sub.disconnect('crosscode-map-editor');
const master = new IPC();
master.config.silent = true;
master.config.id = 'crosscode-map-editor'
master.serve(() => {
master.server.on('connect', () => openWindow());
});
master.server.start();
});
});
function createKernel(id, host = os.hostname(), port = 7022, opts = {}) {
opts = _.defaultsDeep(utils.isPlainObject(opts) ? _.cloneDeep(opts) : {}, consts.kernelOpts);
var inst = new ipc.IPC();
inst.config.networkHost = host || opts.networkHost;
inst.config.networkPort = port || opts.networkPort;
inst.config.retry = opts.retry;
inst.config.maxRetries = opts.maxRetries;
inst.config.tls = opts.tls;
inst.config.silent = opts.silent;
return new lib.kernel(inst, id, inst.config.networkHost, inst.config.networkPort);
}
constructor(options: ConstructorOptions) {
this.serverID = makeUniqServerId();
this.isAlive = false;
this._ipc = new IPC();
this._spawn = options.spawnNode
? makeSpawnNodeFn(this.serverID, options.spawnNode)
: options.spawn;
this.remote = this.initializeRemote();
this._pendingRequests = {};
}