From 7a2de6c437b16e35e95cc6c9a4ffa3dc95dd1dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 25 Nov 2022 03:03:57 +0100 Subject: [PATCH] rework PR comments --- backend/src/federation/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/backend/src/federation/index.ts b/backend/src/federation/index.ts index a7a06e42a..cbf78bc1c 100644 --- a/backend/src/federation/index.ts +++ b/backend/src/federation/index.ts @@ -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 => { 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 })