Files
dat-thang/tests/interop/cabal/cable_bootstrap.js
T
divorce b735900f2e 0.0.002
ddat interop with dat js
cable interop with cabal js
ddat's frontend = dat-thang
cable fe = cable-thang
dillo support based on cel's dillo-dat
bootstrap node
xplatform support

Signed-off-by: divo <418@cryspace.space>
2026-10-19 00:17:02 -04:00

34 lines
1.1 KiB
JavaScript

'use strict'
// Run a public Cabal-compatible HyperDHT bootstrap node in the foreground.
// Put this under a service manager and advertise the reachable IPv4 host/UDP port.
const { loadCabalCore } = require('./cable_hyperswarm')
async function main () {
const host = process.argv[2]
const port = Number(process.argv[3])
if (!host || !Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error('usage: cable bootstrap serve <public-ipv4-host> <udp-port>')
}
const { requireCabal } = loadCabalCore()
const DHT = requireCabal('hyperdht')
const node = DHT.bootstrapper(port, host)
await node.ready()
const address = node.address()
process.stdout.write('Cabal Hyperswarm bootstrap serving ' + host + ':' + address.port +
' (bound ' + address.host + ':' + address.port + ')\n')
const close = async () => {
try { await node.destroy() } finally { process.exit(0) }
}
process.once('SIGINT', close)
process.once('SIGTERM', close)
}
if (require.main === module) main().catch(err => {
process.stderr.write((err && err.stack) || String(err))
process.stderr.write('\n')
process.exitCode = 1
})
module.exports = { main }