diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 36f747f9..8866f817 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -638,7 +638,7 @@ class HttpCli(object): penalty = 0.7 t_idle = t0 - idx.p_end if idx.p_dur > 0.7 and t_idle < penalty: - m = "rate-limit ({:.1f} sec), cost {:.2f}, idle {:.2f}" + m = "rate-limit {:.1f} sec, cost {:.2f}, idle {:.2f}" raise Pebkac(429, m.format(penalty, idx.p_dur, t_idle)) if "srch" in body: diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 8cf00487..de37c6d5 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -740,9 +740,17 @@ function up2k_init(subtle) { function handshakes_permitted() { var lim = multitask ? 1 : 0; - return lim >= + + if (lim < st.todo.upload.length + - st.busy.upload.length; + st.busy.upload.length) + return false; + + var cd = st.todo.handshake.length ? st.todo.handshake[0].cooldown : 0; + if (cd && cd - Date.now() > 0) + return false; + + return true; } function hashing_permitted() { @@ -1155,6 +1163,15 @@ function up2k_init(subtle) { if (rsp.indexOf('
') === 0) rsp = rsp.slice(5); + if (rsp.indexOf('rate-limit ') !== -1) { + var penalty = rsp.replace(/.*rate-limit /, "").split(' ')[0]; + console.log("rate-limit: " + penalty); + t.cooldown = Date.now() + parseFloat(penalty) * 1000; + st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1); + st.todo.handshake.unshift(t); + return; + } + st.bytes.uploaded += t.size; if (rsp.indexOf('partial upload exists') !== -1 || rsp.indexOf('file already exists') !== -1) {