Skip to content
This repository has been archived by the owner on May 12, 2018. It is now read-only.

Commit

Permalink
Long polling support
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed May 11, 2014
1 parent 3e261ba commit a912a18
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{

"difficulty": 5,
"difficulty": 7,

"poolPort": 5555,

"useLongPolling": false,

"blockRefreshInterval": 1000,

"daemon": {
Expand Down
47 changes: 42 additions & 5 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ function processBlockTemplate(template){
CurrentJob.extraNonce = 0;
CurrentJob.reserveOffset = template.reserved_offset;
CurrentJob.buffer = new Buffer(CurrentJob.blob, 'hex');

for (var minerId in connectedMiners){
var miner = connectedMiners[minerId];
if (miner.longPoll){
console.log('sending new job to longpolled miner');
clearInterval(miner.longPoll.timeout);
miner.longPoll.reply(null, {
blob: CurrentJob.nextBlob(),
job_id: CurrentJob.id,
target: miner.getTargetHex()
});
miner.lastJobId = CurrentJob.id;
miner.extraNonce = CurrentJob.extraNonce;
delete miner.longPoll;
}
}

}

function jobRefresh(){
Expand Down Expand Up @@ -219,6 +236,12 @@ function handleMinerMethod(id, method, params, res){
res.end(sendData);
};

res.on('close', function(){
sendReply = function(){
console.log('tried writing to dead socket');
};
});

switch(method){
case 'login':
if (!params.login){
Expand Down Expand Up @@ -252,11 +275,25 @@ function handleMinerMethod(id, method, params, res){
return;
}
if (miner.lastJobId === CurrentJob.id) {
sendReply(null, {
blob: '',
job_id: '',
target: ''
});
if (!config.useLongPolling){
sendReply(null, {
blob: '',
job_id: '',
target: ''
});
return;
}
miner.longPoll = {
timeout: setTimeout(function(){
delete miner.longPoll;
sendReply(null, {
blob: '',
job_id: '',
target: ''
});
}, 5000),
reply: sendReply
};
return;
}
sendReply(null, {
Expand Down

0 comments on commit a912a18

Please sign in to comment.