From 7bdf3458435f313b19bdef9bf7387788579549a8 Mon Sep 17 00:00:00 2001 From: Jerry Brady Date: Mon, 7 Apr 2014 02:34:44 +0000 Subject: [PATCH] fixes to handle proxy switching accounting --- lib/pool.js | 3 +-- lib/stratum.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index f8c1315..150d491 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -687,7 +687,6 @@ var pool = module.exports = function pool(options, authorizeFn){ function (clientsToRelinquish) { clientsToRelinquish.forEach(function(cObj) { cObj.client.removeAllListeners(); - cObj.client.socket.removeAllListeners(); _this.stratumServer.removeStratumClientBySubId(cObj.subId); }); @@ -744,4 +743,4 @@ var pool = module.exports = function pool(options, authorizeFn){ }; }; -pool.prototype.__proto__ = events.EventEmitter.prototype; \ No newline at end of file +pool.prototype.__proto__ = events.EventEmitter.prototype; diff --git a/lib/stratum.js b/lib/stratum.js index d618a2c..da3b039 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -208,7 +208,6 @@ var StratumClient = function(options){ return; } - if (messageJson) { handleMessage(messageJson); } @@ -277,6 +276,12 @@ var StratumClient = function(options){ this.manuallyAuthClient = function (username, password) { handleAuthorize({id: 1, params: [username, password]}, false /*do not reply to miner*/); } + + this.manuallySetValues = function (otherClient) { + _this.extraNonce1 = otherClient.extraNonce1; + _this.previousDifficulty = otherClient.previousDifficulty; + _this.difficulty = otherClient.difficulty; + } }; StratumClient.prototype.__proto__ = events.EventEmitter.prototype; @@ -296,7 +301,7 @@ var StratumServer = exports.Server = function StratumServer(ports, connectionTim var socketTimeout = connectionTimeout * 1000; var bannedMS = banning ? banning.time * 1000 : null; - + var _this = this; var stratumClients = {}; var subscriptionCounter = SubscriptionCounter(); @@ -338,6 +343,8 @@ var StratumServer = exports.Server = function StratumServer(ports, connectionTim remoteAddress: socket.remoteAddress } ); + + stratumClients[subscriptionId] = client; _this.emit('client.connected', client); client.on('socketDisconnect', function() { @@ -403,6 +410,7 @@ var StratumServer = exports.Server = function StratumServer(ports, connectionTim var subId = _this.handleNewClient(clientObj.socket); if (subId != null) { // not banned! stratumClients[subId].manuallyAuthClient(clientObj.workerName, clientObj.workerPass); + stratumClients[subId].manuallySetValues(clientObj); } }