Updated readme desc

This commit is contained in:
Matt 2014-03-06 01:50:43 -07:00
parent fce8d5b1b8
commit 7dbcc4f863
6 changed files with 28 additions and 11 deletions

View File

@ -87,6 +87,7 @@ var pool = Stratum.createPool({
//instanceId: 37, //Recommend not using this because a crypto-random one will be generated //instanceId: 37, //Recommend not using this because a crypto-random one will be generated
"connectionTimeout": 120, //Remove workers that haven't been in contact for this many seconds
/* Each pool can have as many ports for your miners to connect to as you wish. Each port can /* Each pool can have as many ports for your miners to connect to as you wish. Each port can
be configured to use its own pool difficulty and variable difficulty settings. varDiff is be configured to use its own pool difficulty and variable difficulty settings. varDiff is

View File

@ -39,6 +39,8 @@ function DaemonInterface(options){
return !results.error; return !results.error;
}); });
callback(allOnline); callback(allOnline);
if (!allOnline)
_this.emit('connectionFailed', results);
}); });
} }

View File

@ -3,7 +3,9 @@ var events = require('events');
var pool = require('./pool.js'); var pool = require('./pool.js');
exports.daemon = require('./daemon.js');
exports.createPool = function(poolOptions, authorizeFn){ exports.createPool = function(poolOptions, authorizeFn){
var newPool = new pool(poolOptions, authorizeFn); var newPool = new pool(poolOptions, authorizeFn);
return newPool; return newPool;
}; };

View File

@ -4,6 +4,10 @@ var events = require('events');
var util = require('./util.js'); var util = require('./util.js');
//Example of p2p in node from TheSeven: http://paste.pm/e54.js
var commandStringBuffer = function(s){ var commandStringBuffer = function(s){
var buff = new Buffer(12); var buff = new Buffer(12);
buff.fill(0); buff.fill(0);

View File

@ -317,8 +317,8 @@ var pool = module.exports = function pool(options, authorizeFn){
} }
}); });
}).on('connectionFailed', function(instance){ }).on('connectionFailed', function(error){
emitErrorLog('system','Failed to start daemon'); emitErrorLog('system','Failed to connect daemon(s): ' + JSON.stringify(error));
}).on('error', function(message){ }).on('error', function(message){
emitErrorLog('system', message); emitErrorLog('system', message);
}); });
@ -328,7 +328,7 @@ var pool = module.exports = function pool(options, authorizeFn){
function StartStratumServer(){ function StartStratumServer(){
_this.stratumServer = new stratum.Server(options.ports, authorizeFn); _this.stratumServer = new stratum.Server(options.ports, options.connectionTimeout, authorizeFn);
_this.stratumServer.on('started', function(){ _this.stratumServer.on('started', function(){
emitLog('system','Stratum server started on port(s): ' + Object.keys(options.ports).join(', ')); emitLog('system','Stratum server started on port(s): ' + Object.keys(options.ports).join(', '));
_this.emit('started'); _this.emit('started');
@ -480,5 +480,4 @@ var pool = module.exports = function pool(options, authorizeFn){
} }
}; };
pool.prototype.__proto__ = events.EventEmitter.prototype; pool.prototype.__proto__ = events.EventEmitter.prototype;
pool.daemon = daemon;

View File

@ -30,6 +30,9 @@ var StratumClient = function(options){
var _this = this; var _this = this;
this.lastActivity = Date.now();
(function init(){ (function init(){
setupSocket(); setupSocket();
})(); })();
@ -43,15 +46,16 @@ var StratumClient = function(options){
handleAuthorize(message, true /*reply to socket*/); handleAuthorize(message, true /*reply to socket*/);
break; break;
case 'mining.submit': case 'mining.submit':
_this.lastActivity = Date.now();
handleSubmit(message); handleSubmit(message);
break; break;
case 'mining.get_transactions': /*case 'mining.get_transactions':
sendJson({ sendJson({
id : null, id : null,
result : [], result : [],
error : true error : true
}); });
break; break;*/
default: default:
_this.emit('unknownStratumMethod', message); _this.emit('unknownStratumMethod', message);
break; break;
@ -254,7 +258,7 @@ StratumClient.prototype.__proto__ = events.EventEmitter.prototype;
* - 'client.disconnected'(StratumClientInstance) - when a miner disconnects. Be aware that the socket cannot be used anymore. * - 'client.disconnected'(StratumClientInstance) - when a miner disconnects. Be aware that the socket cannot be used anymore.
* - 'started' - when the server is up and running * - 'started' - when the server is up and running
**/ **/
var StratumServer = exports.Server = function StratumServer(ports, authorizeFn){ var StratumServer = exports.Server = function StratumServer(ports, connectionTimeout, authorizeFn){
//private members //private members
@ -300,8 +304,13 @@ var StratumServer = exports.Server = function StratumServer(ports, authorizeFn){
for (var clientId in stratumClients) { for (var clientId in stratumClients) {
// if a client gets disconnected WHILE doing this loop a crash might happen. // if a client gets disconnected WHILE doing this loop a crash might happen.
// 'm not sure if that can ever happn but an if here doesn't hurt! // 'm not sure if that can ever happn but an if here doesn't hurt!
if (typeof(stratumClients[clientId]) !== 'undefined') { var client = stratumClients[clientId];
stratumClients[clientId].sendMiningJob(jobParams); if (typeof(client) !== 'undefined') {
if (Date.now() - client.lastActivity > connectionTimeout){
client.socket.end();
return;
}
client.sendMiningJob(jobParams);
} }
} }
}; };