From 72c26213a19451b971b1a19203cad233bed52f09 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 25 Mar 2014 16:21:17 -0600 Subject: [PATCH] Updated git info for node-stratum-pool and refactored website/api structure. --- README.md | 6 +-- libs/api.js | 40 +++++++++++++++- libs/stats.js | 4 +- libs/website.js | 53 +++++++--------------- package.json | 2 +- pool_configs/litecoin_testnet_example.json | 2 +- website/static/main.js | 2 +- 7 files changed, 64 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 46b967a..4b6995b 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ front-end website. #### Features -* For the pool server it uses the highly efficient [node-stratum](https://github.com/zone117x/node-stratum) module which +* For the pool server it uses the highly efficient [node-stratum-pool](https://github.com/zone117x/node-stratum-pool) module which supports vardiff, POW & POS, transaction messages, anti-DDoS, IP banning, several hashing algorithms. * The portal has an [MPOS](https://github.com/MPOS/php-mpos) compatibility mode so that the it can @@ -328,7 +328,7 @@ Description of options: You can create as many of these pool config files as you want (such as one pool per coin you which to operate). If you are creating multiple pools, ensure that they have unique stratum ports. -For more information on these configuration options see the [pool module documentation](https://github.com/zone117x/node-stratum#module-usage) +For more information on these configuration options see the [pool module documentation](https://github.com/zone117x/node-stratum-pool#module-usage) @@ -373,7 +373,7 @@ Credits ------- * [vekexasia](https://github.com/vekexasia) - co-developer & great tester * [TheSeven](https://github.com/TheSeven) - answering an absurd amount of my questions and being a very helpful gentleman -* Those that contributed to [node-stratum](/zone117x/node-stratum) +* Those that contributed to [node-stratum-pool](/zone117x/node-stratum-pool) License diff --git a/libs/api.js b/libs/api.js index 84636c4..092d9b8 100644 --- a/libs/api.js +++ b/libs/api.js @@ -1 +1,39 @@ -//create the stats object in here. then let the website use this object. that way we can have a config for stats and website separate :D \ No newline at end of file +var redis = require('redis'); +var async = require('async'); + +var stats = require('./stats.js'); + +module.exports = function(logger, portalConfig, poolConfigs){ + + + var _this = this; + + var portalStats = this.stats = new stats(logger, portalConfig, poolConfigs); + + this.liveStatConnections = {}; + + this.handleApiRequest = function(req, res, next){ + switch(req.params.method){ + case 'stats': + res.end(portalStats.statsString); + return; + case 'live_stats': + res.writeHead(200, { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-cache', + 'Connection': 'keep-alive' + }); + res.write('\n'); + var uid = Math.random().toString(); + _this.liveStatConnections[uid] = res; + req.on("close", function() { + delete _this.liveStatConnections[uid]; + }); + + return; + default: + next(); + } + }; + +}; \ No newline at end of file diff --git a/libs/stats.js b/libs/stats.js index eb42833..177c82a 100644 --- a/libs/stats.js +++ b/libs/stats.js @@ -11,7 +11,9 @@ module.exports = function(logger, portalConfig, poolConfigs){ 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) }; @@ -38,7 +40,7 @@ module.exports = function(logger, portalConfig, poolConfigs){ this.statsString = ''; - this.getStats = function(callback){ + this.getGlobalStats = function(callback){ var allCoinStats = {}; diff --git a/libs/website.js b/libs/website.js index a018fcf..5e6cbfe 100644 --- a/libs/website.js +++ b/libs/website.js @@ -31,7 +31,7 @@ var async = require('async'); var dot = require('dot'); var express = require('express'); -var stats = require('./stats.js'); +var api = require('./api.js'); module.exports = function(logger){ @@ -41,7 +41,8 @@ module.exports = function(logger){ var websiteConfig = portalConfig.website; - var portalStats = new stats(logger, portalConfig, poolConfigs); + var portalApi = new api(logger, portalConfig, poolConfigs); + var portalStats = portalApi.stats; var logSystem = 'Website'; @@ -106,17 +107,17 @@ module.exports = function(logger){ }); - portalStats.getStats(function(){ + portalStats.getGlobalStats(function(){ readPageFiles(Object.keys(pageFiles)); }); var buildUpdatedWebsite = function(){ - portalStats.getStats(function(){ + portalStats.getGlobalStats(function(){ processTemplates(); var statData = 'data: ' + JSON.stringify(portalStats.stats) + '\n\n'; - for (var uid in liveStatConnections){ - var res = liveStatConnections[uid]; + for (var uid in portalApi.liveStatConnections){ + var res = portalApi.liveStatConnections[uid]; res.write(statData); } @@ -146,43 +147,21 @@ module.exports = function(logger){ }; - var liveStatConnections = {}; + app.get('/get_page', function(req, res, next){ + var requestedPage = getPage(req.query.id); + if (requestedPage){ + res.end(requestedPage); + return; + } + next(); + }); app.get('/:page', route); app.get('/', route); app.get('/api/:method', function(req, res, next){ - - switch(req.params.method){ - case 'get_page': - var requestedPage = getPage(req.query.id); - if (requestedPage){ - res.end(requestedPage); - return; - } - case 'stats': - res.end(portalStats.statsString); - return; - case 'live_stats': - res.writeHead(200, { - 'Content-Type': 'text/event-stream', - 'Cache-Control': 'no-cache', - 'Connection': 'keep-alive' - }); - res.write('\n'); - var uid = Math.random().toString(); - liveStatConnections[uid] = res; - req.on("close", function() { - delete liveStatConnections[uid]; - }); - - return; - default: - next(); - } - - //res.send('you did api method ' + req.params.method); + portalApi.handleApiRequest(req, res, next); }); app.use('/static', express.static('website/static')); diff --git a/package.json b/package.json index af44f45..c63ae63 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "url": "https://github.com/zone117x/node-open-mining-portal.git" }, "dependencies": { - "stratum-pool": "https://github.com/zone117x/node-stratum/archive/master.tar.gz", + "stratum-pool": "https://github.com/zone117x/node-stratum-pool/archive/master.tar.gz", "dateformat": "*", "node-json-minify": "*", "posix": "*", diff --git a/pool_configs/litecoin_testnet_example.json b/pool_configs/litecoin_testnet_example.json index 1c73847..ba66286 100644 --- a/pool_configs/litecoin_testnet_example.json +++ b/pool_configs/litecoin_testnet_example.json @@ -60,7 +60,7 @@ } }, "3032": { - "diff": 32 + "diff": 16 }, "3256": { "diff": 256 diff --git a/website/static/main.js b/website/static/main.js index df5c7d7..a87d63e 100644 --- a/website/static/main.js +++ b/website/static/main.js @@ -5,7 +5,7 @@ $(function(){ if (pushSate) history.pushState(null, null, '/' + page); $('.selected').removeClass('selected'); $('a[href="/' + page + '"]').parent().addClass('selected') - $.get("/api/get_page", {id: page}, function(data){ + $.get("/get_page", {id: page}, function(data){ $('#page').html(data); }, 'html') };