Merge pull request #222 from shocknet/disable-reinstantiate

disable reinstantiation
This commit is contained in:
Daniel Lugo 2020-10-20 13:37:16 -04:00 committed by GitHub
commit a5e665b4f8
2 changed files with 7 additions and 30 deletions

View file

@ -224,7 +224,6 @@ let user
/** @type {string|null} */
let _currentAlias = null
/** @type {string|null} */
let _currentPass = null
/** @type {string|null} */
let mySec = null
@ -361,7 +360,6 @@ const authenticate = async (alias, pass, __user) => {
mySec = await mySEA.secret(_user._.sea.epub, _user._.sea)
_currentAlias = alias
_currentPass = await mySEA.encrypt(pass, mySec)
await new Promise(res => setTimeout(res, 5000))
@ -433,30 +431,11 @@ const instantiateGun = () => {
instantiateGun()
const freshGun = async () => {
const _gun = /** @type {unknown} */ (new Gun({
axe: false,
multicast: false,
peers: Config.PEERS
}))
const gun = /** @type {GUNNode} */ (_gun)
const user = gun.user()
if (!_currentAlias || !_currentPass || !mySec) {
throw new Error('Called freshGun() without alias, pass and secret cached')
const freshGun = () => {
return {
gun,
user
}
const pass = await mySEA.decrypt(_currentPass, mySec)
if (typeof pass !== 'string') {
throw new Error('could not decrypt stored in memory current pass')
}
await authenticate(_currentAlias, pass, user)
return { gun, user }
}
/**
@ -1428,9 +1407,7 @@ const register = async (alias, pass) => {
if (typeof ack.err === 'string') {
throw new Error(ack.err)
} else if (typeof ack.pub === 'string' || typeof user._.sea === 'object') {
const mySecret = await mySEA.secret(user._.sea.epub, user._.sea)
_currentAlias = alias
_currentPass = await mySEA.encrypt(pass, mySecret)
// OK
} else {
throw new Error('unknown error, ack: ' + JSON.stringify(ack))
}

View file

@ -195,11 +195,11 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
}
logger.info(
`\n recreating a fresh gun and retrying one last time \n` +
`\n NOT recreating a fresh gun but retrying one last time \n` +
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
)
const { gun, user } = await require('../../Mediator/index').freshGun()
const { gun, user } = require('../../Mediator/index').freshGun()
return timeout10(promGen(gun, user))
/* eslint-enable no-empty */