log through winston

This commit is contained in:
Daniel Lugo 2020-02-27 13:22:57 -04:00
parent fee5d705f3
commit 0ce7c92020
14 changed files with 141 additions and 112 deletions

View file

@ -30,7 +30,7 @@ class Auth {
return { exists: true, parsable: true } return { exists: true, parsable: true }
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
return { exists: true, parsable: false } return { exists: true, parsable: false }
} }
} }
@ -130,7 +130,7 @@ class Auth {
}) })
}) })
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
throw err throw err
} }
} }

View file

@ -1 +1,5 @@
{} {
"1582813836485": "b8328f50-596d-11ea-b251-cf923e62abf5",
"1582815195785": "e2674790-5970-11ea-ba5d-4b7fda6488de",
"1582820933939": "3e9c1830-597e-11ea-acaa-2b96f5467d08"
}

View file

@ -2,13 +2,13 @@
* @format * @format
*/ */
const Gun = require('gun') const Gun = require('gun')
const logger = require('winston')
// @ts-ignore // @ts-ignore
Gun.log = () => {} Gun.log = () => {}
// @ts-ignore // @ts-ignore
require('gun/lib/open') require('gun/lib/open')
const debounce = require('lodash/debounce') const debounce = require('lodash/debounce')
const Encryption = require('../../../utils/encryptionStore') const Encryption = require('../../../utils/encryptionStore')
const logger = require('winston')
/** @type {import('../contact-api/SimpleGUN').ISEA} */ /** @type {import('../contact-api/SimpleGUN').ISEA} */
// @ts-ignore // @ts-ignore
@ -486,7 +486,7 @@ class Mediator {
field: 'deviceId', field: 'deviceId',
message: 'Please specify a device ID' message: 'Please specify a device ID'
} }
console.error(error) logger.error(error)
return false return false
} }
@ -495,7 +495,7 @@ class Mediator {
field: 'deviceId', field: 'deviceId',
message: 'Please specify a device ID' message: 'Please specify a device ID'
} }
console.error('Unknown Device', error) logger.error('Unknown Device', error)
return false return false
} }
if (typeof data === 'string') { if (typeof data === 'string') {
@ -513,7 +513,7 @@ class Mediator {
const decryptedData = JSON.parse(decryptedMessage) const decryptedData = JSON.parse(decryptedMessage)
return cb(decryptedData) return cb(decryptedData)
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
return false return false
} }
}) })
@ -538,7 +538,7 @@ class Mediator {
socket.emit(eventName, encryptedMessage) socket.emit(eventName, encryptedMessage)
} catch (err) { } catch (err) {
logger.error(err.message) logger.error(err.message)
console.error(err) logger.error(err)
} }
} }
} }
@ -581,7 +581,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.ACCEPT_REQUEST, { this.socket.emit(Action.ACCEPT_REQUEST, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -607,7 +607,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.BLACKLIST, { this.socket.emit(Action.BLACKLIST, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -637,7 +637,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.GENERATE_NEW_HANDSHAKE_NODE, { this.socket.emit(Action.GENERATE_NEW_HANDSHAKE_NODE, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -652,11 +652,11 @@ class Mediator {
sendHandshakeRequest = async body => { sendHandshakeRequest = async body => {
try { try {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('\n') logger.info('\n')
console.log('------------------------------') logger.info('------------------------------')
console.log('will now try to send a handshake request') logger.info('will now try to send a handshake request')
console.log('------------------------------') logger.info('------------------------------')
console.log('\n') logger.info('\n')
} }
const { recipientPublicKey, token } = body const { recipientPublicKey, token } = body
@ -671,11 +671,11 @@ class Mediator {
) )
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('\n') logger.info('\n')
console.log('------------------------------') logger.info('------------------------------')
console.log('handshake request successfuly sent') logger.info('handshake request successfuly sent')
console.log('------------------------------') logger.info('------------------------------')
console.log('\n') logger.info('\n')
} }
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, { this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, {
@ -685,11 +685,11 @@ class Mediator {
}) })
} catch (err) { } catch (err) {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('\n') logger.info('\n')
console.log('------------------------------') logger.info('------------------------------')
console.log('handshake request send fail: ' + err.message) logger.info('handshake request send fail: ' + err.message)
console.log('------------------------------') logger.info('------------------------------')
console.log('\n') logger.info('\n')
} }
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, { this.socket.emit(Action.SEND_HANDSHAKE_REQUEST, {
@ -723,7 +723,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SEND_HANDSHAKE_REQUEST_WITH_INITIAL_MSG, { this.socket.emit(Action.SEND_HANDSHAKE_REQUEST_WITH_INITIAL_MSG, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -749,7 +749,7 @@ class Mediator {
origBody: reqBody origBody: reqBody
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SEND_MESSAGE, { this.socket.emit(Action.SEND_MESSAGE, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -782,7 +782,7 @@ class Mediator {
origBody: reqBody origBody: reqBody
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SEND_PAYMENT, { this.socket.emit(Action.SEND_PAYMENT, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -808,7 +808,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SET_AVATAR, { this.socket.emit(Action.SET_AVATAR, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -834,7 +834,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SET_DISPLAY_NAME, { this.socket.emit(Action.SET_DISPLAY_NAME, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -856,9 +856,9 @@ class Mediator {
API.Events.onAvatar(avatar => { API.Events.onAvatar(avatar => {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('---avatar---') logger.info('---avatar---')
console.log(avatar) logger.info(avatar || 'null')
console.log('-----------------------') logger.info('-----------------------')
} }
this.socket.emit(Event.ON_AVATAR, { this.socket.emit(Event.ON_AVATAR, {
@ -868,7 +868,7 @@ class Mediator {
}) })
}, user) }, user)
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_AVATAR, { this.socket.emit(Event.ON_AVATAR, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -888,9 +888,9 @@ class Mediator {
API.Events.onBlacklist(blacklist => { API.Events.onBlacklist(blacklist => {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('---blacklist---') logger.info('---blacklist---')
console.log(blacklist) logger.info(blacklist.join(','))
console.log('-----------------------') logger.info('-----------------------')
} }
this.socket.emit(Event.ON_BLACKLIST, { this.socket.emit(Event.ON_BLACKLIST, {
@ -900,7 +900,7 @@ class Mediator {
}) })
}, user) }, user)
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_BLACKLIST, { this.socket.emit(Event.ON_BLACKLIST, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -916,15 +916,15 @@ class Mediator {
try { try {
const { token } = body const { token } = body
// console.log('ON_CHATS', body) // logger.info('ON_CHATS', body)
await throwOnInvalidToken(token) await throwOnInvalidToken(token)
API.Events.onChats(chats => { API.Events.onChats(chats => {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('---chats---') logger.info('---chats---')
console.log(chats) logger.info(chats)
console.log('-----------------------') logger.info('-----------------------')
} }
this.socket.emit(Event.ON_CHATS, { this.socket.emit(Event.ON_CHATS, {
@ -934,7 +934,7 @@ class Mediator {
}) })
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_CHATS, { this.socket.emit(Event.ON_CHATS, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -954,9 +954,9 @@ class Mediator {
API.Events.onDisplayName(displayName => { API.Events.onDisplayName(displayName => {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('---displayName---') logger.info('---displayName---')
console.log(displayName) logger.info(displayName)
console.log('-----------------------') logger.info('-----------------------')
} }
this.socket.emit(Event.ON_DISPLAY_NAME, { this.socket.emit(Event.ON_DISPLAY_NAME, {
@ -966,7 +966,7 @@ class Mediator {
}) })
}, user) }, user)
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_DISPLAY_NAME, { this.socket.emit(Event.ON_DISPLAY_NAME, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -986,9 +986,9 @@ class Mediator {
API.Events.onCurrentHandshakeAddress(addr => { API.Events.onCurrentHandshakeAddress(addr => {
if (Config.SHOW_LOG) { if (Config.SHOW_LOG) {
console.log('---addr---') logger.info('---addr---')
console.log(addr) logger.info(addr)
console.log('-----------------------') logger.info('-----------------------')
} }
this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, { this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, {
@ -998,7 +998,7 @@ class Mediator {
}) })
}, user) }, user)
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, { this.socket.emit(Event.ON_HANDSHAKE_ADDRESS, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -1017,12 +1017,6 @@ class Mediator {
await throwOnInvalidToken(token) await throwOnInvalidToken(token)
API.Events.onSimplerReceivedRequests(receivedRequests => { API.Events.onSimplerReceivedRequests(receivedRequests => {
if (Config.SHOW_LOG) {
// console.log('---receivedRequests---')
// console.log(receivedRequests)
// console.log('-----------------------')
}
this.socket.emit(Event.ON_RECEIVED_REQUESTS, { this.socket.emit(Event.ON_RECEIVED_REQUESTS, {
msg: receivedRequests, msg: receivedRequests,
ok: true, ok: true,
@ -1030,7 +1024,7 @@ class Mediator {
}) })
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_RECEIVED_REQUESTS, { this.socket.emit(Event.ON_RECEIVED_REQUESTS, {
msg: err.message, msg: err.message,
ok: false, ok: false,
@ -1055,7 +1049,7 @@ class Mediator {
API.Events.onSimplerSentRequests( API.Events.onSimplerSentRequests(
debounce(sentRequests => { debounce(sentRequests => {
// console.log( // logger.info(
// `new Reqss in mediator: ${JSON.stringify(sentRequests)}` // `new Reqss in mediator: ${JSON.stringify(sentRequests)}`
// ) // )
this.socket.emit(Event.ON_SENT_REQUESTS, { this.socket.emit(Event.ON_SENT_REQUESTS, {
@ -1067,7 +1061,7 @@ class Mediator {
) )
} }
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_SENT_REQUESTS, { this.socket.emit(Event.ON_SENT_REQUESTS, {
msg: err.message, msg: err.message,
ok: false, ok: false,
@ -1093,7 +1087,7 @@ class Mediator {
}) })
}, user) }, user)
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_BIO, { this.socket.emit(Event.ON_BIO, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -1119,7 +1113,7 @@ class Mediator {
origBody: body origBody: body
}) })
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Action.SET_BIO, { this.socket.emit(Action.SET_BIO, {
ok: false, ok: false,
msg: err.message, msg: err.message,
@ -1149,7 +1143,7 @@ class Mediator {
mySEA mySEA
) )
} catch (err) { } catch (err) {
console.log(err) logger.info(err)
this.socket.emit(Event.ON_SEED_BACKUP, { this.socket.emit(Event.ON_SEED_BACKUP, {
ok: false, ok: false,
msg: err.message, msg: err.message,

View file

@ -2,6 +2,7 @@
* @format * @format
*/ */
const uuidv1 = require('uuid/v1') const uuidv1 = require('uuid/v1')
const logger = require('winston')
const LightningServices = require('../../../utils/lightningServices') 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') throw new Error('Do not send a request to yourself')
} }
console.log('sendHR() -> before recipientEpub') logger.info('sendHR() -> before recipientEpub')
/** @type {string} */ /** @type {string} */
const recipientEpub = await Utils.pubToEpub(recipientPublicKey) const recipientEpub = await Utils.pubToEpub(recipientPublicKey)
console.log('sendHR() -> before mySecret') logger.info('sendHR() -> before mySecret')
const mySecret = require('../Mediator').getMySecret() const mySecret = require('../Mediator').getMySecret()
console.log('sendHR() -> before ourSecret') logger.info('sendHR() -> before ourSecret')
const ourSecret = await SEA.secret(recipientEpub, user._.sea) const ourSecret = await SEA.secret(recipientEpub, user._.sea)
// check if successful handshake is present // check if successful handshake is present
console.log('sendHR() -> before alreadyHandshaked') logger.info('sendHR() -> before alreadyHandshaked')
/** @type {boolean} */ /** @type {boolean} */
const alreadyHandshaked = await Utils.successfulHandshakeAlreadyExists( const alreadyHandshaked = await Utils.successfulHandshakeAlreadyExists(
@ -482,7 +483,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
throw new Error(ErrorCode.ALREADY_HANDSHAKED) 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 // check that we have already sent a request to this user, on his current
// handshake node // handshake node
@ -493,7 +494,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
.then() .then()
) )
console.log('sendHR() -> before currentHandshakeAddress') logger.info('sendHR() -> before currentHandshakeAddress')
const currentHandshakeAddress = await Utils.tryAndWait(gun => const currentHandshakeAddress = await Utils.tryAndWait(gun =>
gun gun
@ -517,7 +518,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
const lastRequestIDSentToUser = maybeLastRequestIDSentToUser const lastRequestIDSentToUser = maybeLastRequestIDSentToUser
console.log('sendHR() -> before alreadyContactedOnCurrHandshakeNode') logger.info('sendHR() -> before alreadyContactedOnCurrHandshakeNode')
const hrInHandshakeNode = await Utils.tryAndWait( const hrInHandshakeNode = await Utils.tryAndWait(
gun => 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( const outgoingFeedID = await __createOutgoingFeed(
recipientPublicKey, recipientPublicKey,
@ -550,7 +551,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
SEA SEA
) )
console.log('sendHR() -> before encryptedForUsOutgoingFeedID') logger.info('sendHR() -> before encryptedForUsOutgoingFeedID')
const encryptedForUsOutgoingFeedID = await SEA.encrypt( const encryptedForUsOutgoingFeedID = await SEA.encrypt(
outgoingFeedID, outgoingFeedID,
@ -571,7 +572,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
mySecret mySecret
) )
console.log('sendHR() -> before newHandshakeRequestID') logger.info('sendHR() -> before newHandshakeRequestID')
/** @type {string} */ /** @type {string} */
const newHandshakeRequestID = await new Promise((res, rej) => { const newHandshakeRequestID = await new Promise((res, rej) => {
const hr = gun const hr = gun

View file

@ -2,6 +2,7 @@
* @prettier * @prettier
*/ */
const debounce = require('lodash/debounce') const debounce = require('lodash/debounce')
const logger = require('winston')
const ErrorCode = require('../errorCode') const ErrorCode = require('../errorCode')
const Key = require('../key') const Key = require('../key')
@ -52,7 +53,7 @@ const __onUserToIncoming = (cb, user, SEA) => {
// on disconnect // on disconnect
delete userToIncoming[userPub] delete userToIncoming[userPub]
} else { } else {
console.error( logger.error(
'got a non string non null value inside user to incoming' 'got a non string non null value inside user to incoming'
) )
} }
@ -60,14 +61,14 @@ const __onUserToIncoming = (cb, user, SEA) => {
} }
if (encryptedIncomingID.length === 0) { if (encryptedIncomingID.length === 0) {
console.error('got an empty string value') logger.error('got an empty string value')
return return
} }
const incomingID = await SEA.decrypt(encryptedIncomingID, mySecret) const incomingID = await SEA.decrypt(encryptedIncomingID, mySecret)
if (typeof incomingID === 'undefined') { if (typeof incomingID === 'undefined') {
console.warn('could not decrypt incomingID inside __onUserToIncoming') logger.warn('could not decrypt incomingID inside __onUserToIncoming')
return return
} }
@ -151,7 +152,7 @@ const onBlacklist = (cb, user) => {
blacklist.push(publicKey) blacklist.push(publicKey)
callb(blacklist) callb(blacklist)
} else { } 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 => { user.get(Key.CURRENT_HANDSHAKE_ADDRESS).on(addr => {
if (typeof addr !== 'string') { if (typeof addr !== 'string') {
console.error('expected handshake address to be an string') logger.error('expected handshake address to be an string')
setAddress(null) setAddress(null)
@ -289,7 +290,7 @@ const onIncomingMessages = (cb, userPK, incomingFeedID, gun, user, SEA) => {
.map() .map()
.on(async (data, key) => { .on(async (data, key) => {
if (!Schema.isMessage(data)) { if (!Schema.isMessage(data)) {
console.warn('non-message received') logger.warn('non-message received')
return return
} }
@ -413,10 +414,10 @@ const onOutgoing = cb => {
currentOutgoings = newOuts currentOutgoings = newOuts
notifyOutgoingsListeners() notifyOutgoingsListeners()
} catch (e) { } catch (e) {
console.log('--------------------------') logger.info('--------------------------')
console.log('Events -> onOutgoing') logger.info('Events -> onOutgoing')
console.log(e) logger.info(e)
console.log('--------------------------') logger.info('--------------------------')
} }
}, 400) }, 400)
) )

View file

@ -1,5 +1,6 @@
/** @format */ /** @format */
const debounce = require('lodash/debounce') const debounce = require('lodash/debounce')
const logger = require('winston')
const Key = require('../key') const Key = require('../key')
const Schema = require('../schema') const Schema = require('../schema')
@ -34,7 +35,7 @@ const setReceivedReqsMap = reqs => {
} }
listeners.add(() => { listeners.add(() => {
console.log( logger.info(
`new received reqs: ${JSON.stringify(getReceivedReqs(), null, 4)}` `new received reqs: ${JSON.stringify(getReceivedReqs(), null, 4)}`
) )
}) })
@ -94,8 +95,8 @@ const listenerForAddr = addr => data => {
} }
} }
console.log('data for address: ' + addr) logger.info('data for address: ' + addr)
console.log(JSON.stringify(data, null, 4)) logger.info(JSON.stringify(data, null, 4))
react() react()
} }

View file

@ -1,5 +1,6 @@
/** @format */ /** @format */
const debounce = require('lodash/debounce') const debounce = require('lodash/debounce')
const logger = require('winston')
const Streams = require('../streams') const Streams = require('../streams')
/** /**
@ -28,23 +29,33 @@ const listeners = new Set()
let currentReqs = [] let currentReqs = []
listeners.add(() => { listeners.add(() => {
console.log(`new sent reqs: ${JSON.stringify(currentReqs)}`) logger.info(`new sent reqs: ${JSON.stringify(currentReqs)}`)
}) })
const getCurrentSentReqs = () => currentReqs const getCurrentSentReqs = () => currentReqs
// any time any of the streams we use notifies us that it changed, we fire up
// react()
const react = debounce(() => { const react = debounce(() => {
/** @type {SimpleSentRequest[]} */ /** @type {SimpleSentRequest[]} */
const newReqs = [] const newReqs = []
// reactive streams
// maps a pk to its current handshake address
const pubToHAddr = Streams.getAddresses() const pubToHAddr = Streams.getAddresses()
// a set or list containing copies of sent requests
const storedReqs = Streams.getStoredReqs() const storedReqs = Streams.getStoredReqs()
// maps a pk to the last request sent to it (so old stored reqs are invalidated)
const pubToLastSentReqID = Streams.getSentReqIDs() const pubToLastSentReqID = Streams.getSentReqIDs()
// maps a pk to a feed, messages if subbed and pk is pubbing, null /
// 'disconnected' otherwise
const pubToFeed = Streams.getPubToFeed() const pubToFeed = Streams.getPubToFeed()
// pk to avatar
const pubToAvatar = Streams.getPubToAvatar() const pubToAvatar = Streams.getPubToAvatar()
// pk to display name
const pubToDN = Streams.getPubToDn() const pubToDN = Streams.getPubToDn()
console.log( logger.info(
`pubToLastSentREqID: ${JSON.stringify(pubToLastSentReqID, null, 4)}` `pubToLastSentREqID: ${JSON.stringify(pubToLastSentReqID, null, 4)}`
) )
@ -53,7 +64,10 @@ const react = debounce(() => {
const currAddress = pubToHAddr[recipientPub] const currAddress = pubToHAddr[recipientPub]
const lastReqID = pubToLastSentReqID[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 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]) const isConnected = Array.isArray(pubToFeed[recipientPub])
if (isStale || isConnected) { if (isStale || isConnected) {
@ -61,14 +75,20 @@ const react = debounce(() => {
continue continue
} }
// no address for this pk? let's ask the corresponding stream to sub to
// gun.user(pk).get('currentAddr')
if (typeof currAddress === 'undefined') { if (typeof currAddress === 'undefined') {
// eslint-disable-next-line no-empty-function // eslint-disable-next-line no-empty-function
Streams.onAddresses(() => {}, recipientPub)() 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') { if (typeof pubToAvatar[recipientPub] === 'undefined') {
// eslint-disable-next-line no-empty-function // eslint-disable-next-line no-empty-function
Streams.onAvatar(() => {}, recipientPub)() 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') { if (typeof pubToDN[recipientPub] === 'undefined') {
// eslint-disable-next-line no-empty-function // eslint-disable-next-line no-empty-function
Streams.onDisplayName(() => {}, recipientPub)() Streams.onDisplayName(() => {}, recipientPub)()
@ -78,6 +98,9 @@ const react = debounce(() => {
id: sentReqID, id: sentReqID,
recipientAvatar: pubToAvatar[recipientPub] || null, recipientAvatar: pubToAvatar[recipientPub] || null,
recipientChangedRequestAddress: 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, typeof currAddress !== 'undefined' && handshakeAddress !== currAddress,
recipientDisplayName: pubToDN[recipientPub] || null, recipientDisplayName: pubToDN[recipientPub] || null,
recipientPublicKey: recipientPub, recipientPublicKey: recipientPub,

View file

@ -169,8 +169,8 @@ const onAcceptedRequests = (user, SEA) => {
}) })
}) })
} catch (err) { } catch (err) {
console.warn(`Jobs.onAcceptedRequests() -> ${err.message}`) logger.warn(`Jobs.onAcceptedRequests() -> ${err.message}`)
console.log(err) logger.error(err)
} }
}) })
} }

View file

@ -3,6 +3,7 @@
*/ */
const LightningServices = require('../../../../utils/lightningServices') const LightningServices = require('../../../../utils/lightningServices')
const logger = require('winston')
const ErrorCode = require('../errorCode') const ErrorCode = require('../errorCode')
const Key = require('../key') const Key = require('../key')
@ -78,12 +79,12 @@ const listenerForAddr = (addr, user, SEA) => async (order, orderID) => {
orderToResponse.get(orderID).put(encInvoice, ack => { orderToResponse.get(orderID).put(encInvoice, ack => {
if (ack.err) { if (ack.err) {
console.error(`error saving order response: ${ack.err}`) logger.error(`error saving order response: ${ack.err}`)
} }
}) })
} catch (err) { } catch (err) {
console.error('error inside onOrders:') logger.error('error inside onOrders:')
console.error(err) logger.error(err)
} }
} }

View file

@ -1,4 +1,6 @@
/** @format */ /** @format */
const logger = require('winston')
const Key = require('../key') const Key = require('../key')
/** /**
* @typedef {Record<string, string|null|undefined>} Addresses * @typedef {Record<string, string|null|undefined>} Addresses
@ -11,7 +13,7 @@ const pubToAddress = {}
const listeners = new Set() const listeners = new Set()
listeners.add(() => { listeners.add(() => {
console.log(`pubToAddress: ${JSON.stringify(pubToAddress, null, 4)}`) logger.info(`pubToAddress: ${JSON.stringify(pubToAddress, null, 4)}`)
}) })
const notify = () => listeners.forEach(l => l()) const notify = () => listeners.forEach(l => l())

View file

@ -29,7 +29,7 @@ let pubToFeed = {}
const getPubToFeed = () => pubToFeed const getPubToFeed = () => pubToFeed
feedsListeners.add(() => { feedsListeners.add(() => {
console.log(`new pubToFeed: ${JSON.stringify(getPubToFeed())}`) logger.info(`new pubToFeed: ${JSON.stringify(getPubToFeed())}`)
}) })
/** @param {Feeds} ptf */ /** @param {Feeds} ptf */

View file

@ -163,7 +163,7 @@ module.exports = async (
resolve(unlockResponse); resolve(unlockResponse);
}); });
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
if (err.message === "unknown service lnrpc.WalletUnlocker") { if (err.message === "unknown service lnrpc.WalletUnlocker") {
resolve({ resolve({
message: "Wallet already unlocked" message: "Wallet already unlocked"
@ -244,7 +244,7 @@ module.exports = async (
req.body = JSON.parse(decryptedMessage); req.body = JSON.parse(decryptedMessage);
return next(); return next();
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
return res return res
.status(401) .status(401)
.json( .json(
@ -255,7 +255,7 @@ module.exports = async (
app.use(async (req, res, next) => { app.use(async (req, res, next) => {
try { try {
console.log("Route:", req.path) logger.info("Route:", req.path)
if (unprotectedRoutes[req.method][req.path]) { if (unprotectedRoutes[req.method][req.path]) {
next(); next();
@ -352,10 +352,10 @@ module.exports = async (
} }
const authorizedDevice = await Encryption.authorizeDevice({ deviceId, publicKey }) const authorizedDevice = await Encryption.authorizeDevice({ deviceId, publicKey })
console.log(authorizedDevice) logger.info(authorizedDevice)
return res.status(200).json(authorizedDevice) return res.status(200).json(authorizedDevice)
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
return res.status(401).json({ return res.status(401).json({
field: 'unknown', field: 'unknown',
message: err message: err
@ -384,7 +384,7 @@ module.exports = async (
app.post("/api/lnd/auth", async (req, res) => { app.post("/api/lnd/auth", async (req, res) => {
try { try {
console.log("/api/lnd/auth Body:", req.body) logger.info("/api/lnd/auth Body:", req.body)
const health = await checkHealth(); const health = await checkHealth();
const walletInitialized = await walletExists(); const walletInitialized = await walletExists();
// If we're connected to lnd, unlock the wallet using the password supplied // If we're connected to lnd, unlock the wallet using the password supplied
@ -603,7 +603,7 @@ module.exports = async (
} }
}); });
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
res.status(400).json({ res.status(400).json({
field: "unknown", field: "unknown",
errorMessage: sanitizeLNDError(err.message) errorMessage: sanitizeLNDError(err.message)
@ -614,7 +614,7 @@ module.exports = async (
waitUntilFileExists(1); waitUntilFileExists(1);
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
return res.status(500).json({ return res.status(500).json({
field: "unknown", field: "unknown",
errorMessage: err errorMessage: err
@ -623,7 +623,7 @@ module.exports = async (
} }
); );
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
return res.status(500).json({ return res.status(500).json({
field: "unknown", field: "unknown",
errorMessage: err errorMessage: err
@ -631,7 +631,7 @@ module.exports = async (
} }
}); });
} catch (err) { } catch (err) {
console.error(err); logger.error(err);
return res.status(500).json({ return res.status(500).json({
field: "unknown", field: "unknown",
errorMessage: err errorMessage: err

View file

@ -85,7 +85,7 @@ const server = program => {
const auth = require('../services/auth/auth') const auth = require('../services/auth/auth')
app.use(async (req, res, next) => { app.use(async (req, res, next) => {
console.log('Route:', req.path) logger.info('Route:', req.path)
if (unprotectedRoutes[req.method][req.path]) { if (unprotectedRoutes[req.method][req.path]) {
next() next()
} else { } else {
@ -117,7 +117,7 @@ const server = program => {
app.use((req, res, next) => { app.use((req, res, next) => {
if (sensitiveRoutes[req.method][req.path]) { if (sensitiveRoutes[req.method][req.path]) {
console.log( logger.info(
JSON.stringify({ JSON.stringify({
time: new Date(), time: new Date(),
ip: req.ip, ip: req.ip,
@ -127,7 +127,7 @@ const server = program => {
}) })
) )
} else { } else {
console.log( logger.info(
JSON.stringify({ JSON.stringify({
time: new Date(), time: new Date(),
ip: req.ip, ip: req.ip,
@ -224,8 +224,8 @@ const server = program => {
// const localtunnel = require('localtunnel'); // const localtunnel = require('localtunnel');
// //
// const tunnel = localtunnel(port, (err, t) => { // const tunnel = localtunnel(port, (err, t) => {
// console.log('err', err); // logger.info('err', err);
// console.log('t', t.url); // logger.info('t', t.url);
// }); // });
} catch (err) { } catch (err) {
logger.info(err) logger.info(err)

View file

@ -3,6 +3,8 @@
*/ */
const Crypto = require('crypto') const Crypto = require('crypto')
const { Buffer } = require('buffer') const { Buffer } = require('buffer')
const logger = require('winston')
const APIKeyPair = new Map() const APIKeyPair = new Map()
const authorizedDevices = new Map() const authorizedDevices = new Map()
@ -107,7 +109,7 @@ const Encryption = {
}, },
(err, publicKey, privateKey) => { (err, publicKey, privateKey) => {
if (err) { if (err) {
console.error(err) logger.error(err)
reject(err) reject(err)
return err return err
} }