Archived
1
0

make miner multi threaded

This commit is contained in:
ZiRo 2016-05-18 18:54:05 +02:00
parent 7f445f81fc
commit e372893373
4 changed files with 76 additions and 29 deletions

View File

@ -1,17 +1,61 @@
var easiness = 55.0;
var miner_threads = 4;
var randoffs = 64;
onready(function(){ onready(function(){
document.getElementById("start_miner").onclick = function() { document.getElementById("start_miner").onclick = function() {
var btn = document.getElementById("start_miner"); var btn = document.getElementById("start_miner");
var label = btn.value; var label = btn.value;
btn.value = "..." btn.value = "..."
btn.disabled = true; btn.disabled = true;
var worker = new Worker("./static/mineworker.js");
worker.onmessage = function(e) {
miner_cb(e.data); var b = new Uint8Array(randoffs);
btn.value=label; window.crypto.getRandomValues(b);
btn.disabled = false; var b_cur = 0;
worker.terminate(); var b_i = 0;
var tmp = new Uint8Array(randoffs+b_i+1);
tmp.set(b)
tmp[b.length]=0
b = tmp;
var workers = new Array(miner_threads);
var worker_cb = function(e) {
if (e.data[0] == "ok") {
miner_cb(e.data[1]);
btn.value=label;
btn.disabled = false;
for (i=0; i<miner_threads; i++) {
workers[i].terminate();
}
} else {
if (b_cur >= 256) {
var tmp = new Uint8Array(randoffs+b_i+1);
tmp.set(b)
tmp[b.length]=0
b = tmp;
b_i++;
b_cur=0;
}
b[randoffs+b_i]=b_cur;
b_cur++;
var params = [b, easiness, e.data[2]];
workers[e.data[2]].postMessage(params);
}
} }
worker.postMessage(55.0); // Start the worker.
for (i=0; i<miner_threads; i++) {
b[randoffs+b_i]=b_cur;
b_cur++;
var params = [b, easiness, i];
workers[i] = new Worker("./static/mineworker.js");
workers[i].onmessage = worker_cb;
workers[i].postMessage(params); // Start the worker.
}
b_cur=4;
}; };
}); });
function miner_cb(s) { function miner_cb(s) {

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@ importScripts('./siphash-lib.js');
importScripts('./miner-js.js'); importScripts('./miner-js.js');
onmessage = function(e) { onmessage = function(e) {
var s = cuckoo["mine_cuckoo"](e.data); var s = cuckoo["mine_cuckoo"](e.data[0], e.data[1]);
s.push(e.data[2]);
postMessage(s); postMessage(s);
} }

View File

@ -620,9 +620,15 @@ parent.appendChild(post);}
/* local file: ./contrib/js/banner.js */ /* local file: ./contrib/js/banner.js */
var banner_count=3;function nntpchan_inject_banners(elem,prefix){var n=Math.floor(Math.random()*banner_count);var banner=prefix+"static/banner_"+n+".jpg";var e=document.createElement("img");e.src=banner;e.id="nntpchan_banner";elem.appendChild(e);} var banner_count=3;function nntpchan_inject_banners(elem,prefix){var n=Math.floor(Math.random()*banner_count);var banner=prefix+"static/banner_"+n+".jpg";var e=document.createElement("img");e.src=banner;e.id="nntpchan_banner";elem.appendChild(e);}
/* local file: ./contrib/js/cuckoo_miner.js */ /* local file: ./contrib/js/cuckoo_miner.js */
onready(function(){document.getElementById("start_miner").onclick=function(){var btn=document.getElementById("start_miner");var label=btn.value;btn.value="..." var easiness=55.0;var miner_threads=4;var randoffs=64;onready(function(){document.getElementById("start_miner").onclick=function(){var btn=document.getElementById("start_miner");var label=btn.value;btn.value="..."
btn.disabled=true;var worker=new Worker("./static/mineworker.js");worker.onmessage=function(e){miner_cb(e.data);btn.value=label;btn.disabled=false;worker.terminate();} btn.disabled=true;var b=new Uint8Array(randoffs);window.crypto.getRandomValues(b);var b_cur=0;var b_i=0;var tmp=new Uint8Array(randoffs+b_i+1);tmp.set(b)
worker.postMessage(55.0);};});function miner_cb(s){document.getElementById("miner_result").value=s;} tmp[b.length]=0
b=tmp;var workers=new Array(miner_threads);var worker_cb=function(e){if(e.data[0]=="ok"){miner_cb(e.data[1]);btn.value=label;btn.disabled=false;for(i=0;i<miner_threads;i++){workers[i].terminate();}}else{if(b_cur>=256){var tmp=new Uint8Array(randoffs+b_i+1);tmp.set(b)
tmp[b.length]=0
b=tmp;b_i++;b_cur=0;}
b[randoffs+b_i]=b_cur;b_cur++;var params=[b,easiness,e.data[2]];workers[e.data[2]].postMessage(params);}}
for(i=0;i<miner_threads;i++){b[randoffs+b_i]=b_cur;b_cur++;var params=[b,easiness,i];workers[i]=new Worker("./static/mineworker.js");workers[i].onmessage=worker_cb;workers[i].postMessage(params);}
b_cur=4;};});function miner_cb(s){document.getElementById("miner_result").value=s;}
/* local file: ./contrib/js/expand-image.js */ /* local file: ./contrib/js/expand-image.js */
function filenameIsImage(fname){return/\.(gif|jpeg|jpg|png|webp)/.test(fname.toLowerCase());} function filenameIsImage(fname){return/\.(gif|jpeg|jpg|png|webp)/.test(fname.toLowerCase());}
function setupInlineImage(thumb,url){if(thumb.inlineIsSetUp)return;thumb.inlineIsSetUp=true;var img=thumb.querySelector("img.thumbnail");var expanded=false;var oldurl=img.src;thumb.onclick=function(){if(expanded){img.setAttribute("class","thumbnail");img.src=oldurl;expanded=false;}else{img.setAttribute("class","expanded-thumbnail");img.src=url;expanded=true;} function setupInlineImage(thumb,url){if(thumb.inlineIsSetUp)return;thumb.inlineIsSetUp=true;var img=thumb.querySelector("img.thumbnail");var expanded=false;var oldurl=img.src;thumb.onclick=function(){if(expanded){img.setAttribute("class","thumbnail");img.src=oldurl;expanded=false;}else{img.setAttribute("class","expanded-thumbnail");img.src=url;expanded=true;}