Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
serverBase.run = function (options) {
const logger = flaschenpost.getLogger();
const certificate = fs.readFileSync(path.join(__dirname, '..', '..', 'keys', 'localhost.selfsigned', 'certificate.pem')),
privateKey = fs.readFileSync(path.join(__dirname, '..', '..', 'keys', 'localhost.selfsigned', 'privateKey.pem'));
/* eslint-disable no-process-env */
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
/* eslint-enable no-process-env */
const peer = p2p.peer({
host: 'localhost',
port: options.p2p.port,
privateKey,
certificate,
metadata: {
host: 'localhost',
port: options.http.port
'use strict';
const http = require('http'),
https = require('https');
const _ = require('lodash'),
flaschenpost = require('flaschenpost'),
parse = require('parse-duration'),
Timer = require('timer2');
const Peer = require('./Peer');
const logger = flaschenpost.getLogger();
const p2p = {};
p2p.peer = function (options) {
if (!options) {
throw new Error('Options are missing.');
}
if (!options.privateKey && options.certificate) {
throw new Error('Private key is missing.');
}
if (options.privateKey && !options.certificate) {
throw new Error('Certificate is missing.');
}
const useHttps = !!options.privateKey && !!options.certificate;
'use strict';
var url = require('url');
var flaschenpost = require('flaschenpost'),
request = require('request');
var errors = require('./errors');
var logger = flaschenpost.getLogger();
var remote = function (host, port) {
if (!host) {
throw new Error('Host is missing.');
}
if (!port) {
throw new Error('Port is missing.');
}
return {
run: function (fn, args, callback) {
var target;
if (!fn) {
throw new Error('Function is missing.');
}
'use strict';
const path = require('path');
const async = require('async'),
flaschenpost = require('flaschenpost'),
requireAll = require('require-all');
const createPeer = require('./createPeer');
const env = requireAll(path.join(__dirname, 'env')),
logger = flaschenpost.getLogger();
const createPeers = function (options, callback) {
logger.info('Creating peers...', { count: options.count });
async.timesSeries(options.count, (n, next) => {
createPeer(options, next);
}, (err, peers) => {
if (err) {
return callback(err);
}
callback(null, peers, env);
});
};
module.exports = createPeers;
'use strict';
const async = require('async'),
flaschenpost = require('flaschenpost');
const logger = flaschenpost.getLogger();
const formRing = function (peers, callback) {
logger.info('Forming ring...');
async.each(peers, (peer, done) => {
peer.join(peers[0], done);
}, callback);
};
module.exports = formRing;
'use strict';
const async = require('async'),
cmp = require('comparejs'),
flaschenpost = require('flaschenpost'),
parse = require('parse-duration');
const logger = flaschenpost.getLogger();
const waitUntil = function (peers, options) {
return {
have: fn => {
return {
equalTo: (expected, callback) => {
logger.info('Waiting for peers to fulfill predicate...', { expected });
async.each(peers, (peer, doneEach) => {
let actual;
async.until(
() => {
return cmp.eq(actual, expected);
},
doneUntil => {
'use strict';
const async = require('async'),
flaschenpost = require('flaschenpost');
const logger = flaschenpost.getLogger();
const stop = function (peers, callback) {
logger.info('Stopping peers...');
async.each(peers, (peer, done) => {
peer.stop(done);
}, callback);
};
module.exports = stop;
'use strict';
const _ = require('lodash'),
async = require('async'),
flaschenpost = require('flaschenpost');
const logger = flaschenpost.getLogger();
const isRing = function (peers, callback) {
const peersWithNeighbours = [];
const getPeerIndex = function (self) {
if (!self) {
return -1;
}
return _.findIndex(peersWithNeighbours, function (peerWithNeighbours) {
return (
peerWithNeighbours.self.host === self.host &&
peerWithNeighbours.self.port === self.port
);
});
};
'use strict';
const url = require('url');
const flaschenpost = require('flaschenpost'),
processEnv = require('processenv'),
request = require('request'),
uuid = require('uuidv4');
const logger = flaschenpost.getLogger();
const port = processEnv('PORT') || 3000;
const job = {
id: process.argv[2] || uuid(),
data: process.argv[3] || 'foo'
};
request.post(url.format({
protocol: 'http',
hostname: 'localhost',
port,
pathname: '/job'
}), {
body: { value: job.id, data: job.data },
json: true
express = require('express'),
flaschenpost = require('flaschenpost'),
request = require('request'),
requireAll = require('require-all'),
sha1 = require('sha1');
const Endpoint = require('./Endpoint'),
errors = require('./errors'),
interval = require('./interval'),
WellKnownPeers = require('./WellKnownPeers');
const EventEmitter2 = eventEmitter2.EventEmitter2;
const routes = requireAll(path.join(__dirname, 'routes'));
const logger = flaschenpost.getLogger();
const Peer = function (options) {
if (!options) {
throw new Error('Options are missing.');
}
EventEmitter2.call(this, {
wildcard: true,
delimiter: '::'
});
this.protocol = options.protocol || 'https';
this.self = new Endpoint(options);
this.metadata = options.metadata || {};
this.successor = new Endpoint(options);