Skip to content

Commit

Permalink
parallelize handshakes
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Jul 3, 2021
1 parent c95941e commit a5120d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ in the `scripts` folder:

roughly sorted by priority

* keepalive handshake after 5h
* skip pushing postlist if todo.upload has entries
* readme.md as epilogue
* reduce up2k roundtrips
* start from a chunk index and just go
Expand Down
11 changes: 6 additions & 5 deletions copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,14 @@ def handle_post_json(self):
os.makedirs(fsenc(dst))
except OSError as ex:
self.log("makedirs failed [{}]".format(dst))
if ex.errno == 13:
raise Pebkac(500, "the server OS denied write-access")
if not os.path.isdir(fsenc(dst)):
if ex.errno == 13:
raise Pebkac(500, "the server OS denied write-access")

if ex.errno == 17:
raise Pebkac(400, "some file got your folder name")
if ex.errno == 17:
raise Pebkac(400, "some file got your folder name")

raise Pebkac(500, min_ex())
raise Pebkac(500, min_ex())
except:
raise Pebkac(500, min_ex())

Expand Down
33 changes: 13 additions & 20 deletions copyparty/web/up2k.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ function up2k_init(subtle) {
}
else files = e.target.files;

if (!files || files.length == 0)
if (!files || !files.length)
return alert('no files selected??');

more_one_file();
Expand Down Expand Up @@ -837,13 +837,20 @@ function up2k_init(subtle) {
//

function handshakes_permitted() {
var lim = multitask ? 1 : 0;
// verification
if (st.todo.handshake.length &&
st.todo.handshake[0].t4)
return true;

if (lim <
if ((multitask ? 2 : 0) <
st.todo.upload.length +
st.busy.upload.length)
return false;

if (parallel_uploads <
st.busy.handshake.length)
return false;

var cd = st.todo.handshake.length ? st.todo.handshake[0].cooldown : 0;
if (cd && cd - Date.now() > 0)
return false;
Expand Down Expand Up @@ -917,22 +924,8 @@ function up2k_init(subtle) {
st.todo.handshake.unshift(t);
}

if (st.todo.handshake.length > 0 &&
st.busy.handshake.length == 0 && (
st.todo.handshake[0].t4 || (
handshakes_permitted() &&
st.busy.upload.length < parallel_uploads
)
)
) {
exec_handshake();
mou_ikkai = true;
}

if (handshakes_permitted() &&
st.todo.handshake.length > 0 &&
st.busy.handshake.length == 0 &&
st.busy.upload.length < parallel_uploads) {
st.todo.handshake.length) {
exec_handshake();
mou_ikkai = true;
}
Expand All @@ -945,7 +938,7 @@ function up2k_init(subtle) {

if (hashing_permitted() &&
st.todo.hash.length > 0 &&
st.busy.hash.length == 0) {
!st.busy.hash.length) {
exec_hash();
mou_ikkai = true;
}
Expand Down Expand Up @@ -1376,7 +1369,7 @@ function up2k_init(subtle) {
}
st.busy.upload.splice(st.busy.upload.indexOf(upt), 1);
t.postlist.splice(t.postlist.indexOf(npart), 1);
if (t.postlist.length == 0) {
if (!t.postlist.length) {
t.t4 = Date.now();
pvis.seth(t.n, 1, 'verifying');
st.todo.handshake.unshift(t);
Expand Down

0 comments on commit a5120d4

Please sign in to comment.