diff --git a/libs/apis.js b/libs/apis.js new file mode 100644 index 0000000..966fc12 --- /dev/null +++ b/libs/apis.js @@ -0,0 +1,18 @@ +var express = require('express'); +var os = require('os'); +var app = express(); + +app.get('/getstatus', function (req, res) { + res.send({ + 'loadavg': os.loadavg(), + 'freemem': os.freemem(), + }); +}); + + +module.exports = { + start: function () { + app.listen(9000); + } +} + diff --git a/libs/mposCompatibility.js b/libs/mposCompatibility.js index d139be0..51d9834 100644 --- a/libs/mposCompatibility.js +++ b/libs/mposCompatibility.js @@ -63,9 +63,9 @@ module.exports = function(logger, poolConfigs){ var sendResult = function(authorized){ cluster.workers[data.workerId].send({ - type: 'mposAuth', - callbackId: data.callbackId, - authorized: authorized + type : 'mposAuth', + callbackId : data.callbackId, + authorized : authorized }); }; diff --git a/libs/poolWorker.js b/libs/poolWorker.js index c280b6c..1469ed4 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -74,16 +74,17 @@ module.exports = function(logger){ clearTimeout(authTimeout); }; process.send({ - type: 'mposAuth', - coin: poolOptions.coin.name, - callbackId: callbackId, - workerId: cluster.worker.id, - workerName: workerName, - password: password, - authLevel: mposAuthLevel + type : 'mposAuth', + coin : poolOptions.coin.name, + callbackId : callbackId, + workerId : cluster.worker.id, + workerName : workerName, + password : password, + authLevel : mposAuthLevel }); } else{ + // if we're here than it means we're on stratumAuth: "none" or something unrecognized by the system! callback({ error: null, authorized: true, @@ -107,30 +108,30 @@ module.exports = function(logger){ logDebug(logIdentify, 'client', 'Valid share submitted, share data: ' + shareData); process.send({ - type: 'share', - share: data, - coin: poolOptions.coin.name, - isValidShare: isValidShare, - isValidBlock: isValidBlock, - solution: blockHex + type : 'share', + share : data, + coin : poolOptions.coin.name, + isValidShare : isValidShare, + isValidBlock : isValidBlock, + solution : blockHex // blockHex is undefined is this was not a valid block. }); if (isValidBlock){ logDebug(logIdentify, 'client', 'Block found, solution: ' + shareData.solution); process.send({ - type: 'block', - share: data, - coin: poolOptions.coin.name + type : 'block', + share : data, + coin : poolOptions.coin.name }); } }).on('difficultyUpdate', function(workerName, diff){ if (poolOptions.shareProcessing.mpos.enabled){ process.send({ - type: 'difficultyUpdate', - workerName: workerName, - diff: diff, - coin: poolOptions.coin.name + type : 'difficultyUpdate', + workerName : workerName, + diff : diff, + coin : poolOptions.coin.name }); } }).on('log', function(severity, logKey, logText) { diff --git a/libs/workerapi.js b/libs/workerapi.js new file mode 100644 index 0000000..9e1f732 --- /dev/null +++ b/libs/workerapi.js @@ -0,0 +1,56 @@ +var express = require('express'); +var os = require('os'); + + +function workerapi(listen) { + var _this = this; + var app = express(); + var counters = { + validShares : 0, + validBlocks : 0, + invalidShares : 0 + }; + + var lastEvents = { + lastValidShare : 0 , + lastValidBlock : 0, + lastInvalidShare : 0 + }; + + app.get('/stats', function (req, res) { + res.send({ + "clients" : Object.keys(_this.poolObj.stratumServer.getStratumClients()).length, + "counters" : counters, + "lastEvents" : lastEvents + }); + }); + + + this.start = function (poolObj) { + this.poolObj = poolObj; + this.poolObj.once('started', function () { + app.listen(listen, function (lol) { + console.log("LISTENING "); + }); + }) + .on('share', function(isValidShare, isValidBlock, shareData) { + var now = Date.now(); + if (isValidShare) { + counters.validShares ++; + lastEvents.lastValidShare = now; + if (isValidBlock) { + counters.validBlocks ++; + lastEvents.lastValidBlock = now; + } + } else { + counters.invalidShares ++; + lastEvents.lastInvalidShare = now; + } + }); + } +} + + + +module.exports = workerapi; +