Refactored handleAuthorize to accept a new parameter used to reply or not to the socket

This commit is contained in:
Andrea Baccega 2014-03-02 15:57:06 +01:00
parent 89434f29dc
commit 1e3c47d527
1 changed files with 11 additions and 8 deletions

View File

@ -40,7 +40,7 @@ var StratumClient = function(options){
handleSubscribe(message);
break;
case 'mining.authorize':
handleAuthorize(message);
handleAuthorize(message, true /*reply to socket*/);
break;
case 'mining.submit':
handleSubmit(message);
@ -87,17 +87,20 @@ var StratumClient = function(options){
);
}
function handleAuthorize(message){
function handleAuthorize(message, replyToSocket){
_this.workerIP = options.socket.address().address;
_this.workerName = message.params[0];
_this.workerPass = message.params[1];
options.authorizeFn(_this.workerIP, _this.workerName, _this.workerPass, function(result) {
_this.authorized = (!result.error && result.authorized);
sendJson({
id : message.id,
result : _this.authorized,
error : result.error
});
if (replyToSocket) {
sendJson({
id : message.id,
result : _this.authorized,
error : result.error
});
}
// If the authorizer wants us to close the socket lets do it.
if (result.disconnect === true) {
@ -235,7 +238,7 @@ var StratumClient = function(options){
};
this.manuallyInitClient = function (username, password) {
handleAuthorize({id: 1, params: [username, password]});
handleAuthorize({id: 1, params: [username, password]}, false /*do not reply to miner*/);
handleSubscribe({id: 2});
}
};