-
Notifications
You must be signed in to change notification settings - Fork 24
/
grape.js
executable file
·104 lines (98 loc) · 2.55 KB
/
grape.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env node
'use strict'
const _ = require('lodash')
const Grape = require('../lib/Grape')
const program = require('yargs')
.option('b', {
describe: 'Listening host',
alias: 'bind',
type: 'string'
})
.option('dp', {
describe: 'DHT listening port',
alias: 'dht_port',
type: 'number',
demand: true
})
.option('dc', {
describe: 'DHT concurrency',
alias: 'dht_concurrency',
type: 'number'
})
.option('dht_maxTables', {
describe: 'DHT max tables',
type: 'number'
})
.option('dht_maxValues', {
describe: 'DHT max values',
type: 'number'
})
.option('bn', {
describe: 'Bootstrap nodes',
alias: 'bootstrap',
type: 'string',
demand: true
})
.option('aph', {
describe: 'HTTP api port',
alias: 'api_port',
type: 'number',
demand: true
})
.option('dht_peer_maxAge', {
describe: 'Max age for peers in DHT',
alias: 'dpa',
type: 'number'
})
.option('cache_maxAge', {
describe: 'Maximum cache age',
type: 'number'
})
.option('dnl', {
alias: 'dht_nodeLiveness',
describe: 'Interval in ms to check for dead nodes',
type: 'number'
})
.option('check_maxPayloadSize', {
describe: 'Limit for max payload size',
type: 'number'
})
.help('help')
.version()
.example('grape --dp 20001 --dc 32 --aph 30001 --bn \'127.0.0.1:20002,127.0.0.1:20003\'')
.example('grape --dp 20002 --dc 32 --b 127.0.0.1 --aph 40001 --bn \'127.0.0.1:20001,127.0.0.1:20003\'')
.example('grape --dp 20003 --dc 32 --aph 50001 --bn \'127.0.0.1:20001,127.0.0.1:20002\'')
.usage('Usage: $0 --dp <dht-port> --aph <http-api-port> --bn <nodes> [--b bind-to-address]')
.argv
const dhtPort = program.dp
const apiPort = program.aph
const bind = program.b
const maxDhtPeerAge = program.dpa
const maxCacheAge = program.cache_maxAge
const maxDhtTables = program.dht_maxTables
const maxDhtValues = program.dht_maxValues
const maxDhtConcurrency = program.dht_concurrency
const dhtNodeLiveness = program.dnl
const maxPayloadSize = program.check_maxPayloadSize
const dhtBoostrap = _.reduce((program.bn || '').split(','), (acc, e) => {
if (e) {
acc.push(e)
}
return acc
}, [])
const g = new Grape({
host: bind,
dht_port: dhtPort,
dht_bootstrap: dhtBoostrap,
dht_maxTables: maxDhtTables,
dht_maxValues: maxDhtValues,
dht_concurrency: maxDhtConcurrency,
dht_nodeLiveness: dhtNodeLiveness,
api_port: apiPort,
dht_peer_maxAge: maxDhtPeerAge,
cache_maxAge: maxCacheAge,
check_maxPayloadSize: maxPayloadSize
})
g.start((err) => {
if (err) throw err
})