Merge branch 'zone117x-master'

This commit is contained in:
Eugene@ubuntu 2014-04-03 20:17:38 +04:00
commit 0fc90d082d
3 changed files with 64 additions and 26 deletions

View File

@ -385,8 +385,14 @@ Donations
--------- ---------
To support development of this project feel free to donate :) To support development of this project feel free to donate :)
BTC: 1KRotMnQpxu3sePQnsVLRy3EraRFYfJQFR * BTC: 1KRotMnQpxu3sePQnsVLRy3EraRFYfJQFR
* LTC: LKfavSDJmwiFdcgaP1bbu46hhyiWw5oFhE
* VTC: VgW4uFTZcimMSvcnE4cwS3bjJ6P8bcTykN
* MAX: mWexUXRCX5PWBmfh34p11wzS5WX2VWvTRT
* QRK: QehPDAhzVQWPwDPQvmn7iT3PoFUGT7o8bC
* DRK: XcQmhp8ANR7okWAuArcNFZ2bHSB81jpapQ
* DOGE: DBGGVtwAAit1NPZpRm5Nz9VUFErcvVvHYW
* Cryptsy Trade Key: 254ca13444be14937b36c44ba29160bd8f02ff76
Credits Credits
------- -------

View File

@ -17,27 +17,34 @@ var listener = module.exports = function listener(options){
} }
var blockNotifyServer = net.createServer(function(c) { var blockNotifyServer = net.createServer(function(c) {
emitLog('Block listener has incoming connection'); emitLog('Block listener has incoming connection');
var data = ''; var data = '';
c.on('data', function(d){ try {
emitLog('Block listener received blocknotify data'); c.on('data', function (d) {
data += d; emitLog('Block listener received blocknotify data');
if (data.slice(-1) === '\n'){ data += d;
c.end(); if (data.slice(-1) === '\n') {
} c.end();
}); }
c.on('end', function() { });
c.on('end', function () {
emitLog('Block listener connection ended'); emitLog('Block listener connection ended');
var message = JSON.parse(data); var message = JSON.parse(data);
if (message.password === options.password){ if (message.password === options.password) {
_this.emit('hash', message); _this.emit('hash', message);
} }
else else
emitLog('Block listener received notification with incorrect password'); emitLog('Block listener received notification with incorrect password');
});
}
catch(e){
emitLog('Block listener failed to parse message ' + data);
}
});
}); });
blockNotifyServer.listen(options.port, function() { blockNotifyServer.listen(options.port, function() {
emitLog('Block notify listener server started on port ' + options.port) emitLog('Block notify listener server started on port ' + options.port)

View File

@ -14,13 +14,6 @@ module.exports = function(logger, portalConfig, poolConfigs){
var redisClients = []; var redisClients = [];
/*var algoMultipliers = {
'x11': Math.pow(2, 16),
'scrypt': Math.pow(2, 16),
'scrypt-jane': Math.pow(2,16),
'sha256': Math.pow(2, 32)
};*/
var canDoStats = true; var canDoStats = true;
Object.keys(poolConfigs).forEach(function(coin){ Object.keys(poolConfigs).forEach(function(coin){
@ -55,7 +48,6 @@ module.exports = function(logger, portalConfig, poolConfigs){
this.stats = {}; this.stats = {};
this.statsString = ''; this.statsString = '';
this.getGlobalStats = function(callback){ this.getGlobalStats = function(callback){
var allCoinStats = {}; var allCoinStats = {};
@ -76,6 +68,7 @@ module.exports = function(logger, portalConfig, poolConfigs){
var commandsPerCoin = redisComamndTemplates.length; var commandsPerCoin = redisComamndTemplates.length;
client.coins.map(function(coin){ client.coins.map(function(coin){
redisComamndTemplates.map(function(t){ redisComamndTemplates.map(function(t){
var clonedTemplates = t.slice(0); var clonedTemplates = t.slice(0);
@ -84,6 +77,7 @@ module.exports = function(logger, portalConfig, poolConfigs){
}); });
}); });
client.client.multi(redisCommands).exec(function(err, replies){ client.client.multi(redisCommands).exec(function(err, replies){
if (err){ if (err){
console.log('error with getting hashrate stats ' + JSON.stringify(err)); console.log('error with getting hashrate stats ' + JSON.stringify(err));
@ -121,6 +115,7 @@ module.exports = function(logger, portalConfig, poolConfigs){
workers: 0, workers: 0,
hashrate: 0 hashrate: 0
}, },
algos: {},
pools: allCoinStats pools: allCoinStats
}; };
@ -143,8 +138,27 @@ module.exports = function(logger, portalConfig, poolConfigs){
coinStats.hashrate = hashratePre / 1e3 | 0; coinStats.hashrate = hashratePre / 1e3 | 0;
portalStats.global.hashrate += coinStats.hashrate; portalStats.global.hashrate += coinStats.hashrate;
portalStats.global.workers += Object.keys(coinStats.workers).length; portalStats.global.workers += Object.keys(coinStats.workers).length;
/* algorithm specific global stats */
var algo = coinStats.algorithm;
if (!portalStats.algos.hasOwnProperty(algo)){
portalStats.algos[algo] = {
workers: 0,
hashrate: 0,
hashrateString: null
};
}
portalStats.algos[algo].hashrate += coinStats.hashrate;
portalStats.algos[algo].workers += Object.keys(coinStats.workers).length;
delete coinStats.hashrates; delete coinStats.hashrates;
delete coinStats.shares; delete coinStats.shares;
coinStats.hashrateString = _this.getReadableHashRateString(coinStats.hashrate);
});
Object.keys(portalStats.algos).forEach(function(algo){
var algoStats = portalStats.algos[algo];
algoStats.hashrateString = _this.getReadableHashRateString(algoStats.hashrate);
}); });
_this.stats = portalStats; _this.stats = portalStats;
@ -153,5 +167,16 @@ module.exports = function(logger, portalConfig, poolConfigs){
}); });
}; };
this.getReadableHashRateString = function(hashrate){
var i = -1;
var byteUnits = [ ' KH', ' MH', ' GH', ' TH', ' PH' ];
do {
hashrate = hashrate / 1024;
i++;
} while (hashrate > 1024);
return hashrate.toFixed(2) + byteUnits[i];
};
}; };