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".
This commit is contained in:
Avery Pennarun 2011-01-25 21:07:01 -08:00
parent fdb7c9b995
commit 8fde1155da
6 changed files with 32 additions and 22 deletions

View File

@ -21,7 +21,6 @@ while 1:
break break
verbose = verbosity verbose = verbosity
no_fullness = no_fullness0
sys.stderr.flush() sys.stderr.flush()
sys.stdout.flush() sys.stdout.flush()
main() main()

View File

@ -189,7 +189,8 @@ class FirewallClient:
raise Fatal('cleanup: %r returned %d' % (self.argv, rv)) 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): syslog, daemon):
handlers = [] handlers = []
if helpers.verbose >= 1: if helpers.verbose >= 1:
@ -200,7 +201,8 @@ def _main(listener, fw, ssh_cmd, remotename, python, seed_hosts, auto_nets,
try: try:
(serverproc, serversock) = ssh.connect(ssh_cmd, remotename, python, (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: except socket.error, e:
if e.args[0] == errno.EPIPE: if e.args[0] == errno.EPIPE:
raise Fatal("failed to establish ssh session (1)") 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) raise Fatal('server died with error code %d' % rv)
ssnet.runonce(handlers, mux) ssnet.runonce(handlers, mux)
if latency_control:
mux.check_fullness()
mux.callback() 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): subnets_include, subnets_exclude, syslog, daemon, pidfile):
if syslog: if syslog:
ssyslog.start_syslog() ssyslog.start_syslog()
@ -344,7 +348,8 @@ def main(listenip, ssh_cmd, remotename, python, seed_hosts, auto_nets,
try: try:
return _main(listener, fw, ssh_cmd, remotename, return _main(listener, fw, ssh_cmd, remotename,
python, seed_hosts, auto_nets, syslog, daemon) python, latency_control,
seed_hosts, auto_nets, syslog, daemon)
finally: finally:
try: try:
if daemon: if daemon:

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, os, re import sys, os, re
import helpers, options, client, server, firewall, hostwatch, ssnet import helpers, options, client, server, firewall, hostwatch
import compat.ssubprocess as ssubprocess import compat.ssubprocess as ssubprocess
from helpers import * from helpers import *
@ -51,7 +51,6 @@ sshuttle --server
sshuttle --firewall <port> <subnets...> sshuttle --firewall <port> <subnets...>
sshuttle --hostwatch 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] 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 H,auto-hosts scan for remote hostnames and update local /etc/hosts
N,auto-nets automatically determine subnets to route 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 v,verbose increase debug message verbosity
e,ssh-cmd= the command to use to connect to the remote [ssh] 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) 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 D,daemon run in the background as a daemon
syslog send log messages to syslog (default if you use --daemon) syslog send log messages to syslog (default if you use --daemon)
pidfile= pidfile name (only if using --daemon) [./sshuttle.pid] pidfile= pidfile name (only if using --daemon) [./sshuttle.pid]
@ -74,11 +74,12 @@ o = options.Options('sshuttle', optspec)
if opt.daemon: if opt.daemon:
opt.syslog = 1 opt.syslog = 1
helpers.verbose = opt.verbose helpers.verbose = opt.verbose
ssnet.no_fullness = opt.disable_fullness
try: try:
if opt.server: if opt.server:
if len(extra) != 0: if len(extra) != 0:
o.fatal('no arguments expected') o.fatal('no arguments expected')
server.latency_control = opt.latency_control
sys.exit(server.main()) sys.exit(server.main())
elif opt.firewall: elif opt.firewall:
if len(extra) != 1: if len(extra) != 1:
@ -109,6 +110,7 @@ try:
opt.ssh_cmd, opt.ssh_cmd,
remotename, remotename,
opt.python, opt.python,
opt.latency_control,
sh, sh,
opt.auto_nets, opt.auto_nets,
parse_subnets(includes), parse_subnets(includes),

View File

@ -111,6 +111,7 @@ def main():
helpers.logprefix = ' s: ' helpers.logprefix = ' s: '
else: else:
helpers.logprefix = 'server: ' helpers.logprefix = 'server: '
debug1('latency control setting = %r\n' % latency_control)
routes = list(list_routes()) routes = list(list_routes())
debug1('available routes:\n') debug1('available routes:\n')
@ -172,5 +173,6 @@ def main():
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv) raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
ssnet.runonce(handlers, mux) ssnet.runonce(handlers, mux)
mux.check_fullness() if latency_control:
mux.check_fullness()
mux.callback() mux.callback()

19
ssh.py
View File

@ -1,6 +1,6 @@
import sys, os, re, socket, zlib import sys, os, re, socket, zlib
import compat.ssubprocess as ssubprocess import compat.ssubprocess as ssubprocess
import helpers, ssnet import helpers
from helpers import * from helpers import *
@ -14,14 +14,16 @@ def readfile(name):
raise Exception("can't find file %r in any of %r" % (name, path)) 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) (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) 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] main_exe = sys.argv[0]
portl = [] portl = []
@ -52,7 +54,9 @@ def connect(ssh_cmd, rhostport, python, stderr):
z = zlib.compressobj(1) z = zlib.compressobj(1)
content = readfile('assembler.py') 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, 'compat/ssubprocess.py') +
empackage(z, 'ssnet.py') + empackage(z, 'ssnet.py') +
empackage(z, 'hostwatch.py') + empackage(z, 'hostwatch.py') +
@ -63,9 +67,8 @@ def connect(ssh_cmd, rhostport, python, stderr):
import sys; import sys;
skip_imports=1; skip_imports=1;
verbosity=%d; verbosity=%d;
no_fullness0=%d;
exec compile(sys.stdin.read(%d), "assembler.py", "exec") 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()) pyscript = re.sub(r'\s+', ' ', pyscript.strip())

View File

@ -35,7 +35,7 @@ cmd_to_name = {
CMD_HOST_LIST: 'HOST_LIST', CMD_HOST_LIST: 'HOST_LIST',
} }
no_fullness = 0
def _add(l, elem): def _add(l, elem):
if not elem in l: if not elem in l:
@ -308,7 +308,7 @@ class Mux(Handler):
return total return total
def check_fullness(self): def check_fullness(self):
if not no_fullness and self.fullness > 32768: if self.fullness > 32768:
if not self.too_full: if not self.too_full:
self.send(0, CMD_PING, 'rttest') self.send(0, CMD_PING, 'rttest')
self.too_full = True self.too_full = True
@ -326,8 +326,7 @@ class Mux(Handler):
debug2(' > channel=%d cmd=%s len=%d (fullness=%d)\n' debug2(' > channel=%d cmd=%s len=%d (fullness=%d)\n'
% (channel, cmd_to_name.get(cmd,hex(cmd)), % (channel, cmd_to_name.get(cmd,hex(cmd)),
len(data), self.fullness)) len(data), self.fullness))
if not no_fullness: self.fullness += len(data)
self.fullness += len(data)
def got_packet(self, channel, cmd, data): def got_packet(self, channel, cmd, data):
debug2('< channel=%d cmd=%s len=%d\n' debug2('< channel=%d cmd=%s len=%d\n'