From 6deaf5c268cc95158e4c3695338ea0da8b3ac95f Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 20 Feb 2023 21:34:30 +0000 Subject: [PATCH] add jitter simlation --- copyparty/__main__.py | 1 + copyparty/httpcli.py | 3 +++ copyparty/svchub.py | 3 +++ tests/util.py | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 4491e5d4..8a61e06b 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -683,6 +683,7 @@ def add_network(ap): ap2.add_argument("--s-wr-sz", metavar="B", type=int, default=256*1024, help="socket write size in bytes") ap2.add_argument("--s-wr-slp", metavar="SEC", type=float, default=0, help="debug: socket write delay in seconds") ap2.add_argument("--rsp-slp", metavar="SEC", type=float, default=0, help="debug: response delay in seconds") + ap2.add_argument("--rsp-jtr", metavar="SEC", type=float, default=0, help="debug: response delay, random duration 0..SEC") def add_tls(ap): diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 3f062c0b..66de4b95 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -10,6 +10,7 @@ import gzip import itertools import json import os +import random import re import stat import string @@ -343,6 +344,8 @@ class HttpCli(object): if self.args.rsp_slp: time.sleep(self.args.rsp_slp) + if self.args.rsp_jtr: + time.sleep(random.random() * self.args.rsp_jtr) zso = self.headers.get("cookie") if zso: diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 70b6f166..2440af8c 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -348,6 +348,9 @@ class SvcHub(object): al.RS = R + "/" if R else "" al.SRS = "/" + R + "/" if R else "/" + if al.rsp_jtr: + al.rsp_slp = 0.000001 + return True def _setlimits(self) -> None: diff --git a/tests/util.py b/tests/util.py index 8f02244d..45781501 100644 --- a/tests/util.py +++ b/tests/util.py @@ -107,7 +107,7 @@ class Cfg(Namespace): ex = "css_browser hist js_browser no_forget no_hash no_idx" ka.update(**{k: None for k in ex.split()}) - ex = "df loris re_maxage rproxy rsp_slp s_wr_slp theme themes turbo" + ex = "df loris re_maxage rproxy rsp_jtr rsp_slp s_wr_slp theme themes turbo" ka.update(**{k: 0 for k in ex.split()}) ex = "doctitle favico html_head lg_sbf log_fk md_sbf mth textfiles R RS SR"