-
Notifications
You must be signed in to change notification settings - Fork 4
/
proxy.js
67 lines (51 loc) · 2.1 KB
/
proxy.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
const cluster = require("cluster");
const totalCPUs = require("os").cpus().length;
const minerListener = require('./lib/miner_listener.js');
const config = require('./config.json');
config.version = "0.1.4";
// TODO, stratumProxy/poolConnection engine (50%)
// api/stats engine (0%)
// validate config
if (cluster.isMaster) {
console.log(`VerusProxy v${config.version} by hellcatz`);
//console.log(`Master ${process.pid} is running`);
let my_fork = function() {
let worker = cluster.fork();
// example fork inter-process communications
worker.on('message', function(msg){
console.log('from worker:', msg);
//worker.send({chat: "Master got worker message"});
});
return worker;
};
// allow multithreading for big farms with 1000's of workers
let numThreads = 1; // default to 1, simple home proxy mode
if (config.threads && typeof config.threads === 'string') {
// assume string is "auto", leave 1 thread idle
numThreads = totalCPUs - 1;
} else if (config.threads && typeof config.threads === 'number') {
numThreads = Math.min(Math.max(config.threads, 1), totalCPUs);
}
console.log(`Using ${numThreads} out of ${totalCPUs} total threads`);
// fork the threads!
for (let i = 0; i < numThreads; i++) {
my_fork();
}
cluster.on("exit", (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died, forking again`);
my_fork();
});
} else {
//console.log(`Worker ${process.pid} is running`);
// example fork inter-process communications
process.on('message', function(msg) {
console.log('from master:', msg);
});
//process.send({chat: "Hello master from worker!"});
if (!config.notifyTimeoutMs) {
config.notifyTimeoutMs = 15000;
}
// start stratum mining server for this fork
minerListener.createMiningListener(config);
// TODO, monitor ssl certificates for updates and udpdate our listener's TLS options ...
}