remove unused code
This commit is contained in:
parent
cb0d792223
commit
529c21239d
2 changed files with 1 additions and 76 deletions
|
|
@ -196,14 +196,7 @@ const server = program => {
|
||||||
|
|
||||||
const io = require('socket.io')(serverInstance)
|
const io = require('socket.io')(serverInstance)
|
||||||
|
|
||||||
const Sockets = require('./sockets')(
|
const Sockets = require('./sockets')(io, lnd)
|
||||||
io,
|
|
||||||
lnd,
|
|
||||||
program.user,
|
|
||||||
program.pwd,
|
|
||||||
program.limituser,
|
|
||||||
program.limitpwd
|
|
||||||
)
|
|
||||||
|
|
||||||
require('./routes')(app, defaults, Sockets, {
|
require('./routes')(app, defaults, Sockets, {
|
||||||
serverHost: module.serverHost,
|
serverHost: module.serverHost,
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,6 @@ const logger = require("winston");
|
||||||
module.exports = (
|
module.exports = (
|
||||||
io,
|
io,
|
||||||
lnd,
|
lnd,
|
||||||
login,
|
|
||||||
pass,
|
|
||||||
limitlogin,
|
|
||||||
limitpass
|
|
||||||
) => {
|
) => {
|
||||||
const Mediator = require("../services/gunDB/Mediator/index.js");
|
const Mediator = require("../services/gunDB/Mediator/index.js");
|
||||||
const EventEmitter = require("events");
|
const EventEmitter = require("events");
|
||||||
|
|
@ -17,21 +13,6 @@ module.exports = (
|
||||||
|
|
||||||
const mySocketsEvents = new MySocketsEvents();
|
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
|
// register the lnd invoices listener
|
||||||
const registerLndInvoiceListener = socket => {
|
const registerLndInvoiceListener = socket => {
|
||||||
socket._invoiceListener = {
|
socket._invoiceListener = {
|
||||||
|
|
@ -57,20 +38,8 @@ module.exports = (
|
||||||
unregisterLndInvoiceListener(socket);
|
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 => {
|
io.on("connection", socket => {
|
||||||
|
|
||||||
logger.info(`io.onconnection`)
|
logger.info(`io.onconnection`)
|
||||||
|
|
||||||
// this is where we create the websocket connection
|
// this is where we create the websocket connection
|
||||||
|
|
@ -81,50 +50,13 @@ module.exports = (
|
||||||
|
|
||||||
logger.info("socket.handshake", socket.handshake);
|
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 */
|
/** printing out the client who joined */
|
||||||
logger.info("New socket client connected (id=" + socket.id + ").");
|
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);
|
registerSocketListeners(socket);
|
||||||
|
|
||||||
/** listening if client has disconnected */
|
/** listening if client has disconnected */
|
||||||
socket.on("disconnect", () => {
|
socket.on("disconnect", () => {
|
||||||
clients.splice(clients.indexOf(socket), 1);
|
|
||||||
unregisterSocketListeners(socket);
|
unregisterSocketListeners(socket);
|
||||||
logger.info("client disconnected (id=" + socket.id + ").");
|
logger.info("client disconnected (id=" + socket.id + ").");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue