mirror of
https://github.com/9001/copyparty.git
synced 2026-02-21 01:40:39 +10:00
u2c: server-offline timeout; closes #1197
This commit is contained in:
24
bin/u2c.py
24
bin/u2c.py
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
S_VERSION = "2.18"
|
S_VERSION = "2.19"
|
||||||
S_BUILD_DT = "2026-01-02"
|
S_BUILD_DT = "2026-01-18"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
u2c.py: upload to copyparty
|
u2c.py: upload to copyparty
|
||||||
@@ -100,7 +100,7 @@ except:
|
|||||||
ub64enc = base64.urlsafe_b64encode
|
ub64enc = base64.urlsafe_b64encode
|
||||||
|
|
||||||
|
|
||||||
class BadAuth(Exception):
|
class Fatal(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@@ -835,10 +835,15 @@ def handshake(ar, file, search):
|
|||||||
url = ""
|
url = ""
|
||||||
url = ar.vtop + url
|
url = ar.vtop + url
|
||||||
|
|
||||||
|
t0 = time.time()
|
||||||
|
tmax = t0 + ar.t_hs
|
||||||
while True:
|
while True:
|
||||||
sc = 600
|
sc = 600
|
||||||
txt = ""
|
txt = ""
|
||||||
t0 = time.time()
|
t1 = time.time()
|
||||||
|
if t1 >= tmax:
|
||||||
|
print("\nERROR: server offline for longer than --t-hs; giving up")
|
||||||
|
raise Fatal()
|
||||||
try:
|
try:
|
||||||
zs = json.dumps(req, separators=(",\n", ": "))
|
zs = json.dumps(req, separators=(",\n", ": "))
|
||||||
sc, txt = web.req("POST", url, {}, zs.encode("utf-8"), MJ)
|
sc, txt = web.req("POST", url, {}, zs.encode("utf-8"), MJ)
|
||||||
@@ -861,11 +866,11 @@ def handshake(ar, file, search):
|
|||||||
return [], False
|
return [], False
|
||||||
elif sc == 403 or sc == 401:
|
elif sc == 403 or sc == 401:
|
||||||
print("\nERROR: login required, or wrong password:\n%s" % (txt,))
|
print("\nERROR: login required, or wrong password:\n%s" % (txt,))
|
||||||
raise BadAuth()
|
raise Fatal()
|
||||||
|
|
||||||
t = "handshake failed, retrying: %s\n t0=%.3f t1=%.3f td=%.3f\n %s\n\n"
|
t = "handshake failed, retrying: %s\n t0=%.3f t1=%.3f t2=%.3f td1=%.3f td2=%.3f\n %s\n\n"
|
||||||
now = time.time()
|
now = time.time()
|
||||||
eprint(t % (file.name, t0, now, now - t0, em))
|
eprint(t % (file.name, t0, t1, now, now - t0, now - t1, em))
|
||||||
time.sleep(ar.cd)
|
time.sleep(ar.cd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1051,7 +1056,7 @@ class Ctl(object):
|
|||||||
print(" hs...")
|
print(" hs...")
|
||||||
try:
|
try:
|
||||||
hs, _ = handshake(self.ar, file, search)
|
hs, _ = handshake(self.ar, file, search)
|
||||||
except BadAuth:
|
except Fatal:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if search:
|
if search:
|
||||||
@@ -1356,7 +1361,7 @@ class Ctl(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
hs, sprs = handshake(self.ar, file, search)
|
hs, sprs = handshake(self.ar, file, search)
|
||||||
except BadAuth:
|
except Fatal:
|
||||||
self.panik = 1
|
self.panik = 1
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -1591,6 +1596,7 @@ NOTE: if server has --usernames enabled, then password is "username:password"
|
|||||||
ap.add_argument("-ns", action="store_true", help="no status panel (for slow consoles and macos)")
|
ap.add_argument("-ns", action="store_true", help="no status panel (for slow consoles and macos)")
|
||||||
ap.add_argument("--cxp", type=float, metavar="SEC", default=57, help="assume http connections expired after SEConds")
|
ap.add_argument("--cxp", type=float, metavar="SEC", default=57, help="assume http connections expired after SEConds")
|
||||||
ap.add_argument("--cd", type=float, metavar="SEC", default=5, help="delay before reattempting a failed handshake/upload")
|
ap.add_argument("--cd", type=float, metavar="SEC", default=5, help="delay before reattempting a failed handshake/upload")
|
||||||
|
ap.add_argument("--t-hs", type=float, metavar="SEC", default=186, help="crash if handshakes fail due to server-offline for this long")
|
||||||
ap.add_argument("--safe", action="store_true", help="use simple fallback approach")
|
ap.add_argument("--safe", action="store_true", help="use simple fallback approach")
|
||||||
ap.add_argument("-z", action="store_true", help="ZOOMIN' (skip uploading files if they exist at the destination with the ~same last-modified timestamp, so same as yolo / turbo with date-chk but even faster)")
|
ap.add_argument("-z", action="store_true", help="ZOOMIN' (skip uploading files if they exist at the destination with the ~same last-modified timestamp, so same as yolo / turbo with date-chk but even faster)")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user