mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2374 from gradido/2367-feature-add-federation-configs
feat(backend): add federation config properties
This commit is contained in:
commit
f2380c6dfa
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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<void> => {
|
||||
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 })
|
||||
|
||||
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user