log through winston
This commit is contained in:
parent
fee5d705f3
commit
0ce7c92020
14 changed files with 141 additions and 112 deletions
|
|
@ -30,7 +30,7 @@ class Auth {
|
|||
|
||||
return { exists: true, parsable: true }
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
return { exists: true, parsable: false }
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ class Auth {
|
|||
})
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,5 @@
|
|||
{}
|
||||
{
|
||||
"1582813836485": "b8328f50-596d-11ea-b251-cf923e62abf5",
|
||||
"1582815195785": "e2674790-5970-11ea-ba5d-4b7fda6488de",
|
||||
"1582820933939": "3e9c1830-597e-11ea-acaa-2b96f5467d08"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
* @format
|
||||
*/
|
||||
const Gun = require('gun')
|
||||
const logger = require('winston')
|
||||
// @ts-ignore
|
||||
Gun.log = () => {}
|
||||
// @ts-ignore
|
||||
require('gun/lib/open')
|
||||
const debounce = require('lodash/debounce')
|
||||
const Encryption = require('../../../utils/encryptionStore')
|
||||
const logger = require('winston')
|
||||
|
||||
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
||||
// @ts-ignore
|
||||
|
|
@ -486,7 +486,7 @@ class Mediator {
|
|||
field: 'deviceId',
|
||||
message: 'Please specify a device ID'
|
||||
}
|
||||
console.error(error)
|
||||
logger.error(error)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -495,7 +495,7 @@ class Mediator {
|
|||
field: 'deviceId',
|
||||
message: 'Please specify a device ID'
|
||||
}
|
||||
console.error('Unknown Device', error)
|
||||
logger.error('Unknown Device', error)
|
||||
return false
|
||||
}
|
||||
if (typeof data === 'string') {
|
||||
|
|
@ -513,7 +513,7 @@ class Mediator {
|
|||
const decryptedData = JSON.parse(decryptedMessage)
|
||||
return cb(decryptedData)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
|
@ -538,7 +538,7 @@ class Mediator {
|
|||
socket.emit(eventName, encryptedMessage)
|
||||
} catch (err) {
|
||||
logger.error(err.message)
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -581,7 +581,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.ACCEPT_REQUEST, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -607,7 +607,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.BLACKLIST, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -637,7 +637,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.GENERATE_NEW_HANDSHAKE_NODE, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -652,11 +652,11 @@ class Mediator {
|
|||
sendHandshakeRequest = async body => {
|
||||
try {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('\n')
|
||||
console.log('------------------------------')
|
||||
console.log('will now try to send a handshake request')
|
||||
console.log('------------------------------')
|
||||
console.log('\n')
|
||||
logger.info('\n')
|
||||
logger.info('------------------------------')
|
||||
logger.info('will now try to send a handshake request')
|
||||
logger.info('------------------------------')
|
||||
logger.info('\n')
|
||||
}
|
||||
|
||||
const { recipientPublicKey, token } = body
|
||||
|
|
@ -671,11 +671,11 @@ class Mediator {
|
|||
)
|
||||
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('\n')
|
||||
console.log('------------------------------')
|
||||
console.log('handshake request successfuly sent')
|
||||
console.log('------------------------------')
|
||||
console.log('\n')
|
||||
logger.info('\n')
|
||||
logger.info('------------------------------')
|
||||
logger.info('handshake request successfuly sent')
|
||||
logger.info('------------------------------')
|
||||
logger.info('\n')
|
||||
}
|
||||
|
||||
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, {
|
||||
|
|
@ -685,11 +685,11 @@ class Mediator {
|
|||
})
|
||||
} catch (err) {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('\n')
|
||||
console.log('------------------------------')
|
||||
console.log('handshake request send fail: ' + err.message)
|
||||
console.log('------------------------------')
|
||||
console.log('\n')
|
||||
logger.info('\n')
|
||||
logger.info('------------------------------')
|
||||
logger.info('handshake request send fail: ' + err.message)
|
||||
logger.info('------------------------------')
|
||||
logger.info('\n')
|
||||
}
|
||||
|
||||
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, {
|
||||
|
|
@ -723,7 +723,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST_WITH_INITIAL_MSG, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -749,7 +749,7 @@ class Mediator {
|
|||
origBody: reqBody
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SEND_MESSAGE, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -782,7 +782,7 @@ class Mediator {
|
|||
origBody: reqBody
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SEND_PAYMENT, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -808,7 +808,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SET_AVATAR, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -834,7 +834,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SET_DISPLAY_NAME, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -856,9 +856,9 @@ class Mediator {
|
|||
|
||||
API.Events.onAvatar(avatar => {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('---avatar---')
|
||||
console.log(avatar)
|
||||
console.log('-----------------------')
|
||||
logger.info('---avatar---')
|
||||
logger.info(avatar || 'null')
|
||||
logger.info('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_AVATAR, {
|
||||
|
|
@ -868,7 +868,7 @@ class Mediator {
|
|||
})
|
||||
}, user)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_AVATAR, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -888,9 +888,9 @@ class Mediator {
|
|||
|
||||
API.Events.onBlacklist(blacklist => {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('---blacklist---')
|
||||
console.log(blacklist)
|
||||
console.log('-----------------------')
|
||||
logger.info('---blacklist---')
|
||||
logger.info(blacklist.join(','))
|
||||
logger.info('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_BLACKLIST, {
|
||||
|
|
@ -900,7 +900,7 @@ class Mediator {
|
|||
})
|
||||
}, user)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_BLACKLIST, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -916,15 +916,15 @@ class Mediator {
|
|||
try {
|
||||
const { token } = body
|
||||
|
||||
// console.log('ON_CHATS', body)
|
||||
// logger.info('ON_CHATS', body)
|
||||
|
||||
await throwOnInvalidToken(token)
|
||||
|
||||
API.Events.onChats(chats => {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('---chats---')
|
||||
console.log(chats)
|
||||
console.log('-----------------------')
|
||||
logger.info('---chats---')
|
||||
logger.info(chats)
|
||||
logger.info('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_CHATS, {
|
||||
|
|
@ -934,7 +934,7 @@ class Mediator {
|
|||
})
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_CHATS, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -954,9 +954,9 @@ class Mediator {
|
|||
|
||||
API.Events.onDisplayName(displayName => {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('---displayName---')
|
||||
console.log(displayName)
|
||||
console.log('-----------------------')
|
||||
logger.info('---displayName---')
|
||||
logger.info(displayName)
|
||||
logger.info('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_DISPLAY_NAME, {
|
||||
|
|
@ -966,7 +966,7 @@ class Mediator {
|
|||
})
|
||||
}, user)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_DISPLAY_NAME, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -986,9 +986,9 @@ class Mediator {
|
|||
|
||||
API.Events.onCurrentHandshakeAddress(addr => {
|
||||
if (Config.SHOW_LOG) {
|
||||
console.log('---addr---')
|
||||
console.log(addr)
|
||||
console.log('-----------------------')
|
||||
logger.info('---addr---')
|
||||
logger.info(addr)
|
||||
logger.info('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, {
|
||||
|
|
@ -998,7 +998,7 @@ class Mediator {
|
|||
})
|
||||
}, user)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -1017,12 +1017,6 @@ class Mediator {
|
|||
await throwOnInvalidToken(token)
|
||||
|
||||
API.Events.onSimplerReceivedRequests(receivedRequests => {
|
||||
if (Config.SHOW_LOG) {
|
||||
// console.log('---receivedRequests---')
|
||||
// console.log(receivedRequests)
|
||||
// console.log('-----------------------')
|
||||
}
|
||||
|
||||
this.socket.emit(Event.ON_RECEIVED_REQUESTS, {
|
||||
msg: receivedRequests,
|
||||
ok: true,
|
||||
|
|
@ -1030,7 +1024,7 @@ class Mediator {
|
|||
})
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_RECEIVED_REQUESTS, {
|
||||
msg: err.message,
|
||||
ok: false,
|
||||
|
|
@ -1055,7 +1049,7 @@ class Mediator {
|
|||
|
||||
API.Events.onSimplerSentRequests(
|
||||
debounce(sentRequests => {
|
||||
// console.log(
|
||||
// logger.info(
|
||||
// `new Reqss in mediator: ${JSON.stringify(sentRequests)}`
|
||||
// )
|
||||
this.socket.emit(Event.ON_SENT_REQUESTS, {
|
||||
|
|
@ -1067,7 +1061,7 @@ class Mediator {
|
|||
)
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_SENT_REQUESTS, {
|
||||
msg: err.message,
|
||||
ok: false,
|
||||
|
|
@ -1093,7 +1087,7 @@ class Mediator {
|
|||
})
|
||||
}, user)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_BIO, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -1119,7 +1113,7 @@ class Mediator {
|
|||
origBody: body
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Action.SET_BIO, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
@ -1149,7 +1143,7 @@ class Mediator {
|
|||
mySEA
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
logger.info(err)
|
||||
this.socket.emit(Event.ON_SEED_BACKUP, {
|
||||
ok: false,
|
||||
msg: err.message,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* @format
|
||||
*/
|
||||
const uuidv1 = require('uuid/v1')
|
||||
const logger = require('winston')
|
||||
|
||||
const LightningServices = require('../../../utils/lightningServices')
|
||||
|
||||
|
|
@ -458,20 +459,20 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
throw new Error('Do not send a request to yourself')
|
||||
}
|
||||
|
||||
console.log('sendHR() -> before recipientEpub')
|
||||
logger.info('sendHR() -> before recipientEpub')
|
||||
|
||||
/** @type {string} */
|
||||
const recipientEpub = await Utils.pubToEpub(recipientPublicKey)
|
||||
|
||||
console.log('sendHR() -> before mySecret')
|
||||
logger.info('sendHR() -> before mySecret')
|
||||
|
||||
const mySecret = require('../Mediator').getMySecret()
|
||||
console.log('sendHR() -> before ourSecret')
|
||||
logger.info('sendHR() -> before ourSecret')
|
||||
const ourSecret = await SEA.secret(recipientEpub, user._.sea)
|
||||
|
||||
// check if successful handshake is present
|
||||
|
||||
console.log('sendHR() -> before alreadyHandshaked')
|
||||
logger.info('sendHR() -> before alreadyHandshaked')
|
||||
|
||||
/** @type {boolean} */
|
||||
const alreadyHandshaked = await Utils.successfulHandshakeAlreadyExists(
|
||||
|
|
@ -482,7 +483,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
throw new Error(ErrorCode.ALREADY_HANDSHAKED)
|
||||
}
|
||||
|
||||
console.log('sendHR() -> before maybeLastRequestIDSentToUser')
|
||||
logger.info('sendHR() -> before maybeLastRequestIDSentToUser')
|
||||
|
||||
// check that we have already sent a request to this user, on his current
|
||||
// handshake node
|
||||
|
|
@ -493,7 +494,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
.then()
|
||||
)
|
||||
|
||||
console.log('sendHR() -> before currentHandshakeAddress')
|
||||
logger.info('sendHR() -> before currentHandshakeAddress')
|
||||
|
||||
const currentHandshakeAddress = await Utils.tryAndWait(gun =>
|
||||
gun
|
||||
|
|
@ -517,7 +518,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
|
||||
const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
|
||||
|
||||
console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode')
|
||||
logger.info('sendHR() -> before alreadyContactedOnCurrHandshakeNode')
|
||||
|
||||
const hrInHandshakeNode = await Utils.tryAndWait(
|
||||
gun =>
|
||||
|
|
@ -542,7 +543,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('sendHR() -> before __createOutgoingFeed')
|
||||
logger.info('sendHR() -> before __createOutgoingFeed')
|
||||
|
||||
const outgoingFeedID = await __createOutgoingFeed(
|
||||
recipientPublicKey,
|
||||
|
|
@ -550,7 +551,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
SEA
|
||||
)
|
||||
|
||||
console.log('sendHR() -> before encryptedForUsOutgoingFeedID')
|
||||
logger.info('sendHR() -> before encryptedForUsOutgoingFeedID')
|
||||
|
||||
const encryptedForUsOutgoingFeedID = await SEA.encrypt(
|
||||
outgoingFeedID,
|
||||
|
|
@ -571,7 +572,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
|||
mySecret
|
||||
)
|
||||
|
||||
console.log('sendHR() -> before newHandshakeRequestID')
|
||||
logger.info('sendHR() -> before newHandshakeRequestID')
|
||||
/** @type {string} */
|
||||
const newHandshakeRequestID = await new Promise((res, rej) => {
|
||||
const hr = gun
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
* @prettier
|
||||
*/
|
||||
const debounce = require('lodash/debounce')
|
||||
const logger = require('winston')
|
||||
|
||||
const ErrorCode = require('../errorCode')
|
||||
const Key = require('../key')
|
||||
|
|
@ -52,7 +53,7 @@ const __onUserToIncoming = (cb, user, SEA) => {
|
|||
// on disconnect
|
||||
delete userToIncoming[userPub]
|
||||
} else {
|
||||
console.error(
|
||||
logger.error(
|
||||
'got a non string non null value inside user to incoming'
|
||||
)
|
||||
}
|
||||
|
|
@ -60,14 +61,14 @@ const __onUserToIncoming = (cb, user, SEA) => {
|
|||
}
|
||||
|
||||
if (encryptedIncomingID.length === 0) {
|
||||
console.error('got an empty string value')
|
||||
logger.error('got an empty string value')
|
||||
return
|
||||
}
|
||||
|
||||
const incomingID = await SEA.decrypt(encryptedIncomingID, mySecret)
|
||||
|
||||
if (typeof incomingID === 'undefined') {
|
||||
console.warn('could not decrypt incomingID inside __onUserToIncoming')
|
||||
logger.warn('could not decrypt incomingID inside __onUserToIncoming')
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ const onBlacklist = (cb, user) => {
|
|||
blacklist.push(publicKey)
|
||||
callb(blacklist)
|
||||
} else {
|
||||
console.warn('Invalid public key received for blacklist')
|
||||
logger.warn('Invalid public key received for blacklist')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -191,7 +192,7 @@ const onCurrentHandshakeAddress = (cb, user) => {
|
|||
|
||||
user.get(Key.CURRENT_HANDSHAKE_ADDRESS).on(addr => {
|
||||
if (typeof addr !== 'string') {
|
||||
console.error('expected handshake address to be an string')
|
||||
logger.error('expected handshake address to be an string')
|
||||
|
||||
setAddress(null)
|
||||
|
||||
|
|
@ -289,7 +290,7 @@ const onIncomingMessages = (cb, userPK, incomingFeedID, gun, user, SEA) => {
|
|||
.map()
|
||||
.on(async (data, key) => {
|
||||
if (!Schema.isMessage(data)) {
|
||||
console.warn('non-message received')
|
||||
logger.warn('non-message received')
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -413,10 +414,10 @@ const onOutgoing = cb => {
|
|||
currentOutgoings = newOuts
|
||||
notifyOutgoingsListeners()
|
||||
} catch (e) {
|
||||
console.log('--------------------------')
|
||||
console.log('Events -> onOutgoing')
|
||||
console.log(e)
|
||||
console.log('--------------------------')
|
||||
logger.info('--------------------------')
|
||||
logger.info('Events -> onOutgoing')
|
||||
logger.info(e)
|
||||
logger.info('--------------------------')
|
||||
}
|
||||
}, 400)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/** @format */
|
||||
const debounce = require('lodash/debounce')
|
||||
const logger = require('winston')
|
||||
|
||||
const Key = require('../key')
|
||||
const Schema = require('../schema')
|
||||
|
|
@ -34,7 +35,7 @@ const setReceivedReqsMap = reqs => {
|
|||
}
|
||||
|
||||
listeners.add(() => {
|
||||
console.log(
|
||||
logger.info(
|
||||
`new received reqs: ${JSON.stringify(getReceivedReqs(), null, 4)}`
|
||||
)
|
||||
})
|
||||
|
|
@ -94,8 +95,8 @@ const listenerForAddr = addr => data => {
|
|||
}
|
||||
}
|
||||
|
||||
console.log('data for address: ' + addr)
|
||||
console.log(JSON.stringify(data, null, 4))
|
||||
logger.info('data for address: ' + addr)
|
||||
logger.info(JSON.stringify(data, null, 4))
|
||||
|
||||
react()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/** @format */
|
||||
const debounce = require('lodash/debounce')
|
||||
const logger = require('winston')
|
||||
|
||||
const Streams = require('../streams')
|
||||
/**
|
||||
|
|
@ -28,23 +29,33 @@ const listeners = new Set()
|
|||
let currentReqs = []
|
||||
|
||||
listeners.add(() => {
|
||||
console.log(`new sent reqs: ${JSON.stringify(currentReqs)}`)
|
||||
logger.info(`new sent reqs: ${JSON.stringify(currentReqs)}`)
|
||||
})
|
||||
|
||||
const getCurrentSentReqs = () => currentReqs
|
||||
|
||||
// any time any of the streams we use notifies us that it changed, we fire up
|
||||
// react()
|
||||
const react = debounce(() => {
|
||||
/** @type {SimpleSentRequest[]} */
|
||||
const newReqs = []
|
||||
|
||||
// reactive streams
|
||||
// maps a pk to its current handshake address
|
||||
const pubToHAddr = Streams.getAddresses()
|
||||
// a set or list containing copies of sent requests
|
||||
const storedReqs = Streams.getStoredReqs()
|
||||
// maps a pk to the last request sent to it (so old stored reqs are invalidated)
|
||||
const pubToLastSentReqID = Streams.getSentReqIDs()
|
||||
// maps a pk to a feed, messages if subbed and pk is pubbing, null /
|
||||
// 'disconnected' otherwise
|
||||
const pubToFeed = Streams.getPubToFeed()
|
||||
// pk to avatar
|
||||
const pubToAvatar = Streams.getPubToAvatar()
|
||||
// pk to display name
|
||||
const pubToDN = Streams.getPubToDn()
|
||||
|
||||
console.log(
|
||||
logger.info(
|
||||
`pubToLastSentREqID: ${JSON.stringify(pubToLastSentReqID, null, 4)}`
|
||||
)
|
||||
|
||||
|
|
@ -53,7 +64,10 @@ const react = debounce(() => {
|
|||
const currAddress = pubToHAddr[recipientPub]
|
||||
|
||||
const lastReqID = pubToLastSentReqID[recipientPub]
|
||||
// invalidate if this stored request is not the last one sent to this
|
||||
// particular pk
|
||||
const isStale = typeof lastReqID !== 'undefined' && lastReqID !== sentReqID
|
||||
// invalidate if we are in a pub/sub state to this pk (handshake in place)
|
||||
const isConnected = Array.isArray(pubToFeed[recipientPub])
|
||||
|
||||
if (isStale || isConnected) {
|
||||
|
|
@ -61,14 +75,20 @@ const react = debounce(() => {
|
|||
continue
|
||||
}
|
||||
|
||||
// no address for this pk? let's ask the corresponding stream to sub to
|
||||
// gun.user(pk).get('currentAddr')
|
||||
if (typeof currAddress === 'undefined') {
|
||||
// eslint-disable-next-line no-empty-function
|
||||
Streams.onAddresses(() => {}, recipientPub)()
|
||||
}
|
||||
// no avatar for this pk? let's ask the corresponding stream to sub to
|
||||
// gun.user(pk).get('avatar')
|
||||
if (typeof pubToAvatar[recipientPub] === 'undefined') {
|
||||
// eslint-disable-next-line no-empty-function
|
||||
Streams.onAvatar(() => {}, recipientPub)()
|
||||
}
|
||||
// no display name for this pk? let's ask the corresponding stream to sub to
|
||||
// gun.user(pk).get('displayName')
|
||||
if (typeof pubToDN[recipientPub] === 'undefined') {
|
||||
// eslint-disable-next-line no-empty-function
|
||||
Streams.onDisplayName(() => {}, recipientPub)()
|
||||
|
|
@ -78,6 +98,9 @@ const react = debounce(() => {
|
|||
id: sentReqID,
|
||||
recipientAvatar: pubToAvatar[recipientPub] || null,
|
||||
recipientChangedRequestAddress:
|
||||
// if we haven't received the other's user current handshake address,
|
||||
// let's assume he hasn't changed it and that this request is still
|
||||
// valid
|
||||
typeof currAddress !== 'undefined' && handshakeAddress !== currAddress,
|
||||
recipientDisplayName: pubToDN[recipientPub] || null,
|
||||
recipientPublicKey: recipientPub,
|
||||
|
|
|
|||
|
|
@ -169,8 +169,8 @@ const onAcceptedRequests = (user, SEA) => {
|
|||
})
|
||||
})
|
||||
} catch (err) {
|
||||
console.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
|
||||
console.log(err)
|
||||
logger.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
|
||||
logger.error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
|
||||
const LightningServices = require('../../../../utils/lightningServices')
|
||||
const logger = require('winston')
|
||||
|
||||
const ErrorCode = require('../errorCode')
|
||||
const Key = require('../key')
|
||||
|
|
@ -78,12 +79,12 @@ const listenerForAddr = (addr, user, SEA) => async (order, orderID) => {
|
|||
|
||||
orderToResponse.get(orderID).put(encInvoice, ack => {
|
||||
if (ack.err) {
|
||||
console.error(`error saving order response: ${ack.err}`)
|
||||
logger.error(`error saving order response: ${ack.err}`)
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('error inside onOrders:')
|
||||
console.error(err)
|
||||
logger.error('error inside onOrders:')
|
||||
logger.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
/** @format */
|
||||
const logger = require('winston')
|
||||
|
||||
const Key = require('../key')
|
||||
/**
|
||||
* @typedef {Record<string, string|null|undefined>} Addresses
|
||||
|
|
@ -11,7 +13,7 @@ const pubToAddress = {}
|
|||
const listeners = new Set()
|
||||
|
||||
listeners.add(() => {
|
||||
console.log(`pubToAddress: ${JSON.stringify(pubToAddress, null, 4)}`)
|
||||
logger.info(`pubToAddress: ${JSON.stringify(pubToAddress, null, 4)}`)
|
||||
})
|
||||
|
||||
const notify = () => listeners.forEach(l => l())
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ let pubToFeed = {}
|
|||
const getPubToFeed = () => pubToFeed
|
||||
|
||||
feedsListeners.add(() => {
|
||||
console.log(`new pubToFeed: ${JSON.stringify(getPubToFeed())}`)
|
||||
logger.info(`new pubToFeed: ${JSON.stringify(getPubToFeed())}`)
|
||||
})
|
||||
|
||||
/** @param {Feeds} ptf */
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ module.exports = async (
|
|||
resolve(unlockResponse);
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
if (err.message === "unknown service lnrpc.WalletUnlocker") {
|
||||
resolve({
|
||||
message: "Wallet already unlocked"
|
||||
|
|
@ -244,7 +244,7 @@ module.exports = async (
|
|||
req.body = JSON.parse(decryptedMessage);
|
||||
return next();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
return res
|
||||
.status(401)
|
||||
.json(
|
||||
|
|
@ -255,7 +255,7 @@ module.exports = async (
|
|||
|
||||
app.use(async (req, res, next) => {
|
||||
try {
|
||||
console.log("Route:", req.path)
|
||||
logger.info("Route:", req.path)
|
||||
|
||||
if (unprotectedRoutes[req.method][req.path]) {
|
||||
next();
|
||||
|
|
@ -352,10 +352,10 @@ module.exports = async (
|
|||
}
|
||||
|
||||
const authorizedDevice = await Encryption.authorizeDevice({ deviceId, publicKey })
|
||||
console.log(authorizedDevice)
|
||||
logger.info(authorizedDevice)
|
||||
return res.status(200).json(authorizedDevice)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
return res.status(401).json({
|
||||
field: 'unknown',
|
||||
message: err
|
||||
|
|
@ -384,7 +384,7 @@ module.exports = async (
|
|||
|
||||
app.post("/api/lnd/auth", async (req, res) => {
|
||||
try {
|
||||
console.log("/api/lnd/auth Body:", req.body)
|
||||
logger.info("/api/lnd/auth Body:", req.body)
|
||||
const health = await checkHealth();
|
||||
const walletInitialized = await walletExists();
|
||||
// If we're connected to lnd, unlock the wallet using the password supplied
|
||||
|
|
@ -603,7 +603,7 @@ module.exports = async (
|
|||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
res.status(400).json({
|
||||
field: "unknown",
|
||||
errorMessage: sanitizeLNDError(err.message)
|
||||
|
|
@ -614,7 +614,7 @@ module.exports = async (
|
|||
|
||||
waitUntilFileExists(1);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
return res.status(500).json({
|
||||
field: "unknown",
|
||||
errorMessage: err
|
||||
|
|
@ -623,7 +623,7 @@ module.exports = async (
|
|||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
return res.status(500).json({
|
||||
field: "unknown",
|
||||
errorMessage: err
|
||||
|
|
@ -631,7 +631,7 @@ module.exports = async (
|
|||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
logger.error(err);
|
||||
return res.status(500).json({
|
||||
field: "unknown",
|
||||
errorMessage: err
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ const server = program => {
|
|||
const auth = require('../services/auth/auth')
|
||||
|
||||
app.use(async (req, res, next) => {
|
||||
console.log('Route:', req.path)
|
||||
logger.info('Route:', req.path)
|
||||
if (unprotectedRoutes[req.method][req.path]) {
|
||||
next()
|
||||
} else {
|
||||
|
|
@ -117,7 +117,7 @@ const server = program => {
|
|||
|
||||
app.use((req, res, next) => {
|
||||
if (sensitiveRoutes[req.method][req.path]) {
|
||||
console.log(
|
||||
logger.info(
|
||||
JSON.stringify({
|
||||
time: new Date(),
|
||||
ip: req.ip,
|
||||
|
|
@ -127,7 +127,7 @@ const server = program => {
|
|||
})
|
||||
)
|
||||
} else {
|
||||
console.log(
|
||||
logger.info(
|
||||
JSON.stringify({
|
||||
time: new Date(),
|
||||
ip: req.ip,
|
||||
|
|
@ -224,8 +224,8 @@ const server = program => {
|
|||
// const localtunnel = require('localtunnel');
|
||||
//
|
||||
// const tunnel = localtunnel(port, (err, t) => {
|
||||
// console.log('err', err);
|
||||
// console.log('t', t.url);
|
||||
// logger.info('err', err);
|
||||
// logger.info('t', t.url);
|
||||
// });
|
||||
} catch (err) {
|
||||
logger.info(err)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
const Crypto = require('crypto')
|
||||
const { Buffer } = require('buffer')
|
||||
const logger = require('winston')
|
||||
|
||||
const APIKeyPair = new Map()
|
||||
const authorizedDevices = new Map()
|
||||
|
||||
|
|
@ -107,7 +109,7 @@ const Encryption = {
|
|||
},
|
||||
(err, publicKey, privateKey) => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
logger.error(err)
|
||||
reject(err)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue