-
Notifications
You must be signed in to change notification settings - Fork 6
/
distribution.js
68 lines (57 loc) · 1.94 KB
/
distribution.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
#!/usr/bin/env node
const util = require('./distribution/util/util.js');
const args = require('yargs').argv;
// Default configuration
global.nodeConfig = global.nodeConfig || {
ip: '127.0.0.1',
port: 8080,
onStart: () => {
console.log('Node started!');
},
};
/*
As a debugging tool, you can pass ip and port arguments directly.
This is just to allow for you to easily startup nodes from the terminal.
Usage:
./distribution.js --ip '127.0.0.1' --port 1234
*/
if (args.ip) {
global.nodeConfig.ip = args.ip;
}
if (args.port) {
global.nodeConfig.port = parseInt(args.port);
}
if (args.config) {
let nodeConfig = util.deserialize(args.config);
global.nodeConfig.ip = nodeConfig.ip ? nodeConfig.ip : global.nodeConfig.ip;
global.nodeConfig.port = nodeConfig.port ?
nodeConfig.port : global.nodeConfig.port;
global.nodeConfig.onStart = nodeConfig.onStart ?
nodeConfig.onStart : global.nodeConfig.onStart;
}
const distribution = {
util: require('./distribution/util/util.js'),
local: require('./distribution/local/local.js'),
node: require('./distribution/local/node.js'),
};
global.distribution = distribution;
distribution['all'] = {};
distribution['all'].status =
require('./distribution/all/status')({gid: 'all'});
distribution['all'].comm =
require('./distribution/all/comm')({gid: 'all'});
distribution['all'].gossip =
require('./distribution/all/gossip')({gid: 'all'});
distribution['all'].groups =
require('./distribution/all/groups')({gid: 'all'});
distribution['all'].routes =
require('./distribution/all/routes')({gid: 'all'});
distribution['all'].mem =
require('./distribution/all/mem')({gid: 'all'});
distribution['all'].store =
require('./distribution/all/store')({gid: 'all'});
module.exports = global.distribution;
/* The following code is run when distribution.js is run directly */
if (require.main === module) {
distribution.node.start(global.nodeConfig.onStart);
}