diff --git a/backend/.env.dist b/backend/.env.dist index 3b6fe2ce4..c0a2a6098 100644 --- a/backend/.env.dist +++ b/backend/.env.dist @@ -1,4 +1,4 @@ -CONFIG_VERSION=v11.2022-10-27 +CONFIG_VERSION=v12.2022-11-10 # Server PORT=4000 @@ -61,7 +61,8 @@ EVENT_PROTOCOL_DISABLED=false # POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal # LOG_LEVEL=info -# DHT -# if you set this value, the DHT hyperswarm will start to announce and listen -# on an hash created from this tpoic -# DHT_TOPIC=GRADIDO_HUB +# Federation +# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen +# on an hash created from this topic +# FEDERATION_DHT_TOPIC=GRADIDO_HUB +# FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f diff --git a/backend/.env.template b/backend/.env.template index d009d08ff..1bb2e4155 100644 --- a/backend/.env.template +++ b/backend/.env.template @@ -56,5 +56,6 @@ WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET # EventProtocol EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED -# DHT -DHT_TOPIC=$DHT_TOPIC +# Federation +FEDERATION_DHT_TOPIC=$FEDERATION_DHT_TOPIC +FEDERATION_DHT_SEED=$FEDERATION_DHT_SEED diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index a66ed9765..c9e5ea79f 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -17,7 +17,7 @@ const constants = { LOG_LEVEL: process.env.LOG_LEVEL || 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', - EXPECTED: 'v11.2022-10-27', + EXPECTED: 'v12.2022-11-10', CURRENT: '', }, } @@ -117,7 +117,8 @@ if ( } const federation = { - DHT_TOPIC: process.env.DHT_TOPIC || null, + FEDERATION_DHT_TOPIC: process.env.FEDERATION_DHT_TOPIC || null, + FEDERATION_DHT_SEED: process.env.FEDERATION_DHT_SEED || null, } const CONFIG = { diff --git a/backend/src/federation/index.ts b/backend/src/federation/index.ts index 2ca58b432..82b961c63 100644 --- a/backend/src/federation/index.ts +++ b/backend/src/federation/index.ts @@ -4,11 +4,16 @@ import DHT from '@hyperswarm/dht' // import { Connection } from '@dbTools/typeorm' import { backendLogger as logger } from '@/server/logger' +import CONFIG from '@/config' function between(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1) + min) } +const KEY_SECRET_SEEDBYTES = 32 +const getSeed = (): Buffer | null => + CONFIG.FEDERATION_DHT_SEED ? Buffer.alloc(KEY_SECRET_SEEDBYTES, CONFIG.FEDERATION_DHT_SEED) : null + const POLLTIME = 20000 const SUCCESSTIME = 120000 const ERRORTIME = 240000 @@ -27,8 +32,9 @@ export const startDHT = async ( ): Promise => { 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.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`) const node = new DHT({ keyPair }) diff --git a/backend/src/index.ts b/backend/src/index.ts index dc1bbb115..e63f80827 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -19,8 +19,14 @@ async function main() { }) // start DHT hyperswarm when DHT_TOPIC is set in .env - if (CONFIG.DHT_TOPIC) { - await startDHT(CONFIG.DHT_TOPIC) // con, + if (CONFIG.FEDERATION_DHT_TOPIC) { + // eslint-disable-next-line no-console + console.log( + `starting Federation on ${CONFIG.FEDERATION_DHT_TOPIC} ${ + CONFIG.FEDERATION_DHT_SEED ? 'with seed...' : 'without seed...' + }`, + ) + await startDHT(CONFIG.FEDERATION_DHT_TOPIC) // con, } } diff --git a/deployment/bare_metal/.env.dist b/deployment/bare_metal/.env.dist index 1d0e96455..9c6bfd735 100644 --- a/deployment/bare_metal/.env.dist +++ b/deployment/bare_metal/.env.dist @@ -26,7 +26,7 @@ COMMUNITY_REDEEM_CONTRIBUTION_URL=https://stage1.gradido.net/redeem/CL-{code} COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community" # backend -BACKEND_CONFIG_VERSION=v11.2022-10-27 +BACKEND_CONFIG_VERSION=v12.2022-11-10 JWT_EXPIRES_IN=10m GDT_API_URL=https://gdt.gradido.net @@ -59,10 +59,11 @@ WEBHOOK_ELOPAGE_SECRET=secret # EventProtocol EVENT_PROTOCOL_DISABLED=false -## DHT -## if you set this value, the DHT hyperswarm will start to announce and listen -## on an hash created from this tpoic -# DHT_TOPIC=GRADIDO_HUB +# Federation +# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen +# on an hash created from this topic +# FEDERATION_DHT_TOPIC=GRADIDO_HUB +# FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f # database DATABASE_CONFIG_VERSION=v1.2022-03-18