check super peer conn for dup alias check

This commit is contained in:
Daniel Lugo 2020-07-16 14:05:30 -04:00
parent 6708d1622f
commit 58d0fd71e9

View file

@ -12,8 +12,10 @@ require('gun/lib/open')
// @ts-ignore
require('gun/lib/load')
const debounce = require('lodash/debounce')
const Encryption = require('../../../utils/encryptionStore')
const Encryption = require('../../../utils/encryptionStore')
const { SHOCK_SUPER_PEER } = require('../../../config/defaults')
const { PEERS } = require('../config')
const Key = require('../contact-api/key')
/** @type {import('../contact-api/SimpleGUN').ISEA} */
@ -1275,6 +1277,25 @@ const register = async (alias, pass) => {
)
}
const shocknetPeerInUse = PEERS.includes(SHOCK_SUPER_PEER)
if (shocknetPeerInUse) {
/**
* @type {Record<string, any>}
*/
// @ts-ignore
const currPeers = gun._.opt.peers
// This is a very basic test, only checks that the websocket is there but
// doesn't necessarily mean it is connected or that super peer is UP
const shocknetPeerConnected = !!currPeers[SHOCK_SUPER_PEER].wire
if (!shocknetPeerConnected) {
throw new Error(
`API Must be connected to super peer to check for duplicate aliases`
)
}
}
// this import is done here to avoid circular dependency hell
const { timeout5 } = require('../contact-api/utils')