-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbin.js
More file actions
executable file
·50 lines (40 loc) · 1.09 KB
/
bin.js
File metadata and controls
executable file
·50 lines (40 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
var minimist = require('minimist')
var dWebDHT = require('./')
var argv = minimist(process.argv, {
alias: {
bootstrap: 'b',
port: 'p'
}
})
if (argv.help) {
console.error(
'Usage: ddht [options]\n' +
' --bootstrap, -b host:port\n' +
' --port, -p listen-port\n' +
' --quiet'
)
process.exit(0)
}
var dWebDHTRPC = dWebDHT({
bootstrap: argv.bootstrap
})
dWebDHTRPC.on('announce', function (key, peer) {
if (!argv.quiet) console.log('announce:', key.toString('hex'), peer)
})
dWebDHTRPC.on('unannounce', function (key, peer) {
if (!argv.quiet) console.log('unannounce:', key.toString('hex'), peer)
})
dWebDHTRPC.on('lookup', function (key) {
if (!argv.quiet) console.log('lookup:', key.toString('hex'))
})
dWebDHTRPC.listen(argv.port, function () {
console.log('hyperdht listening on ' + dWebDHTRPC.address().port)
})
dWebDHTRPC.ready(function loop () {
if (!argv.quiet) console.log('bootstrapped...')
setTimeout(bootstrap, Math.floor((5 + Math.random() * 60) * 1000))
function bootstrap () {
dWebDHTRPC.bootstrap(loop)
}
})