mirror of
https://github.com/sshuttle/sshuttle.git
synced 2025-04-04 22:09:41 +02:00
Don't use set() since it's not in python 2.3.
Just use a plain list instead. Technically probably slightly worse asymptotic behaviour, but it's not like we'll have a million sockets anyway.
This commit is contained in:
parent
da774f3f46
commit
c403a83ab8
10
client.py
10
client.py
@ -176,9 +176,9 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
|
|||||||
if rv:
|
if rv:
|
||||||
raise Fatal('server died with error code %d' % rv)
|
raise Fatal('server died with error code %d' % rv)
|
||||||
|
|
||||||
r = set()
|
r = []
|
||||||
w = set()
|
w = []
|
||||||
x = set()
|
x = []
|
||||||
handlers = filter(lambda s: s.ok, handlers)
|
handlers = filter(lambda s: s.ok, handlers)
|
||||||
for s in handlers:
|
for s in handlers:
|
||||||
s.pre_select(r,w,x)
|
s.pre_select(r,w,x)
|
||||||
@ -186,9 +186,9 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
|
|||||||
% (len(handlers), len(r), len(w), len(x)))
|
% (len(handlers), len(r), len(w), len(x)))
|
||||||
(r,w,x) = select.select(r,w,x)
|
(r,w,x) = select.select(r,w,x)
|
||||||
#log('r=%r w=%r x=%r\n' % (r,w,x))
|
#log('r=%r w=%r x=%r\n' % (r,w,x))
|
||||||
ready = set(r) | set(w) | set(x)
|
ready = r+w+x
|
||||||
for s in handlers:
|
for s in handlers:
|
||||||
if s.socks & ready:
|
if list_contains_any(s.socks, ready):
|
||||||
s.callback()
|
s.callback()
|
||||||
if use_server:
|
if use_server:
|
||||||
mux.callback()
|
mux.callback()
|
||||||
|
@ -28,3 +28,10 @@ def debug3(s):
|
|||||||
|
|
||||||
class Fatal(Exception):
|
class Fatal(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def list_contains_any(l, sub):
|
||||||
|
for i in sub:
|
||||||
|
if i in l:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
10
server.py
10
server.py
@ -158,9 +158,9 @@ def main():
|
|||||||
if rpid:
|
if rpid:
|
||||||
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
|
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
|
||||||
|
|
||||||
r = set()
|
r = []
|
||||||
w = set()
|
w = []
|
||||||
x = set()
|
x = []
|
||||||
handlers = filter(lambda s: s.ok, handlers)
|
handlers = filter(lambda s: s.ok, handlers)
|
||||||
for s in handlers:
|
for s in handlers:
|
||||||
s.pre_select(r,w,x)
|
s.pre_select(r,w,x)
|
||||||
@ -169,10 +169,10 @@ def main():
|
|||||||
mux.fullness, mux.too_full))
|
mux.fullness, mux.too_full))
|
||||||
(r,w,x) = select.select(r,w,x)
|
(r,w,x) = select.select(r,w,x)
|
||||||
#log('r=%r w=%r x=%r\n' % (r,w,x))
|
#log('r=%r w=%r x=%r\n' % (r,w,x))
|
||||||
ready = set(r) | set(w) | set(x)
|
ready = r+w+x
|
||||||
for s in handlers:
|
for s in handlers:
|
||||||
#debug2('check: %r: %r\n' % (s, s.socks & ready))
|
#debug2('check: %r: %r\n' % (s, s.socks & ready))
|
||||||
if s.socks & ready:
|
if list_contains_any(s.socks, ready):
|
||||||
s.callback()
|
s.callback()
|
||||||
mux.check_fullness()
|
mux.check_fullness()
|
||||||
mux.callback()
|
mux.callback()
|
||||||
|
28
ssnet.py
28
ssnet.py
@ -31,6 +31,11 @@ cmd_to_name = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def _add(l, elem):
|
||||||
|
if not elem in l:
|
||||||
|
l.append(elem)
|
||||||
|
|
||||||
|
|
||||||
def _nb_clean(func, *args):
|
def _nb_clean(func, *args):
|
||||||
try:
|
try:
|
||||||
return func(*args)
|
return func(*args)
|
||||||
@ -167,12 +172,13 @@ class SockWrapper:
|
|||||||
class Handler:
|
class Handler:
|
||||||
def __init__(self, socks = None, callback = None):
|
def __init__(self, socks = None, callback = None):
|
||||||
self.ok = True
|
self.ok = True
|
||||||
self.socks = set(socks or [])
|
self.socks = socks or []
|
||||||
if callback:
|
if callback:
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
|
||||||
def pre_select(self, r, w, x):
|
def pre_select(self, r, w, x):
|
||||||
r |= self.socks
|
for i in self.socks:
|
||||||
|
_add(r, i)
|
||||||
|
|
||||||
def callback(self):
|
def callback(self):
|
||||||
log('--no callback defined-- %r\n' % self)
|
log('--no callback defined-- %r\n' % self)
|
||||||
@ -181,7 +187,7 @@ class Handler:
|
|||||||
v = s.recv(4096)
|
v = s.recv(4096)
|
||||||
if not v:
|
if not v:
|
||||||
log('--closed-- %r\n' % self)
|
log('--closed-- %r\n' % self)
|
||||||
self.socks = set()
|
self.socks = []
|
||||||
self.ok = False
|
self.ok = False
|
||||||
|
|
||||||
|
|
||||||
@ -194,20 +200,20 @@ class Proxy(Handler):
|
|||||||
|
|
||||||
def pre_select(self, r, w, x):
|
def pre_select(self, r, w, x):
|
||||||
if self.wrap1.connect_to:
|
if self.wrap1.connect_to:
|
||||||
w.add(self.wrap1.rsock)
|
_add(w, self.wrap1.rsock)
|
||||||
elif self.wrap1.buf:
|
elif self.wrap1.buf:
|
||||||
if not self.wrap2.too_full():
|
if not self.wrap2.too_full():
|
||||||
w.add(self.wrap2.wsock)
|
_add(w, self.wrap2.wsock)
|
||||||
elif not self.wrap1.shut_read:
|
elif not self.wrap1.shut_read:
|
||||||
r.add(self.wrap1.rsock)
|
_add(r, self.wrap1.rsock)
|
||||||
|
|
||||||
if self.wrap2.connect_to:
|
if self.wrap2.connect_to:
|
||||||
w.add(self.wrap2.rsock)
|
_add(w, self.wrap2.rsock)
|
||||||
elif self.wrap2.buf:
|
elif self.wrap2.buf:
|
||||||
if not self.wrap1.too_full():
|
if not self.wrap1.too_full():
|
||||||
w.add(self.wrap1.wsock)
|
_add(w, self.wrap1.wsock)
|
||||||
elif not self.wrap2.shut_read:
|
elif not self.wrap2.shut_read:
|
||||||
r.add(self.wrap2.rsock)
|
_add(r, self.wrap2.rsock)
|
||||||
|
|
||||||
def callback(self):
|
def callback(self):
|
||||||
self.wrap1.try_connect()
|
self.wrap1.try_connect()
|
||||||
@ -349,9 +355,9 @@ class Mux(Handler):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def pre_select(self, r, w, x):
|
def pre_select(self, r, w, x):
|
||||||
r.add(self.rsock)
|
_add(r, self.rsock)
|
||||||
if self.outbuf:
|
if self.outbuf:
|
||||||
w.add(self.wsock)
|
_add(w, self.wsock)
|
||||||
|
|
||||||
def callback(self):
|
def callback(self):
|
||||||
(r,w,x) = select.select([self.rsock], [self.wsock], [], 0)
|
(r,w,x) = select.select([self.rsock], [self.wsock], [], 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user