-
Notifications
You must be signed in to change notification settings - Fork 1
/
distribution.js
75 lines (63 loc) · 2 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
69
70
71
72
73
74
75
#!/usr/bin/env node
const util = require("./distribution/util/util.js");
const args = require("yargs").argv;
global.https = require("https");
// Default configuration
global.nodeConfig = global.nodeConfig || {
ip: "127.0.0.1",
port: 8080,
onStart: () => {
console.log("Node started!");
},
};
global.nodeState = {};
// global.nodeState.storeDir = 'store/';
/*
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:
node 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.nid) {
global.nodeConfig.nid = args.nid;
}
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.nid = nodeConfig.nid
? nodeConfig.nid
: global.nodeConfig.nid;
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 = {
comm: require("./distribution/all/comm.js")(),
groups: require("./distribution/all/groups.js")(),
status: require("./distribution/all/status.js")(),
routes: require("./distribution/all/routes.js")(),
gossip: require("./distribution/all/gossip.js")(),
mem: require("./distribution/all/mem.js")(),
store: require("./distribution/all/store.js")(),
mr: require("./distribution/all/mr.js")(),
};
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);
}