From d29f0c066ca45bbed8ddc620c5bc2c1ad7a63611 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 14 Feb 2021 01:32:16 +0100 Subject: [PATCH] logging --- copyparty/httpcli.py | 21 ++++++--------------- copyparty/httpconn.py | 6 ++++++ copyparty/httpsrv.py | 2 +- copyparty/up2k.py | 9 ++++++--- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 90ec5fb7..36544bd1 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -34,6 +34,7 @@ class HttpCli(object): self.auth = conn.auth self.log_func = conn.log_func self.log_src = conn.log_src + self.tls = hasattr(self.s, "cipher") self.bufsz = 1024 * 32 self.absolute_urls = False @@ -134,16 +135,6 @@ class HttpCli(object): uparam["raw"] = True uparam["dots"] = True - if hasattr(self.s, "cipher"): - self.ssl_suf = "".join( - [ - " \033[3{}m{}".format(c, s) - for c, s in zip([6, 3, 6], self.s.cipher()) - ] - ) - else: - self.ssl_suf = "" - try: if self.mode in ["GET", "HEAD"]: return self.handle_get() and self.keepalive @@ -221,7 +212,7 @@ class HttpCli(object): logmsg += " [\033[36m" + rval + "\033[0m]" - self.log(logmsg + self.ssl_suf) + self.log(logmsg) # "embedded" resources if self.vpath.startswith(".cpr"): @@ -255,7 +246,7 @@ class HttpCli(object): return self.tx_browser() def handle_options(self): - self.log("OPTIONS " + self.req + self.ssl_suf) + self.log("OPTIONS " + self.req) self.send_headers( None, 204, @@ -268,7 +259,7 @@ class HttpCli(object): return True def handle_put(self): - self.log("PUT " + self.req + self.ssl_suf) + self.log("PUT " + self.req) if self.headers.get("expect", "").lower() == "100-continue": try: @@ -279,7 +270,7 @@ class HttpCli(object): return self.handle_stash() def handle_post(self): - self.log("POST " + self.req + self.ssl_suf) + self.log("POST " + self.req) if self.headers.get("expect", "").lower() == "100-continue": try: @@ -943,7 +934,7 @@ class HttpCli(object): # 512 kB is optimal for huge files, use 64k open_args = [fsenc(fs_path), "rb", 64 * 1024] use_sendfile = ( - not self.ssl_suf + not self.tls # and not self.args.no_sendfile and hasattr(os, "sendfile") ) diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 0e158415..1cb321cb 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -141,6 +141,12 @@ class HttpConn(object): ctx.set_ciphers(self.args.ciphers) self.s = ctx.wrap_socket(self.s, server_side=True) + msg = [ + "\033[1;3{:d}m{}".format(c, s) + for c, s in zip([0, 5, 0], self.s.cipher()) + ] + self.log(" ".join(msg) + "\033[0m") + if self.args.ssl_dbg and hasattr(self.s, "shared_ciphers"): overlap = [y[::-1] for y in self.s.shared_ciphers()] lines = [str(x) for x in (["TLS cipher overlap:"] + overlap)] diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 84b4255e..a6e58255 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -78,7 +78,7 @@ class HttpSrv(object): if not MACOS: self.log( "%s %s" % addr, - "shut_rdwr err:\n {}\n {}".format(repr(sck), ex), + "\033[1;30mshut({}): {}\033[0m".format(sck.fileno(), ex), ) if ex.errno not in [10038, 10054, 107, 57, 9]: # 10038 No longer considered a socket diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 1f09f240..27053f70 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -2,8 +2,9 @@ from __future__ import print_function, unicode_literals -import os import re +import os +import sys import time import math import json @@ -531,9 +532,10 @@ class Up2k(object): while fsz > 0: now = time.time() td = now - last_print - if td >= 0.3: + if td >= 0.1: last_print = now - print(" {} \n\033[A".format(fsz), end="") + msg = " {} MB \r".format(int(fsz / 1024 / 1024)) + print(msg, end="", file=sys.stderr) hashobj = hashlib.sha512() rem = min(csz, fsz) @@ -575,6 +577,7 @@ class Up2k(object): # self.log("lmod", "got {}".format(len(ready))) time.sleep(5) for path, times in ready: + self.log("lmod", "setting times {} on {}".format(times, path)) try: os.utime(fsenc(path), times) except: