OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-proto-peer / scripts / bt-client.mjs

16 lines · javascript ref:
import '../lib/bare-globals.js'
import DHT from 'hyperdht'
import crypto from 'hypercore-crypto'
import b4a from 'b4a'
const seed = crypto.hash(b4a.from('better-test-seed-v2'))
const serverPubKey = DHT.keyPair(seed).publicKey
const dht = new DHT()
const t0 = Date.now()
console.log(JSON.stringify({ event: 'CLIENT_START', firewalled: dht.firewalled }))
const socket = dht.connect(serverPubKey)
socket.on('open', () => { console.log(JSON.stringify({ event: 'CLIENT_OPEN', ms: Date.now() - t0 })); socket.end() })
socket.on('error', (e) => console.log(JSON.stringify({ event: 'CLIENT_ERROR', code: e.code, msg: e.message, ms: Date.now() - t0 })))
socket.on('close', () => console.log(JSON.stringify({ event: 'CLIENT_CLOSE', ms: Date.now() - t0 })))
const iv = setInterval(() => console.log(JSON.stringify({ event: 'CLIENT_STATUS', firewalled: dht.firewalled, ms: Date.now() - t0 })), 20000)
setTimeout(() => { clearInterval(iv); console.log(JSON.stringify({ event: 'CLIENT_DONE' })); process.exit(0) }, 100000)