From 49e4fb7e1205aff7a477907a26eb95d01861944b Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 21 Mar 2021 16:19:45 +0100 Subject: [PATCH] finally time to undefault this --- copyparty/__main__.py | 1 + copyparty/broker_mpw.py | 4 +++- copyparty/broker_thr.py | 4 +++- copyparty/httpsrv.py | 12 +++++++++--- copyparty/tcpsrv.py | 24 +++++++++++++++--------- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 62532723..90995506 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -254,6 +254,7 @@ def main(): ap.add_argument("-a", metavar="ACCT", type=str, action="append", help="add account") ap.add_argument("-v", metavar="VOL", type=str, action="append", help="add volume") ap.add_argument("-q", action="store_true", help="quiet") + ap.add_argument("--log-conn", action="store_true", help="print tcp-server msgs") ap.add_argument("-ed", action="store_true", help="enable ?dots") ap.add_argument("-emp", action="store_true", help="enable markdown plugins") ap.add_argument("-mcr", metavar="SEC", type=int, default=60, help="md-editor mod-chk rate") diff --git a/copyparty/broker_mpw.py b/copyparty/broker_mpw.py index bd1fb486..ae4b9fe5 100644 --- a/copyparty/broker_mpw.py +++ b/copyparty/broker_mpw.py @@ -73,7 +73,9 @@ class MpWorker(object): if PY2: sck = pickle.loads(sck) # nosec - self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30") + if self.args.log_conn: + self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30") + self.httpsrv.accept(sck, addr) with self.mutex: diff --git a/copyparty/broker_thr.py b/copyparty/broker_thr.py index 121da451..643f1f65 100644 --- a/copyparty/broker_thr.py +++ b/copyparty/broker_thr.py @@ -28,7 +28,9 @@ class BrokerThr(object): def put(self, want_retval, dest, *args): if dest == "httpconn": sck, addr = args - self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30") + if self.args.log_conn: + self.log("%s %s" % addr, "|%sC-qpop" % ("-" * 4,), c="1;30") + self.httpsrv.accept(sck, addr) else: diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 8360bf57..c83e4172 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -38,7 +38,9 @@ class HttpSrv(object): def accept(self, sck, addr): """takes an incoming tcp connection and creates a thread to handle it""" - self.log("%s %s" % addr, "|%sC-cthr" % ("-" * 5,), c="1;30") + if self.args.log_conn: + self.log("%s %s" % addr, "|%sC-cthr" % ("-" * 5,), c="1;30") + thr = threading.Thread(target=self.thr_client, args=(sck, addr)) thr.daemon = True thr.start() @@ -66,11 +68,15 @@ class HttpSrv(object): thr.start() try: - self.log("%s %s" % addr, "|%sC-crun" % ("-" * 6,), c="1;30") + if self.args.log_conn: + self.log("%s %s" % addr, "|%sC-crun" % ("-" * 6,), c="1;30") + cli.run() finally: - self.log("%s %s" % addr, "|%sC-cdone" % ("-" * 7,), c="1;30") + if self.args.log_conn: + self.log("%s %s" % addr, "|%sC-cdone" % ("-" * 7,), c="1;30") + try: sck.shutdown(socket.SHUT_RDWR) sck.close() diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index e0e31409..db7beaf2 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -68,23 +68,29 @@ class TcpSrv(object): self.log("tcpsrv", "listening @ {0}:{1}".format(ip, port)) while True: - self.log("tcpsrv", "|%sC-ncli" % ("-" * 1,), c="1;30") + if self.args.log_conn: + self.log("tcpsrv", "|%sC-ncli" % ("-" * 1,), c="1;30") + if self.num_clients.v >= self.args.nc: time.sleep(0.1) continue - self.log("tcpsrv", "|%sC-acc1" % ("-" * 2,), c="1;30") + if self.args.log_conn: + self.log("tcpsrv", "|%sC-acc1" % ("-" * 2,), c="1;30") + ready, _, _ = select.select(self.srv, [], []) for srv in ready: sck, addr = srv.accept() sip, sport = srv.getsockname() - self.log( - "%s %s" % addr, - "|{}C-acc2 \033[0;36m{} \033[3{}m{}".format( - "-" * 3, sip, sport % 8, sport - ), - c="1;30", - ) + if self.args.log_conn: + self.log( + "%s %s" % addr, + "|{}C-acc2 \033[0;36m{} \033[3{}m{}".format( + "-" * 3, sip, sport % 8, sport + ), + c="1;30", + ) + self.num_clients.add() self.hub.broker.put(False, "httpconn", sck, addr)