From 8fde1155da2444e9614484385a5bc30d6feadd25 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Tue, 25 Jan 2011 21:07:01 -0800 Subject: Implement the optional fullness checking a bit more like I like it. Looks like it worked before, but personal preference is a killer. The new name is "--no-latency-control". --- assembler.py | 1 - client.py | 15 ++++++++++----- main.py | 8 +++++--- server.py | 4 +++- ssh.py | 19 +++++++++++-------- ssnet.py | 7 +++---- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/assembler.py b/assembler.py index e65d11e..c478e37 100644 --- a/assembler.py +++ b/assembler.py @@ -21,7 +21,6 @@ while 1: break verbose = verbosity -no_fullness = no_fullness0 sys.stderr.flush() sys.stdout.flush() main() diff --git a/client.py b/client.py index dbd11de..e584933 100644 --- a/client.py +++ b/client.py @@ -189,7 +189,8 @@ class FirewallClient: raise Fatal('cleanup: %r returned %d' % (self.argv, rv)) -def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets, +def _main(listener, fw, ssh_cmd, remotename, python, latency_control, + seed_hosts, auto_nets, syslog, daemon): handlers = [] if helpers.verbose >= 1: @@ -200,7 +201,8 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets, try: (serverproc, serversock) = ssh.connect(ssh_cmd, remotename, python, - stderr=ssyslog._p and ssyslog._p.stdin) + stderr=ssyslog._p and ssyslog._p.stdin, + options=dict(latency_control=latency_control)) except socket.error, e: if e.args[0] == errno.EPIPE: raise Fatal("failed to establish ssh session (1)") @@ -300,11 +302,13 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets, raise Fatal('server died with error code %d' % rv) ssnet.runonce(handlers, mux) + if latency_control: + mux.check_fullness() mux.callback() - mux.check_fullness() -def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets, +def main(listenip, ssh_cmd, remotename, python, latency_control, + seed_hosts, auto_nets, subnets_include, subnets_exclude, syslog, daemon, pidfile): if syslog: ssyslog.start_syslog() @@ -344,7 +348,8 @@ def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets, try: return _main(listener, fw, ssh_cmd, remotename, - python, seed_hosts, auto_nets, syslog, daemon) + python, latency_control, + seed_hosts, auto_nets, syslog, daemon) finally: try: if daemon: diff --git a/main.py b/main.py index cab6a2b..719f86a 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python import sys, os, re -import helpers, options, client, server, firewall, hostwatch, ssnet +import helpers, options, client, server, firewall, hostwatch import compat.ssubprocess as ssubprocess from helpers import * @@ -51,7 +51,6 @@ sshuttle --server sshuttle --firewall sshuttle --hostwatch -- -f,disable-fullness turn off fullness checking (could 10x bandwidth on high latency link) l,listen= transproxy to this ip address and port number [127.0.0.1:0] H,auto-hosts scan for remote hostnames and update local /etc/hosts N,auto-nets automatically determine subnets to route @@ -61,6 +60,7 @@ x,exclude= exclude this subnet (can be used more than once) v,verbose increase debug message verbosity e,ssh-cmd= the command to use to connect to the remote [ssh] seed-hosts= with -H, use these hostnames for initial scan (comma-separated) +no-latency-control sacrifice latency to improve bandwidth benchmarks D,daemon run in the background as a daemon syslog send log messages to syslog (default if you use --daemon) pidfile= pidfile name (only if using --daemon) [./sshuttle.pid] @@ -74,11 +74,12 @@ o = options.Options('sshuttle', optspec) if opt.daemon: opt.syslog = 1 helpers.verbose = opt.verbose -ssnet.no_fullness = opt.disable_fullness + try: if opt.server: if len(extra) != 0: o.fatal('no arguments expected') + server.latency_control = opt.latency_control sys.exit(server.main()) elif opt.firewall: if len(extra) != 1: @@ -109,6 +110,7 @@ try: opt.ssh_cmd, remotename, opt.python, + opt.latency_control, sh, opt.auto_nets, parse_subnets(includes), diff --git a/server.py b/server.py index 24dd462..ae7a921 100644 --- a/server.py +++ b/server.py @@ -111,6 +111,7 @@ def main(): helpers.logprefix = ' s: ' else: helpers.logprefix = 'server: ' + debug1('latency control setting = %r\n' % latency_control) routes = list(list_routes()) debug1('available routes:\n') @@ -172,5 +173,6 @@ def main(): raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv) ssnet.runonce(handlers, mux) - mux.check_fullness() + if latency_control: + mux.check_fullness() mux.callback() diff --git a/ssh.py b/ssh.py index 9d3a8eb..9a6270a 100644 --- a/ssh.py +++ b/ssh.py @@ -1,6 +1,6 @@ import sys, os, re, socket, zlib import compat.ssubprocess as ssubprocess -import helpers, ssnet +import helpers from helpers import * @@ -14,14 +14,16 @@ def readfile(name): raise Exception("can't find file %r in any of %r" % (name, path)) -def empackage(z, filename): +def empackage(z, filename, data=None): (path,basename) = os.path.split(filename) - content = z.compress(readfile(filename)) + if not data: + data = readfile(filename) + content = z.compress(data) content += z.flush(zlib.Z_SYNC_FLUSH) - return '%s\n%d\n%s' % (basename,len(content), content) + return '%s\n%d\n%s' % (basename, len(content), content) -def connect(ssh_cmd, rhostport, python, stderr): +def connect(ssh_cmd, rhostport, python, stderr, options): main_exe = sys.argv[0] portl = [] @@ -52,7 +54,9 @@ def connect(ssh_cmd, rhostport, python, stderr): z = zlib.compressobj(1) content = readfile('assembler.py') - content2 = (empackage(z, 'helpers.py') + + optdata = ''.join("%s=%r\n" % (k,v) for (k,v) in options.items()) + content2 = (empackage(z, 'cmdline_options.py', optdata) + + empackage(z, 'helpers.py') + empackage(z, 'compat/ssubprocess.py') + empackage(z, 'ssnet.py') + empackage(z, 'hostwatch.py') + @@ -63,9 +67,8 @@ def connect(ssh_cmd, rhostport, python, stderr): import sys; skip_imports=1; verbosity=%d; - no_fullness0=%d; exec compile(sys.stdin.read(%d), "assembler.py", "exec") - """ % (helpers.verbose or 0, ssnet.no_fullness or 0, len(content)) + """ % (helpers.verbose or 0, len(content)) pyscript = re.sub(r'\s+', ' ', pyscript.strip()) diff --git a/ssnet.py b/ssnet.py index 9cd42a0..62fa378 100644 --- a/ssnet.py +++ b/ssnet.py @@ -35,7 +35,7 @@ cmd_to_name = { CMD_HOST_LIST: 'HOST_LIST', } -no_fullness = 0 + def _add(l, elem): if not elem in l: @@ -308,7 +308,7 @@ class Mux(Handler): return total def check_fullness(self): - if not no_fullness and self.fullness > 32768: + if self.fullness > 32768: if not self.too_full: self.send(0, CMD_PING, 'rttest') self.too_full = True @@ -326,8 +326,7 @@ class Mux(Handler): debug2(' > channel=%d cmd=%s len=%d (fullness=%d)\n' % (channel, cmd_to_name.get(cmd,hex(cmd)), len(data), self.fullness)) - if not no_fullness: - self.fullness += len(data) + self.fullness += len(data) def got_packet(self, channel, cmd, data): debug2('< channel=%d cmd=%s len=%d\n' -- cgit v1.2.3