Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public constructor(config: P2PConfig) {
super();
this._config = config;
this._isActive = false;
this._newPeers = new Map();
this._triedPeers = new Map();
this._httpServer = http.createServer();
this._scServer = attach(this._httpServer) as SCServerUpdated;
// This needs to be an arrow function so that it can be used as a listener.
this._handlePeerPoolRPC = (request: P2PRequest) => {
if (request.procedure === REMOTE_RPC_GET_ALL_PEERS_LIST) {
this._handleGetPeersRequest(request);
}
// Re-emit the request for external use.
this.emit(EVENT_REQUEST_RECEIVED, request);
};
// This needs to be an arrow function so that it can be used as a listener.
this._handlePeerPoolMessage = (message: P2PMessagePacket) => {
// Re-emit the message for external use.
this.emit(EVENT_MESSAGE_RECEIVED, message);
};
public constructor(config: P2PConfig) {
super();
this._config = config;
this._isActive = false;
this._newPeers = new Map();
this._triedPeers = new Map();
this._httpServer = http.createServer();
this._scServer = attach(this._httpServer) as SCServerUpdated;
// This needs to be an arrow function so that it can be used as a listener.
this._handlePeerPoolRPC = (request: P2PRequest) => {
// Re-emit the request for external use.
this.emit(EVENT_REQUEST_RECEIVED, request);
};
// This needs to be an arrow function so that it can be used as a listener.
this._handlePeerPoolMessage = (message: P2PMessagePacket) => {
// Re-emit the message for external use.
this.emit(EVENT_MESSAGE_RECEIVED, message);
};
this._handlePeerConnect = (peerInfo: P2PPeerInfo) => {
// Re-emit the message to allow it to bubble up the class hierarchy.
this.emit(EVENT_CONNECT_OUTBOUND, peerInfo);
}
}, function(error, response) {
res.json({
// hasError: Boolean(error),
error: error,
response: response
});
});
});
var httpSrv = http.createServer(app).listen(3000);
// var server = app.listen(3000, function() {
// var host = server.address().address;
// var port = server.address().port;
// console.log('App listening at http://%s:%s', host, port);
// });
var scServer = socketClusterServer.attach(httpSrv);
// var documentCount = -1;
var prevDocCount = -1;
scServer.on("connection", function(socket) {
// logger.info("New connection!");
});
client.ping({
requestTimeout: 30000,
// undocumented params are appended to the query string
hello: "elasticsearch"
}, function(error) {
if (error) {
logger.fatal("elasticsearch is down!");
// console.error('elasticsearch cluster is down!');
} else {
// console.log('All is well');
logger.info("Connected to elasticsearch!");
public constructor(config: P2PConfig) {
super();
this._config = config;
this._isActive = false;
this._newPeers = new Map();
this._triedPeers = new Map();
this._httpServer = http.createServer();
this._scServer = attach(this._httpServer, {
wsEngineServerOptions: {
maxPayload: config.wsMaxPayload
? config.wsMaxPayload
: DEFAULT_WS_MAX_PAYLOAD,
},
}) as SCServerUpdated;
// This needs to be an arrow function so that it can be used as a listener.
this._handlePeerPoolRPC = (request: P2PRequest) => {
if (request.procedure === REMOTE_RPC_GET_ALL_PEERS_LIST) {
this._handleGetPeersRequest(request);
}
// Re-emit the request for external use.
this.emit(EVENT_REQUEST_RECEIVED, request);
};
console.warn("Memory leak detected: " + info);
});
setTimeout(function() {
memwatch.gc();
}, 10000);
setInterval(function() {
memwatch.gc();
}, 120000);
var app = express();
const hostname = process.env.HOSTNAME || "localhost";
const port = process.env.PORT || 8000;
var server = http.createServer(app);
var scServer = socketClusterServer.attach(server);
scServer.addMiddleware(scServer.MIDDLEWARE_PUBLISH_IN, function(req, next) {
next({name: "denied", message: "Clients can't publish"});
});
var esclient = new elasticsearch.Client({
host: (process.env.ELASTIC || "192.168.1.65") + ':9200',
log: 'info'
});
app.use(express.static("static"));
app.use(bodyParser.json());
app.use(cacheResponseDirective());
app.use(function(err, req, res, next) {
cachemere.setPrepProvider(self._prepProvider);
self._server = http.createServer(self._middleware[self.MIDDLEWARE_HTTP].run);
self._httpRequestCount = 0;
self._ioRequestCount = 0;
self._httpRPM = 0;
self._ioRPM = 0;
if (self._statusInterval != null) {
clearInterval(self._statusInterval);
}
self._statusInterval = setInterval(this._calculateStatus.bind(this), this._options.workerStatusInterval * 1000);
self._socketServer = socketCluster.attach(self._server, {
sourcePort: self._options.port,
ioClusterClient: self._ioClusterClient,
transports: self._options.transports,
pingTimeout: self._options.heartbeatTimeout,
pingInterval: self._options.heartbeatInterval,
upgradeTimeout: self._options.connectTimeout,
host: self._options.host,
secure: self._options.protocol == 'https',
appName: self._options.appName
});
self._socketServer.on('notice', self.noticeHandler.bind(self));
self._errorDomain.add(self._socketServer);
var oldRequestListeners = self._server.listeners('request').splice(0);
self._server.removeAllListeners('request');
self.httpServer.on('request', self._httpRequestHandler.bind(self));
self.httpServer.on('upgrade', self._httpRequestHandler.bind(self));
self.httpServer.exchange = self.exchange;
self.httpServer.on('error', function (err) {
var error;
if (typeof err == 'string') {
error = new HTTPServerError(err);
} else {
error = err;
}
self.emitError(error);
});
self.scServer = socketClusterServer.attach(self.httpServer, {
brokerEngine: self.brokerEngineClient,
wsEngine: self._paths.wsEnginePath,
allowClientPublish: self.options.allowClientPublish,
handshakeTimeout: self.options.handshakeTimeout,
ackTimeout: self.options.ackTimeout,
pingTimeout: self.options.pingTimeout,
pingInterval: self.options.pingInterval,
pingTimeoutDisabled: self.options.pingTimeoutDisabled,
origins: self.options.origins,
appName: self.options.appName,
path: self.options.path,
authKey: self.options.authKey,
authPrivateKey: self.options.authPrivateKey,
authPublicKey: self.options.authPublicKey,
authAlgorithm: self.options.authAlgorithm,
authVerifyAlgorithms: self.options.authVerifyAlgorithms,
function createSocketServer(port) {
const httpServer = http.createServer();
httpServer.listen(port);
const socketServer = socketClusterServer.attach(httpServer);
return socketServer;
};
* 3 - log everything
* 2 - warnings and errors
* 1 - errors only
* 0 - log nothing
*/
var LOG_LEVEL;
if (typeof argv.l !== 'undefined') {
LOG_LEVEL = Number(argv.l);
} else if (typeof process.env.SCC_STATE_LOG_LEVEL !== 'undefined') {
LOG_LEVEL = Number(process.env.SCC_STATE_LOG_LEVEL);
} else {
LOG_LEVEL = 3;
}
var httpServer = http.createServer();
var scServer = socketCluster.attach(httpServer);
httpServer.on('request', function (req, res) {
if (req.url === '/health-check') {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('OK');
} else {
res.writeHead(404, {'Content-Type': 'text/html'});
res.end('Not found');
}
});
var sccBrokerSockets = {};
var sccWorkerSockets = {};
var serverReady = STARTUP_DELAY > 0 ? false : true;
if (!serverReady) {
logInfo(`Waiting ${STARTUP_DELAY}ms for initial scc-broker instances before allowing scc-worker instances to join`);