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
|
# Server
|
||||||
PORT=4000
|
PORT=4000
|
||||||
@ -61,7 +61,8 @@ EVENT_PROTOCOL_DISABLED=false
|
|||||||
# POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal
|
# POSSIBLE VALUES: all | trace | debug | info | warn | error | fatal
|
||||||
# LOG_LEVEL=info
|
# LOG_LEVEL=info
|
||||||
|
|
||||||
# DHT
|
# Federation
|
||||||
# if you set this value, the DHT hyperswarm will start to announce and listen
|
# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen
|
||||||
# on an hash created from this tpoic
|
# on an hash created from this topic
|
||||||
# DHT_TOPIC=GRADIDO_HUB
|
# FEDERATION_DHT_TOPIC=GRADIDO_HUB
|
||||||
|
# FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f
|
||||||
|
|||||||
@ -56,5 +56,6 @@ WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET
|
|||||||
# EventProtocol
|
# EventProtocol
|
||||||
EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED
|
EVENT_PROTOCOL_DISABLED=$EVENT_PROTOCOL_DISABLED
|
||||||
|
|
||||||
# DHT
|
# Federation
|
||||||
DHT_TOPIC=$DHT_TOPIC
|
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',
|
LOG_LEVEL: process.env.LOG_LEVEL || 'info',
|
||||||
CONFIG_VERSION: {
|
CONFIG_VERSION: {
|
||||||
DEFAULT: 'DEFAULT',
|
DEFAULT: 'DEFAULT',
|
||||||
EXPECTED: 'v11.2022-10-27',
|
EXPECTED: 'v12.2022-11-10',
|
||||||
CURRENT: '',
|
CURRENT: '',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -117,7 +117,8 @@ if (
|
|||||||
}
|
}
|
||||||
|
|
||||||
const federation = {
|
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 = {
|
const CONFIG = {
|
||||||
|
|||||||
@ -4,11 +4,16 @@
|
|||||||
import DHT from '@hyperswarm/dht'
|
import DHT from '@hyperswarm/dht'
|
||||||
// import { Connection } from '@dbTools/typeorm'
|
// import { Connection } from '@dbTools/typeorm'
|
||||||
import { backendLogger as logger } from '@/server/logger'
|
import { backendLogger as logger } from '@/server/logger'
|
||||||
|
import CONFIG from '@/config'
|
||||||
|
|
||||||
function between(min: number, max: number) {
|
function between(min: number, max: number) {
|
||||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
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 POLLTIME = 20000
|
||||||
const SUCCESSTIME = 120000
|
const SUCCESSTIME = 120000
|
||||||
const ERRORTIME = 240000
|
const ERRORTIME = 240000
|
||||||
@ -27,8 +32,9 @@ export const startDHT = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const TOPIC = DHT.hash(Buffer.from(topic))
|
const TOPIC = DHT.hash(Buffer.from(topic))
|
||||||
|
const keyPair = DHT.keyPair(getSeed())
|
||||||
const keyPair = DHT.keyPair()
|
logger.info(`keyPairDHT: publicKey=${keyPair.publicKey.toString('hex')}`)
|
||||||
|
logger.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`)
|
||||||
|
|
||||||
const node = new DHT({ keyPair })
|
const node = new DHT({ keyPair })
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,14 @@ async function main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// start DHT hyperswarm when DHT_TOPIC is set in .env
|
// start DHT hyperswarm when DHT_TOPIC is set in .env
|
||||||
if (CONFIG.DHT_TOPIC) {
|
if (CONFIG.FEDERATION_DHT_TOPIC) {
|
||||||
await startDHT(CONFIG.DHT_TOPIC) // con,
|
// 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"
|
COMMUNITY_DESCRIPTION="Gradido Development Stage1 Test Community"
|
||||||
|
|
||||||
# backend
|
# backend
|
||||||
BACKEND_CONFIG_VERSION=v11.2022-10-27
|
BACKEND_CONFIG_VERSION=v12.2022-11-10
|
||||||
|
|
||||||
JWT_EXPIRES_IN=10m
|
JWT_EXPIRES_IN=10m
|
||||||
GDT_API_URL=https://gdt.gradido.net
|
GDT_API_URL=https://gdt.gradido.net
|
||||||
@ -59,10 +59,11 @@ WEBHOOK_ELOPAGE_SECRET=secret
|
|||||||
# EventProtocol
|
# EventProtocol
|
||||||
EVENT_PROTOCOL_DISABLED=false
|
EVENT_PROTOCOL_DISABLED=false
|
||||||
|
|
||||||
## DHT
|
# Federation
|
||||||
## if you set this value, the DHT hyperswarm will start to announce and listen
|
# if you set the value of FEDERATION_DHT_TOPIC, the DHT hyperswarm will start to announce and listen
|
||||||
## on an hash created from this tpoic
|
# on an hash created from this topic
|
||||||
# DHT_TOPIC=GRADIDO_HUB
|
# FEDERATION_DHT_TOPIC=GRADIDO_HUB
|
||||||
|
# FEDERATION_DHT_SEED=64ebcb0e3ad547848fef4197c6e2332f
|
||||||
|
|
||||||
# database
|
# database
|
||||||
DATABASE_CONFIG_VERSION=v1.2022-03-18
|
DATABASE_CONFIG_VERSION=v1.2022-03-18
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user