mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
rework PR comments
This commit is contained in:
parent
111602c707
commit
7a2de6c437
@ -5,23 +5,21 @@ import DHT from '@hyperswarm/dht'
|
||||
// import { Connection } from '@dbTools/typeorm'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import CONFIG from '@/config'
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const sodium = require('sodium-native')
|
||||
|
||||
function between(min: number, max: number) {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||
}
|
||||
|
||||
const getSeed = (): Buffer | null => {
|
||||
if (CONFIG.FEDERATE_DHT_SEED) {
|
||||
const secret = CONFIG.FEDERATE_DHT_SEED
|
||||
const seed = sodium.sodium_malloc(sodium.crypto_box_SEEDBYTES)
|
||||
seed.write(secret, 'hex')
|
||||
return seed
|
||||
if (CONFIG.FEDERATION_DHT_SEED) {
|
||||
logger.debug(`with seed='${CONFIG.FEDERATION_DHT_SEED}'`)
|
||||
return Buffer.alloc(KEY_SECRET_SEEDBYTES, CONFIG.FEDERATION_DHT_SEED)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const KEY_SECRET_SEEDBYTES = 32
|
||||
|
||||
const POLLTIME = 20000
|
||||
const SUCCESSTIME = 120000
|
||||
const ERRORTIME = 240000
|
||||
@ -40,10 +38,10 @@ export const startDHT = async (
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const TOPIC = DHT.hash(Buffer.from(topic))
|
||||
|
||||
logger.debug(`getSeed='${getSeed()}'`)
|
||||
const keyPair = DHT.keyPair(getSeed())
|
||||
logger.info(`keyPairDHT: publicKey=${keyPair.publicKey.toString('hex')}`)
|
||||
logger.info(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`)
|
||||
logger.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`)
|
||||
|
||||
const node = new DHT({ keyPair })
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user