mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
create DHT-KeyPair with optional configured Seed
This commit is contained in:
parent
28fa11bcd5
commit
5863736658
@ -4,11 +4,24 @@
|
||||
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
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
const POLLTIME = 20000
|
||||
const SUCCESSTIME = 120000
|
||||
const ERRORTIME = 240000
|
||||
@ -28,7 +41,9 @@ export const startDHT = async (
|
||||
try {
|
||||
const TOPIC = DHT.hash(Buffer.from(topic))
|
||||
|
||||
const keyPair = DHT.keyPair()
|
||||
const keyPair = DHT.keyPair(getSeed())
|
||||
logger.info(`keyPairDHT: publicKey=${keyPair.publicKey.toString('hex')}`)
|
||||
logger.info(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`)
|
||||
|
||||
const node = new DHT({ keyPair })
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user