Updated git info for node-stratum-pool and refactored website/api structure.
This commit is contained in:
parent
82844687ac
commit
72c26213a1
|
@ -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
|
||||
|
|
40
libs/api.js
40
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
|
||||
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();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
|
@ -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 = {};
|
||||
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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": "*",
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
}
|
||||
},
|
||||
"3032": {
|
||||
"diff": 32
|
||||
"diff": 16
|
||||
},
|
||||
"3256": {
|
||||
"diff": 256
|
||||
|
|
|
@ -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')
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue