Orginize
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Parse optional Hyperswarm connection-budget knobs from env.
|
||||
* @param {Record<string, string | undefined> | null | undefined} env
|
||||
* @returns {Record<string, unknown>}
|
||||
*/
|
||||
export function bareOsHyperswarmOptsFromEnv(env) {
|
||||
/** @type {Record<string, unknown>} */
|
||||
const o = {}
|
||||
const peerCap = String(env?.BARE_OS_SWARM_MAX_PEERS ?? '').trim()
|
||||
if (peerCap) {
|
||||
const x = Number(peerCap)
|
||||
if (Number.isFinite(x) && x >= 1) o.maxPeers = Math.min(4096, Math.floor(x))
|
||||
}
|
||||
const mcc = String(env?.BARE_OS_SWARM_MAX_CLIENT_CONNECTIONS ?? '').trim()
|
||||
if (mcc) {
|
||||
const x = Number(mcc)
|
||||
if (Number.isFinite(x) && x >= 1) {
|
||||
o.maxClientConnections = Math.min(1_000_000, Math.floor(x))
|
||||
}
|
||||
}
|
||||
const msc = String(env?.BARE_OS_SWARM_MAX_SERVER_CONNECTIONS ?? '').trim()
|
||||
if (msc) {
|
||||
const x = Number(msc)
|
||||
if (Number.isFinite(x) && x >= 1) {
|
||||
o.maxServerConnections = Math.min(1_000_000, Math.floor(x))
|
||||
}
|
||||
}
|
||||
const mpar = String(env?.BARE_OS_SWARM_MAX_PARALLEL ?? '').trim()
|
||||
if (mpar) {
|
||||
const x = Number(mpar)
|
||||
if (Number.isFinite(x) && x >= 1) o.maxParallel = Math.min(64, Math.floor(x))
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional direct-peer target for Hyperswarm joinPeer().
|
||||
* @param {Record<string, string | undefined> | null | undefined} env
|
||||
* @returns {string | null}
|
||||
*/
|
||||
export function bareOsBootJoinPeerHexFromEnv(env) {
|
||||
const raw = String(env?.BARE_OS_BOOT_JOIN_PEER_HEX ?? '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
if (!raw) return null
|
||||
if (!/^[0-9a-f]{64}$/.test(raw)) return null
|
||||
return raw
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional operator JSON merged into `replication_operator_sketch.protomuxOperatorSketch`.
|
||||
* @param {Record<string, string | undefined> | null | undefined} env
|
||||
*/
|
||||
export function bareOsProtomuxTuningFromEnv(env) {
|
||||
const raw = String(env?.BARE_OS_PROTOMUX_TUNING_JSON ?? '').trim()
|
||||
if (!raw) return null
|
||||
try {
|
||||
const o = JSON.parse(raw)
|
||||
return o && typeof o === 'object' && !Array.isArray(o) ? o : null
|
||||
} catch {
|
||||
return { schema: 1, parseError: true }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user