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
verbose = verbosity
no_fullness = no_fullness0
sys.stderr.flush()
sys.stdout.flush()
main()

View File

@ -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)
mux.callback()
if latency_control:
mux.check_fullness()
mux.callback()
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:

View File

@ -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 <port> <subnets...>
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),

View File

@ -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)
if latency_control:
mux.check_fullness()
mux.callback()

19
ssh.py
View File

@ -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())

View File

@ -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,7 +326,6 @@ 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)
def got_packet(self, channel, cmd, data):