Skip to content

Commit

Permalink
add chickenbit to force hashwasm
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Oct 16, 2024
1 parent fc8298c commit d715479
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion copyparty/web/up2k.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var up2k = null,
m = 'will use ' + sha_js + ' instead of native sha512 due to';

try {
if (sread('nosubtle') || window.nosubtle)
throw 'chickenbit';
var cf = crypto.subtle || crypto.webkitSubtle;
cf.digest('SHA-512', new Uint8Array(1)).then(
function (x) { console.log('sha-ok'); up2k = up2k_init(cf); },
Expand Down Expand Up @@ -1358,6 +1360,10 @@ function up2k_init(subtle) {
for (var a = 0; a < Math.min(navigator.hardwareConcurrency || 4, 16); a++)
hws.push(new Worker(SR + '/.cpr/w.hash.js?_=' + TS));

if (!subtle)
for (var a = 0; a < hws.length; a++)
hws[a].postMessage('nosubtle');

console.log(hws.length + " hashers");
}

Expand Down Expand Up @@ -2579,7 +2585,7 @@ function up2k_init(subtle) {
nparts = upt.nparts,
pcar = nparts[0],
pcdr = nparts[nparts.length - 1],
maxsz = u2sz_max * 1024 * 1024;
maxsz = (u2sz_max > 1 ? u2sz_max : 2040) * 1024 * 1024;

if (t.done)
return console.log('done; skip chunk', t.name, t);
Expand Down
4 changes: 4 additions & 0 deletions copyparty/web/w.hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ catch (ex) {
function load_fb() {
subtle = null;
importScripts('deps/sha512.hw.js');
console.log('using fallback hasher');
}


Expand All @@ -29,6 +30,9 @@ var reader = null,


onmessage = (d) => {
if (d.data == 'nosubtle')
return load_fb();

if (busy)
return postMessage(["panic", 'worker got another task while busy']);

Expand Down

0 comments on commit d715479

Please sign in to comment.