OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-proto-peer / scripts / vpn-boot-server.mjs

16 lines · javascript ref:
import '../lib/bare-globals.js'
import DHT from 'hyperdht'
import crypto from 'hypercore-crypto'
import b4a from 'b4a'
// 1) a bootstrap/root DHT node ON the VPN address
const boot = new DHT({ bootstrap: [], host: '10.22.0.2', port: 49999, firewalled: false })
await boot.ready()
console.log(JSON.stringify({ event: 'BOOTSTRAP_READY', addr: '10.22.0.2:49999' }))
// 2) a server that uses the VPN bootstrap
const keyPair = crypto.keyPair(crypto.hash(b4a.from('hpp-vpn-boot-seed-v1')))
const dht = new DHT({ bootstrap: ['10.22.0.2:49999'] })
const server = dht.createServer((s) => { console.log(JSON.stringify({ event: 'SERVER_GOT_CONNECTION' })); s.on('error',()=>{}); s.on('data',()=>{try{s.write(b4a.from('pong'))}catch{}}) })
await server.listen(keyPair)
console.log(JSON.stringify({ event: 'SERVER_LISTENING', firewalled: dht.firewalled }))
setTimeout(()=>process.exit(0), 40000)