remove unused code

This commit is contained in:
Daniel Lugo 2020-02-18 21:15:44 -04:00
parent cb0d792223
commit 529c21239d
2 changed files with 1 additions and 76 deletions

View file

@ -196,14 +196,7 @@ const server = program => {
const io = require('socket.io')(serverInstance)
const Sockets = require('./sockets')(
io,
lnd,
program.user,
program.pwd,
program.limituser,
program.limitpwd
)
const Sockets = require('./sockets')(io, lnd)
require('./routes')(app, defaults, Sockets, {
serverHost: module.serverHost,

View file

@ -5,10 +5,6 @@ const logger = require("winston");
module.exports = (
io,
lnd,
login,
pass,
limitlogin,
limitpass
) => {
const Mediator = require("../services/gunDB/Mediator/index.js");
const EventEmitter = require("events");
@ -17,21 +13,6 @@ module.exports = (
const mySocketsEvents = new MySocketsEvents();
const clients = [];
const authEnabled = (login && pass) || (limitlogin && limitpass);
let userToken = null;
let limitUserToken = null;
if (login && pass) {
userToken = Buffer.from(login + ":" + pass).toString("base64");
}
if (limitlogin && limitpass) {
limitUserToken = Buffer.from(limitlogin + ":" + limitpass).toString(
"base64"
);
}
// register the lnd invoices listener
const registerLndInvoiceListener = socket => {
socket._invoiceListener = {
@ -57,20 +38,8 @@ module.exports = (
unregisterLndInvoiceListener(socket);
};
const getSocketAuthToken = socket => {
if (socket.handshake.query.auth) {
return socket.handshake.query.auth;
} else if (socket.handshake.headers.authorization) {
return socket.handshake.headers.authorization.substr(6);
}
socket.disconnect("unauthorized");
return null;
};
io.on("connection", socket => {
logger.info(`io.onconnection`)
// this is where we create the websocket connection
@ -81,50 +50,13 @@ module.exports = (
logger.info("socket.handshake", socket.handshake);
if (authEnabled) {
logger.info('io.onconnection -> authEnabled')
try {
const authorizationHeaderToken = getSocketAuthToken(socket);
logger.info('io.onconnection -> authHEaderTOken: ' + JSON.stringify(authorizationHeaderToken))
if (authorizationHeaderToken === userToken) {
logger.info('io.onconnection -> setting socket._limitUser to false')
socket._limituser = false;
} else if (authorizationHeaderToken === limitUserToken) {
logger.info('io.onconnection -> setting socket._limitUser to true')
socket._limituser = true;
} else {
logger.info('io.onconnection -> disconnecting socket as unauth')
socket.disconnect("unauthorized");
return;
}
} catch (err) {
logger.info('io.onconnection -> error caught:')
// probably because of missing authorization header
logger.info(JSON.stringify(err));
logger.info('WILL DISCONNECT SOCKET')
socket.disconnect("unauthorized");
return;
}
} else {
logger.info('io.onconnection -> no auth enabled so setting socket._limituser to false')
socket._limituser = false;
}
/** printing out the client who joined */
logger.info("New socket client connected (id=" + socket.id + ").");
socket.emit("hello", { limitUser: socket._limituser });
socket.broadcast.emit("hello", { remoteAddress: socket.handshake.address });
/** pushing new client to client array*/
clients.push(socket);
registerSocketListeners(socket);
/** listening if client has disconnected */
socket.on("disconnect", () => {
clients.splice(clients.indexOf(socket), 1);
unregisterSocketListeners(socket);
logger.info("client disconnected (id=" + socket.id + ").");
});