Skip to content

Commit

Permalink
Merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
clintar committed Apr 6, 2016
2 parents 9dbff72 + ef3f842 commit f4ac57e
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 31 deletions.
5 changes: 5 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"port": 8117,
"blocks": 30,
"payments": 30,
"ssl": false,
"sslport": 8119,
"sslcert": "./certs/cert.pem",
"sslkey": "./certs/privkey.pem",
"sslca": "./certs/chain.pem",
"password": "your_password"
},

Expand Down
63 changes: 37 additions & 26 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ var logSystem = 'master';
require('./lib/exceptionWriter.js')(logSystem);


var singleModule = (function(){
var selectedModules = (function(){

var validModules = ['pool', 'api', 'unlocker', 'payments', 'chartsDataCollector'];

for (var i = 0; i < process.argv.length; i++){
if (process.argv[i].indexOf('-module=') === 0){
var moduleName = process.argv[i].split('=')[1];
if (validModules.indexOf(moduleName) > -1)
return moduleName;

log('error', logSystem, 'Invalid module "%s", valid modules: %s', [moduleName, validModules.join(', ')]);
process.exit();
var modulesStr = process.argv[i].split('=')[1];
var moduleNames = modulesStr.split(',');
for(var j = 0; j < moduleNames.length;j++)
{
var module = moduleNames[j];
if (!(validModules.indexOf(module) > -1))
{
log('error', logSystem, 'Invalid module "%s", valid modules: %s', [module, validModules.join(', ')]);
process.exit();
}
return moduleNames;
}
}
}
})();
Expand All @@ -63,25 +69,30 @@ var singleModule = (function(){

checkRedisVersion(function(){

if (singleModule){
log('info', logSystem, 'Running in single module mode: %s', [singleModule]);

switch(singleModule){
case 'pool':
spawnPoolWorkers();
break;
case 'unlocker':
spawnBlockUnlocker();
break;
case 'payments':
spawnPaymentProcessor();
break;
case 'api':
spawnApi();
break;
case 'chartsDataCollector':
spawnChartsDataCollector();
break;
if (selectedModules){
log('info', logSystem, 'Running in selected module mode: %s', [selectedModules]);
for (var i = 0; i < selectedModules.length; i++){
var selectedModule = selectedModules[i];
switch(selectedModule){
case 'pool':
spawnPoolWorkers();
break;
case 'unlocker':
spawnBlockUnlocker();
break;
case 'payments':
spawnPaymentProcessor();
break;
case 'api':
spawnApi();
break;
case 'chartsDataCollector':
spawnChartsDataCollector();
break;
case 'purchases':
spawnPurchaseProcessor();
break;
}
}
}
else{
Expand Down
119 changes: 119 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var fs = require('fs');
var http = require('http');
var https = require('https');
var url = require("url");
var zlib = require('zlib');

Expand Down Expand Up @@ -594,6 +595,117 @@ function getLogFiles(callback) {
callback(error, logs);
});
}
if(config.api.ssl == true)
{
var options = {
key: fs.readFileSync(config.api.sslkey),
cert: fs.readFileSync(config.api.sslcert),
ca: fs.readFileSync(config.api.sslca),
honorCipherOrder: true
};

var server2 = https.createServer(options, function(request, response){


if (request.method.toUpperCase() === "OPTIONS"){

response.writeHead("204", "No Content", {
"access-control-allow-origin": '*',
"access-control-allow-methods": "GET, POST, PUT, DELETE, OPTIONS",
"access-control-allow-headers": "content-type, accept",
"access-control-max-age": 10, // Seconds.
"content-length": 0,
"Strict-Transport-Security": "max-age=604800"
});

return(response.end());
}


var urlParts = url.parse(request.url, true);

switch(urlParts.pathname){
case '/stats':
var deflate = request.headers['accept-encoding'] && request.headers['accept-encoding'].indexOf('deflate') != -1;
var reply = deflate ? currentStatsCompressed : currentStats;
response.writeHead("200", {
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Content-Encoding': deflate ? 'deflate' : '',
'Content-Length': reply.length
});
response.end(reply);
break;
case '/live_stats':
response.writeHead(200, {
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'no-cache',
'Content-Type': 'application/json',
'Content-Encoding': 'deflate',
'Connection': 'keep-alive'
});
var uid = Math.random().toString();
liveConnections[uid] = response;
response.on("finish", function() {
delete liveConnections[uid];
});
break;
case '/stats_address':
handleMinerStats(urlParts, response);
break;
case '/get_payments':
handleGetPayments(urlParts, response);
break;
case '/get_blocks':
handleGetBlocks(urlParts, response);
break;
case '/get_payment':
handleGetPayment(urlParts, response);
break;
case '/admin_stats':
if (!authorize(request, response))
return;
handleAdminStats(response);
break;
case '/admin_monitoring':
if(!authorize(request, response)) {
return;
}
handleAdminMonitoring(response);
break;
case '/admin_log':
if(!authorize(request, response)) {
return;
}
handleAdminLog(urlParts, response);
break;
case '/admin_users':
if(!authorize(request, response)) {
return;
}
handleAdminUsers(response);
break;

case '/miners_hashrate':
if (!authorize(request, response))
return;
handleGetMinersHashrate(response);
break;
case '/miners_donationHashrate':
if (!authorize(request, response))
return;
handleGetDonationsHashrate(response);
break;
default:
response.writeHead(404, {
'Access-Control-Allow-Origin': '*'
});
response.end('Invalid API call');
break;
}
});
}

var server = http.createServer(function(request, response){

Expand Down Expand Up @@ -694,3 +806,10 @@ initMonitoring();
server.listen(config.api.port, function(){
log('info', logSystem, 'API started & listening on port %d', [config.api.port]);
});
if(config.api.ssl == true)
{
server2.listen(config.api.sslport, function(){
log('info', logSystem, 'API started & listening on port %d', [config.api.port]);
});
}

4 changes: 2 additions & 2 deletions website-example/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
hashrate = hashrate || 0;
var i = 0;
var byteUnits = [' H', ' KH', ' MH', ' GH', ' TH', ' PH' ];
while(hashrate > 1024) {
hashrate = hashrate / 1024;
while(hashrate > 1000) {
hashrate = hashrate / 1000;
i++;
}
return parseInt(hashrate).toFixed(2) + byteUnits;
Expand Down
6 changes: 3 additions & 3 deletions website-example/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ <h4 class="yourStats">Payments</h4>
function getReadableHashRateString(hashrate){
var i = 0;
var byteUnits = [' H', ' KH', ' MH', ' GH', ' TH', ' PH' ];
while (hashrate > 1024){
hashrate = hashrate / 1024;
while (hashrate > 1000){
hashrate = hashrate / 1000;
i++;
}
return hashrate.toFixed(2) + byteUnits[i];
Expand Down Expand Up @@ -444,7 +444,7 @@ <h4 class="yourStats">Payments</h4>

function calcEstimateProfit(){
try {
var rateUnit = Math.pow(1024,parseInt($('#calcHashUnit').data('mul')));
var rateUnit = Math.pow(1000,parseInt($('#calcHashUnit').data('mul')));
var hashRate = parseFloat($('#calcHashRate').val()) * rateUnit;
var profit = (hashRate * 86400 / lastStats.network.difficulty) * lastStats.network.reward;
if (profit) {
Expand Down

0 comments on commit f4ac57e

Please sign in to comment.