Merge pull request #243 from shocknet/rogue-sockets

Rogue sockets
This commit is contained in:
Daniel Lugo 2020-11-06 16:37:46 -04:00 committed by GitHub
commit 2ead87c11c
2 changed files with 12 additions and 75 deletions

View file

@ -70,49 +70,6 @@ module.exports = async (
const getAvailableService = () => {
return lndErrorManager.getAvailableService()
}
/*
new Promise((resolve, reject) => {
const { lightning } = LightningServices.services
lightning.getInfo({}, (err, response) => {
if (err) {
if (err.message.includes('unknown service lnrpc.Lightning')) {
resolve({
service: 'walletUnlocker',
message: 'Wallet locked',
code: err.code,
walletStatus: 'locked',
success: true
})
} else if (err.code === 14) {
reject({
service: 'unknown',
message:
"Failed to connect to LND server, make sure it's up and running.",
code: 14,
walletStatus: 'unknown',
success: false
})
} else {
reject({
service: 'lightning',
message: sanitizeLNDError(err.message),
code: err.code,
walletStatus: 'unlocked',
success: false
})
}
}
resolve({
service: 'lightning',
message: response,
code: null,
walletStatus: 'unlocked',
success: true
})
})
})*/
const checkHealth = async () => {
logger.info('Getting service status...')

View file

@ -257,33 +257,6 @@ module.exports = (
}
}
io.of('default').on('connection', socket => {
logger.info(`io.onconnection`)
logger.info('socket.handshake', socket.handshake)
const isLNDSocket = !!socket.handshake.query.IS_LND_SOCKET
const isNotificationsSocket = !!socket.handshake.query
.IS_NOTIFICATIONS_SOCKET
if (!isLNDSocket) {
/** printing out the client who joined */
logger.info('New socket client connected (id=' + socket.id + ').')
}
if (isLNDSocket) {
const subID = Math.floor(Math.random() * 1000).toString()
const isNotifications = isNotificationsSocket ? 'notifications' : ''
logger.info('[LND] New LND Socket created:' + isNotifications + subID)
const cancelInvoiceStream = onNewInvoice(socket, subID)
const cancelTransactionStream = onNewTransaction(socket, subID)
socket.on('disconnect', () => {
logger.info('LND socket disconnected:' + isNotifications + subID)
cancelInvoiceStream()
cancelTransactionStream()
})
}
})
io.of('gun').on('connect', socket => {
// TODO: off()
@ -445,14 +418,18 @@ module.exports = (
// TODO: make this sync
async socket => {
try {
logger.info('Received connect request for shockping socket')
if (!isAuthenticated()) {
logger.info(
'not authenticated in gun for shockping socket, will send NOT_AUTH'
)
socket.emit(Common.Constants.ErrorCode.NOT_AUTH)
return
}
logger.info('now checking token')
const { token } = socket.handshake.query
const isAuth = await isValidToken(token)
if (!isAuth) {
@ -462,11 +439,13 @@ module.exports = (
}
if (pingIntervalID !== null) {
logger.error('Tried to set ping socket twice')
logger.error(
'Tried to set ping socket twice, this might be due to an app restart and the old socket not being recycled by socket.io in time, will disable the older ping interval, which means the old socket wont work and will ping this new socket instead'
)
clearInterval(pingIntervalID)
pingIntervalID = null
}
socket.emit('shockping')
pingIntervalID = setInterval(() => {
socket.emit('shockping')
}, 3000)
@ -479,7 +458,8 @@ module.exports = (
}
})
} catch (err) {
logger.error('GUNRPC: ' + err.message)
logger.error('Error inside shockping connect: ' + err.message)
socket.emit('$error', err.message)
}
}
)