diff options
Diffstat (limited to 'test/delay_relay.py')
| -rw-r--r-- | test/delay_relay.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/test/delay_relay.py b/test/delay_relay.py index c600a3aa..b0d48e38 100644 --- a/test/delay_relay.py +++ b/test/delay_relay.py @@ -8,7 +8,7 @@ the ones before it have crossed at that rate, then waits out the delay. An optional jitter adds up to that many ms more to each chunk's delay, at random, its order kept (a chunk never overtakes the one before it). - python3 -B test/delay_relay.py LISTEN TARGET --delay MS [--rate MB/s] [--jitter MS] + python3 -B test/delay_relay.py LISTEN TARGET --delay MS [--rate MB/s] [--jitter MS] [--bound MS] python3 -B test/delay_relay.py --self-check An address is a path (a Unix socket) or host:port (TCP). The one-way @@ -46,7 +46,9 @@ def dial(address): return s -def listen(address): +def listen(address, bound=0.0): + """Bound, then listening `bound` s later (an ssh -L's socket file is + there a moment before it answers).""" family, addr = parse(address) s = socket.socket(family) if family == socket.AF_UNIX: @@ -57,6 +59,7 @@ def listen(address): else: s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(addr) + time.sleep(bound) s.listen(64) return s @@ -260,8 +263,9 @@ def main(): ap.add_argument('--delay', type=float, required=True, help='one-way delay, ms') ap.add_argument('--rate', type=float, help='a bandwidth cap, MB/s') ap.add_argument('--jitter', type=float, default=0, help='up to this many ms more a chunk, at random') + ap.add_argument('--bound', type=float, default=0, help='ms between the bind and the listen') a = ap.parse_args() - listener = listen(a.listen) + listener = listen(a.listen, a.bound / 1000) print(f'relaying {a.listen} -> {a.target}, {a.delay} ms each way' + (f', {a.rate} MB/s' if a.rate else '') + (f', jitter {a.jitter} ms' if a.jitter else ''), flush=True) try: |
