mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 17:12:13 -06:00
add keepalive handshakes
This commit is contained in:
parent
a5120d4f6f
commit
83b4b70ef4
|
@ -148,7 +148,7 @@ summary: all planned features work! now please enjoy the bloatening
|
||||||
|
|
||||||
small collection of user feedback
|
small collection of user feedback
|
||||||
|
|
||||||
`good enough`, `surprisingly correct`, `certified good software`, `guaranteed to 400gb ™`, `why`
|
`good enough`, `surprisingly correct`, `certified good software`, `just works`, `why`
|
||||||
|
|
||||||
|
|
||||||
# bugs
|
# bugs
|
||||||
|
|
|
@ -225,7 +225,7 @@ function U2pvis(act, btns) {
|
||||||
this.hashed = function (fobj) {
|
this.hashed = function (fobj) {
|
||||||
var fo = this.tab[fobj.n],
|
var fo = this.tab[fobj.n],
|
||||||
nb = fo.bt * (++fo.nh / fo.cb.length),
|
nb = fo.bt * (++fo.nh / fo.cb.length),
|
||||||
p = this.perc(nb, 0, fobj.size, fobj.t1);
|
p = this.perc(nb, 0, fobj.size, fobj.t_hashing);
|
||||||
|
|
||||||
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
||||||
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
||||||
|
@ -248,7 +248,7 @@ function U2pvis(act, btns) {
|
||||||
fo.cb[nchunk] = cbd;
|
fo.cb[nchunk] = cbd;
|
||||||
fo.bd += delta;
|
fo.bd += delta;
|
||||||
|
|
||||||
var p = this.perc(fo.bd, fo.bd0, fo.bt, fobj.t3);
|
var p = this.perc(fo.bd, fo.bd0, fo.bt, fobj.t_uploading);
|
||||||
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
fo.hp = '{0}%, {1}, {2} MB/s'.format(
|
||||||
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
p[0].toFixed(2), p[1], p[2].toFixed(2)
|
||||||
);
|
);
|
||||||
|
@ -715,8 +715,7 @@ function up2k_init(subtle) {
|
||||||
|
|
||||||
pf.push(name);
|
pf.push(name);
|
||||||
dn.file(function (fobj) {
|
dn.file(function (fobj) {
|
||||||
var idx = pf.indexOf(name);
|
apop(pf, name);
|
||||||
pf.splice(idx, 1);
|
|
||||||
try {
|
try {
|
||||||
if (fobj.size > 0) {
|
if (fobj.size > 0) {
|
||||||
good.push([fobj, name]);
|
good.push([fobj, name]);
|
||||||
|
@ -739,7 +738,7 @@ function up2k_init(subtle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function gotallfiles(good_files, bad_files) {
|
function gotallfiles(good_files, bad_files) {
|
||||||
if (bad_files.length > 0) {
|
if (bad_files.length) {
|
||||||
var ntot = bad_files.length + good_files.length,
|
var ntot = bad_files.length + good_files.length,
|
||||||
msg = 'These {0} files (of {1} total) were skipped because they are empty:\n'.format(bad_files.length, ntot);
|
msg = 'These {0} files (of {1} total) were skipped because they are empty:\n'.format(bad_files.length, ntot);
|
||||||
|
|
||||||
|
@ -837,22 +836,25 @@ function up2k_init(subtle) {
|
||||||
//
|
//
|
||||||
|
|
||||||
function handshakes_permitted() {
|
function handshakes_permitted() {
|
||||||
// verification
|
if (!st.todo.handshake.length)
|
||||||
if (st.todo.handshake.length &&
|
|
||||||
st.todo.handshake[0].t4)
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ((multitask ? 2 : 0) <
|
var cd = st.todo.handshake[0].cooldown;
|
||||||
st.todo.upload.length +
|
if (cd && cd - Date.now() > 0)
|
||||||
st.busy.upload.length)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// keepalive or verify
|
||||||
|
if (st.todo.handshake[0].keepalive ||
|
||||||
|
st.todo.handshake[0].t_uploaded)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (parallel_uploads <
|
if (parallel_uploads <
|
||||||
st.busy.handshake.length)
|
st.busy.handshake.length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var cd = st.todo.handshake.length ? st.todo.handshake[0].cooldown : 0;
|
if ((multitask ? parallel_uploads : 0) <
|
||||||
if (cd && cd - Date.now() > 0)
|
st.todo.upload.length +
|
||||||
|
st.busy.upload.length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -887,13 +889,14 @@ function up2k_init(subtle) {
|
||||||
clearTimeout(tto);
|
clearTimeout(tto);
|
||||||
running = true;
|
running = true;
|
||||||
while (window['vis_exh']) {
|
while (window['vis_exh']) {
|
||||||
var is_busy = 0 !=
|
var now = Date.now(),
|
||||||
st.todo.hash.length +
|
is_busy = 0 !=
|
||||||
st.todo.handshake.length +
|
st.todo.hash.length +
|
||||||
st.todo.upload.length +
|
st.todo.handshake.length +
|
||||||
st.busy.hash.length +
|
st.todo.upload.length +
|
||||||
st.busy.handshake.length +
|
st.busy.hash.length +
|
||||||
st.busy.upload.length;
|
st.busy.handshake.length +
|
||||||
|
st.busy.upload.length;
|
||||||
|
|
||||||
if (was_busy != is_busy) {
|
if (was_busy != is_busy) {
|
||||||
was_busy = is_busy;
|
was_busy = is_busy;
|
||||||
|
@ -904,7 +907,6 @@ function up2k_init(subtle) {
|
||||||
|
|
||||||
if (flag) {
|
if (flag) {
|
||||||
if (is_busy) {
|
if (is_busy) {
|
||||||
var now = Date.now();
|
|
||||||
flag.take(now);
|
flag.take(now);
|
||||||
if (!flag.ours)
|
if (!flag.ours)
|
||||||
return defer();
|
return defer();
|
||||||
|
@ -916,28 +918,46 @@ function up2k_init(subtle) {
|
||||||
|
|
||||||
var mou_ikkai = false;
|
var mou_ikkai = false;
|
||||||
|
|
||||||
if (st.busy.handshake.length > 0 &&
|
if (st.busy.handshake.length &&
|
||||||
st.busy.handshake[0].busied < Date.now() - 30 * 1000
|
st.busy.handshake[0].t_busied < now - 30 * 1000
|
||||||
) {
|
) {
|
||||||
console.log("retrying stuck handshake");
|
console.log("retrying stuck handshake");
|
||||||
var t = st.busy.handshake.shift();
|
var t = st.busy.handshake.shift();
|
||||||
st.todo.handshake.unshift(t);
|
st.todo.handshake.unshift(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var nprev = -1;
|
||||||
|
for (var a = 0; a < st.todo.upload.length; a++) {
|
||||||
|
var nf = st.todo.upload[a].nfile;
|
||||||
|
if (nprev == nf)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
nprev = nf;
|
||||||
|
var t = st.files[nf];
|
||||||
|
if (t.t_busied &&
|
||||||
|
now - t.t_busied > 1000 * 30 &&
|
||||||
|
now - t.t_handshake > 1000 * (21600 - 1800)
|
||||||
|
) {
|
||||||
|
apop(st.todo.handshake, t);
|
||||||
|
st.todo.handshake.unshift(t);
|
||||||
|
t.keepalive = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (handshakes_permitted() &&
|
if (handshakes_permitted() &&
|
||||||
st.todo.handshake.length) {
|
st.todo.handshake.length) {
|
||||||
exec_handshake();
|
exec_handshake();
|
||||||
mou_ikkai = true;
|
mou_ikkai = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st.todo.upload.length > 0 &&
|
if (st.todo.upload.length &&
|
||||||
st.busy.upload.length < parallel_uploads) {
|
st.busy.upload.length < parallel_uploads) {
|
||||||
exec_upload();
|
exec_upload();
|
||||||
mou_ikkai = true;
|
mou_ikkai = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashing_permitted() &&
|
if (hashing_permitted() &&
|
||||||
st.todo.hash.length > 0 &&
|
st.todo.hash.length &&
|
||||||
!st.busy.hash.length) {
|
!st.busy.hash.length) {
|
||||||
exec_hash();
|
exec_hash();
|
||||||
mou_ikkai = true;
|
mou_ikkai = true;
|
||||||
|
@ -1073,7 +1093,7 @@ function up2k_init(subtle) {
|
||||||
|
|
||||||
if (handled) {
|
if (handled) {
|
||||||
pvis.move(t.n, 'ng');
|
pvis.move(t.n, 'ng');
|
||||||
st.busy.hash.splice(st.busy.hash.indexOf(t), 1);
|
apop(st.busy.hash, t);
|
||||||
st.bytes.uploaded += t.size;
|
st.bytes.uploaded += t.size;
|
||||||
return tasker();
|
return tasker();
|
||||||
}
|
}
|
||||||
|
@ -1106,15 +1126,15 @@ function up2k_init(subtle) {
|
||||||
t.hash.push(hashtab[a]);
|
t.hash.push(hashtab[a]);
|
||||||
}
|
}
|
||||||
|
|
||||||
t.t2 = Date.now();
|
t.t_hashed = Date.now();
|
||||||
if (t.n == 0 && window.location.hash == '#dbg') {
|
if (t.n == 0 && window.location.hash == '#dbg') {
|
||||||
var spd = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.);
|
var spd = (t.size / ((t.t_hashed - t.t_hashing) / 1000.)) / (1024 * 1024.);
|
||||||
alert('{0} ms, {1} MB/s\n'.format(t.t2 - t.t1, spd.toFixed(3)) + t.hash.join('\n'));
|
alert('{0} ms, {1} MB/s\n'.format(t.t_hashed - t.t_hashing, spd.toFixed(3)) + t.hash.join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
pvis.seth(t.n, 2, 'hashing done');
|
pvis.seth(t.n, 2, 'hashing done');
|
||||||
pvis.seth(t.n, 1, '📦 wait');
|
pvis.seth(t.n, 1, '📦 wait');
|
||||||
st.busy.hash.splice(st.busy.hash.indexOf(t), 1);
|
apop(st.busy.hash, t);
|
||||||
st.todo.handshake.push(t);
|
st.todo.handshake.push(t);
|
||||||
tasker();
|
tasker();
|
||||||
};
|
};
|
||||||
|
@ -1137,7 +1157,7 @@ function up2k_init(subtle) {
|
||||||
}, 1);
|
}, 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
t.t1 = Date.now();
|
t.t_hashing = Date.now();
|
||||||
segm_next();
|
segm_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1148,30 +1168,41 @@ function up2k_init(subtle) {
|
||||||
|
|
||||||
function exec_handshake() {
|
function exec_handshake() {
|
||||||
var t = st.todo.handshake.shift(),
|
var t = st.todo.handshake.shift(),
|
||||||
|
keepalive = t.keepalive,
|
||||||
me = Date.now();
|
me = Date.now();
|
||||||
|
|
||||||
st.busy.handshake.push(t);
|
st.busy.handshake.push(t);
|
||||||
t.busied = me;
|
t.keepalive = undefined;
|
||||||
|
t.t_busied = me;
|
||||||
|
|
||||||
|
if (keepalive)
|
||||||
|
console.log("sending keepalive handshake", t);
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.onerror = function () {
|
xhr.onerror = function () {
|
||||||
if (t.busied != me) {
|
if (t.t_busied != me) {
|
||||||
console.log('zombie handshake onerror,', t);
|
console.log('zombie handshake onerror,', t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('handshake onerror, retrying', t);
|
console.log('handshake onerror, retrying', t);
|
||||||
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
|
apop(st.busy.handshake, t);
|
||||||
st.todo.handshake.unshift(t);
|
st.todo.handshake.unshift(t);
|
||||||
|
t.keepalive = keepalive;
|
||||||
tasker();
|
tasker();
|
||||||
};
|
};
|
||||||
function orz(e) {
|
function orz(e) {
|
||||||
if (t.busied != me) {
|
if (t.t_busied != me) {
|
||||||
console.log('zombie handshake onload,', t);
|
console.log('zombie handshake onload,', t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (xhr.status == 200) {
|
if (xhr.status == 200) {
|
||||||
var response = JSON.parse(xhr.responseText);
|
t.t_handshake = Date.now();
|
||||||
|
if (keepalive) {
|
||||||
|
apop(st.busy.handshake, t);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = JSON.parse(xhr.responseText);
|
||||||
if (!response.name) {
|
if (!response.name) {
|
||||||
var msg = '',
|
var msg = '',
|
||||||
smsg = '';
|
smsg = '';
|
||||||
|
@ -1195,7 +1226,7 @@ function up2k_init(subtle) {
|
||||||
pvis.seth(t.n, 2, msg);
|
pvis.seth(t.n, 2, msg);
|
||||||
pvis.seth(t.n, 1, smsg);
|
pvis.seth(t.n, 1, smsg);
|
||||||
pvis.move(t.n, smsg == '404' ? 'ng' : 'ok');
|
pvis.move(t.n, smsg == '404' ? 'ng' : 'ok');
|
||||||
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
|
apop(st.busy.handshake, t);
|
||||||
st.bytes.uploaded += t.size;
|
st.bytes.uploaded += t.size;
|
||||||
t.done = true;
|
t.done = true;
|
||||||
tasker();
|
tasker();
|
||||||
|
@ -1237,7 +1268,7 @@ function up2k_init(subtle) {
|
||||||
var done = true,
|
var done = true,
|
||||||
msg = '🎷🐛';
|
msg = '🎷🐛';
|
||||||
|
|
||||||
if (t.postlist.length > 0) {
|
if (t.postlist.length) {
|
||||||
for (var a = 0; a < t.postlist.length; a++)
|
for (var a = 0; a < t.postlist.length; a++)
|
||||||
st.todo.upload.push({
|
st.todo.upload.push({
|
||||||
'nfile': t.n,
|
'nfile': t.n,
|
||||||
|
@ -1248,20 +1279,20 @@ function up2k_init(subtle) {
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
pvis.seth(t.n, 1, msg);
|
pvis.seth(t.n, 1, msg);
|
||||||
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
|
apop(st.busy.handshake, t);
|
||||||
|
|
||||||
if (done) {
|
if (done) {
|
||||||
t.done = true;
|
t.done = true;
|
||||||
st.bytes.uploaded += t.size - t.bytes_uploaded;
|
st.bytes.uploaded += t.size - t.bytes_uploaded;
|
||||||
var spd1 = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.),
|
var spd1 = (t.size / ((t.t_hashed - t.t_hashing) / 1000.)) / (1024 * 1024.),
|
||||||
spd2 = (t.size / ((t.t4 - t.t3) / 1000.)) / (1024 * 1024.);
|
spd2 = (t.size / ((t.t_uploaded - t.t_uploading) / 1000.)) / (1024 * 1024.);
|
||||||
|
|
||||||
pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format(
|
pvis.seth(t.n, 2, 'hash {0}, up {1} MB/s'.format(
|
||||||
spd1.toFixed(2), spd2.toFixed(2)));
|
spd1.toFixed(2), spd2.toFixed(2)));
|
||||||
|
|
||||||
pvis.move(t.n, 'ok');
|
pvis.move(t.n, 'ok');
|
||||||
}
|
}
|
||||||
else t.t4 = undefined;
|
else t.t_uploaded = undefined;
|
||||||
|
|
||||||
tasker();
|
tasker();
|
||||||
}
|
}
|
||||||
|
@ -1280,7 +1311,7 @@ function up2k_init(subtle) {
|
||||||
var penalty = rsp.replace(/.*rate-limit /, "").split(' ')[0];
|
var penalty = rsp.replace(/.*rate-limit /, "").split(' ')[0];
|
||||||
console.log("rate-limit: " + penalty);
|
console.log("rate-limit: " + penalty);
|
||||||
t.cooldown = Date.now() + parseFloat(penalty) * 1000;
|
t.cooldown = Date.now() + parseFloat(penalty) * 1000;
|
||||||
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
|
apop(st.busy.handshake, t);
|
||||||
st.todo.handshake.unshift(t);
|
st.todo.handshake.unshift(t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1299,7 +1330,7 @@ function up2k_init(subtle) {
|
||||||
pvis.seth(t.n, 2, err);
|
pvis.seth(t.n, 2, err);
|
||||||
pvis.move(t.n, 'ng');
|
pvis.move(t.n, 'ng');
|
||||||
|
|
||||||
st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1);
|
apop(st.busy.handshake, t);
|
||||||
tasker();
|
tasker();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1340,8 +1371,8 @@ function up2k_init(subtle) {
|
||||||
var npart = upt.npart,
|
var npart = upt.npart,
|
||||||
t = st.files[upt.nfile];
|
t = st.files[upt.nfile];
|
||||||
|
|
||||||
if (!t.t3)
|
if (!t.t_uploading)
|
||||||
t.t3 = Date.now();
|
t.t_uploading = Date.now();
|
||||||
|
|
||||||
pvis.seth(t.n, 1, "🚀 send");
|
pvis.seth(t.n, 1, "🚀 send");
|
||||||
|
|
||||||
|
@ -1367,10 +1398,10 @@ function up2k_init(subtle) {
|
||||||
xhr.status, t.name) + (txt || "no further information"));
|
xhr.status, t.name) + (txt || "no further information"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
st.busy.upload.splice(st.busy.upload.indexOf(upt), 1);
|
apop(st.busy.upload, upt);
|
||||||
t.postlist.splice(t.postlist.indexOf(npart), 1);
|
apop(t.postlist, npart);
|
||||||
if (!t.postlist.length) {
|
if (!t.postlist.length) {
|
||||||
t.t4 = Date.now();
|
t.t_uploaded = Date.now();
|
||||||
pvis.seth(t.n, 1, 'verifying');
|
pvis.seth(t.n, 1, 'verifying');
|
||||||
st.todo.handshake.unshift(t);
|
st.todo.handshake.unshift(t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,6 +389,13 @@ function has(haystack, needle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function apop(arr, v) {
|
||||||
|
var ofs = arr.indexOf(v);
|
||||||
|
if (ofs !== -1)
|
||||||
|
arr.splice(ofs, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function jcp(obj) {
|
function jcp(obj) {
|
||||||
return JSON.parse(JSON.stringify(obj));
|
return JSON.parse(JSON.stringify(obj));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue