This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (50 loc) · 1.42 KB
/
index.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
const ClusterModel = require('./src/Cluster');
const logger = require('./src/Utils/logger');
const SignalModel = require('./src/Utils/signal');
const BlockChainModel = require('./src/Models/Blockchain');
const NetworkerModel = require('./src/Models/Networker');
/**
* This function prevents fast exit from cluster (CTRL + C),
* sends information about cluster disconnect to signaling server
* @param cluster
*/
const handleClusterExit = (cluster) => {
process.on('SIGINT', function() {
process.stdout.write('\033c');
logger.warn('Detected CTRL+C COMBINATION, closing nicely... \n \t Waiting for other processes to end...');
cluster.networker.disconnect()
.then((msg)=>{
logger.info(`${msg}`);
process.exit(1);
})
.catch((error) => {
logger.log('error', `Error while disconnecting from server, aborting...` + error);
});
});
};
const Cluster = () => {
return new ClusterModel();
};
const Signal = () => {
return SignalModel;
};
const Blockchain = () => {
return new BlockChainModel();
};
const Networker = (blockchain, signal = false, ip = null, port = null, name = null) => {
return new NetworkerModel(
blockchain,
signal,
ip,
port,
name
);
};
//todo add wallet
module.exports = {
Cluster,
Signal,
Networker,
Blockchain,
handleClusterExit
};