Merge pull request #492 from shocknet/bug/gun-stability
Gun stability fixes
This commit is contained in:
commit
9a3de9e348
2 changed files with 36 additions and 28 deletions
|
|
@ -392,15 +392,11 @@ const authenticate = async (alias, pass, __user) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const logoff = () => {
|
|
||||||
user.leave()
|
|
||||||
}
|
|
||||||
|
|
||||||
const instantiateGun = () => {
|
const instantiateGun = () => {
|
||||||
const Config = require('../config')
|
const Config = require('../config')
|
||||||
if (user) {
|
// if (user) {
|
||||||
user.leave()
|
// user.leave()
|
||||||
}
|
// }
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
user = null
|
user = null
|
||||||
if (gun) {
|
if (gun) {
|
||||||
|
|
@ -523,7 +519,7 @@ const register = async (alias, pass) => {
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
authenticate,
|
authenticate,
|
||||||
logoff,
|
instantiateGun,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
isAuthenticating,
|
isAuthenticating,
|
||||||
isRegistering,
|
isRegistering,
|
||||||
|
|
|
||||||
|
|
@ -506,7 +506,7 @@ module.exports = async (
|
||||||
await recreateLnServices()
|
await recreateLnServices()
|
||||||
|
|
||||||
if (GunDB.isAuthenticated()) {
|
if (GunDB.isAuthenticated()) {
|
||||||
GunDB.logoff()
|
GunDB.instantiateGun()
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicKey = await GunDB.authenticate(alias, password)
|
const publicKey = await GunDB.authenticate(alias, password)
|
||||||
|
|
@ -2296,9 +2296,18 @@ module.exports = async (
|
||||||
: publicKey
|
: publicKey
|
||||||
? gun.user(publicKey)
|
? gun.user(publicKey)
|
||||||
: gun
|
: gun
|
||||||
keys.forEach(key => (node = node.get(key)))
|
|
||||||
logger.info(`fetching: ${keys}`)
|
logger.info(`fetching: ${keys}`)
|
||||||
|
keys.forEach(key => (node = node.get(key)))
|
||||||
|
|
||||||
|
if (!publicKeyForDecryption || !epubForDecryption) {
|
||||||
|
logger.warn('[GUN] Missing public key for decryption!', {
|
||||||
|
publicKeyForDecryption,
|
||||||
|
epubForDecryption
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
|
try {
|
||||||
const listener = data => {
|
const listener = data => {
|
||||||
logger.info(`got res for: ${keys}`)
|
logger.info(`got res for: ${keys}`)
|
||||||
logger.info(data || 'falsey data (does not get logged)')
|
logger.info(data || 'falsey data (does not get logged)')
|
||||||
|
|
@ -2317,6 +2326,9 @@ module.exports = async (
|
||||||
|
|
||||||
if (type === 'once') node.once(listener)
|
if (type === 'once') node.once(listener)
|
||||||
if (type === 'load') node.load(listener)
|
if (type === 'load') node.load(listener)
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Gun Fetch Error:', err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue