From 23516ebd71d6518f30a3cfadbe424481c2c13cab Mon Sep 17 00:00:00 2001 From: Joseph Barker Date: Tue, 29 Oct 2019 09:47:45 +0900 Subject: Add option for latency control buffer size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit resolves #297, allowing the buffers used in the latency control to be changed with a command line option ‘--latency-buffer-size’. We do this by changing a module variable in ssnet.py (similar to the MAX_CHANNEL variable) which seems to be the simplest code change without extensive hacking. Documentation is also updated. --- docs/manpage.rst | 7 +++++++ sshuttle/cmdline.py | 3 +++ sshuttle/options.py | 10 ++++++++++ sshuttle/ssnet.py | 5 +++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/manpage.rst b/docs/manpage.rst index f0703ca..5d09c25 100644 --- a/docs/manpage.rst +++ b/docs/manpage.rst @@ -189,6 +189,13 @@ Options control feature, maximizing bandwidth usage. Use at your own risk. +.. option:: --latency-buffer-size + + Set the size of the buffer used in latency control. The + default is ``32768``. Changing this option allows a compromise + to be made between latency and bandwidth without completely + disabling latency control (with :option:`--no-latency-control`). + .. option:: -D, --daemon Automatically fork into the background after connecting diff --git a/sshuttle/cmdline.py b/sshuttle/cmdline.py index c454956..31a57bf 100644 --- a/sshuttle/cmdline.py +++ b/sshuttle/cmdline.py @@ -17,6 +17,9 @@ def main(): if opt.wrap: import sshuttle.ssnet as ssnet ssnet.MAX_CHANNEL = opt.wrap + if opt.latency_buffer_size: + import sshuttle.ssnet as ssnet + ssnet.LATENCY_BUFFER_SIZE = opt.latency_buffer_size helpers.verbose = opt.verbose try: diff --git a/sshuttle/options.py b/sshuttle/options.py index a19d5ef..62f3510 100644 --- a/sshuttle/options.py +++ b/sshuttle/options.py @@ -243,6 +243,16 @@ parser.add_argument( sacrifice latency to improve bandwidth benchmarks """ ) +parser.add_argument( + "--latency-buffer-size", + metavar="SIZE", + type=int, + default=32768, + dest="latency_buffer_size", + help=""" + size of latency control buffer + """ +) parser.add_argument( "--wrap", metavar="NUM", diff --git a/sshuttle/ssnet.py b/sshuttle/ssnet.py index c40b1e8..f0e584c 100644 --- a/sshuttle/ssnet.py +++ b/sshuttle/ssnet.py @@ -8,6 +8,7 @@ import os from sshuttle.helpers import b, binary_type, log, debug1, debug2, debug3, Fatal MAX_CHANNEL = 65535 +LATENCY_BUFFER_SIZE = 32768 # these don't exist in the socket module in python 2.3! SHUT_RD = 0 @@ -368,7 +369,7 @@ class Mux(Handler): return total def check_fullness(self): - if self.fullness > 32768: + if self.fullness > LATENCY_BUFFER_SIZE: if not self.too_full: self.send(0, CMD_PING, b('rttest')) self.too_full = True @@ -448,7 +449,7 @@ class Mux(Handler): def fill(self): self.rsock.setblocking(False) try: - read = _nb_clean(os.read, self.rsock.fileno(), 32768) + read = _nb_clean(os.read, self.rsock.fileno(), LATENCY_BUFFER_SIZE) except OSError: _, e = sys.exc_info()[:2] raise Fatal('other end: %r' % e) -- cgit v1.2.3