Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
84376284
Commit
84376284
authored
Oct 02, 2010
by
Avery Pennarun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out common mainloop code between client and server.
Also improve the socket message output a bit.
parent
b0f061e2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
30 deletions
+34
-30
client.py
client.py
+2
-14
server.py
server.py
+1
-16
ssnet.py
ssnet.py
+31
-0
No files found.
client.py
View file @
84376284
...
...
@@ -4,6 +4,7 @@ import helpers, ssnet, ssh
from
ssnet
import
SockWrapper
,
Handler
,
Proxy
,
Mux
,
MuxWrapper
from
helpers
import
*
def
original_dst
(
sock
):
try
:
SO_ORIGINAL_DST
=
80
...
...
@@ -176,20 +177,7 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
if
rv
:
raise
Fatal
(
'server died with error code
%
d'
%
rv
)
r
=
[]
w
=
[]
x
=
[]
handlers
=
filter
(
lambda
s
:
s
.
ok
,
handlers
)
for
s
in
handlers
:
s
.
pre_select
(
r
,
w
,
x
)
debug2
(
'Waiting:
%
d[
%
d,
%
d,
%
d]...
\n
'
%
(
len
(
handlers
),
len
(
r
),
len
(
w
),
len
(
x
)))
(
r
,
w
,
x
)
=
select
.
select
(
r
,
w
,
x
)
#log('r=%r w=%r x=%r\n' % (r,w,x))
ready
=
r
+
w
+
x
for
s
in
handlers
:
if
list_contains_any
(
s
.
socks
,
ready
):
s
.
callback
()
ssnet
.
runonce
(
handlers
,
mux
)
if
use_server
:
mux
.
callback
()
mux
.
check_fullness
()
...
...
server.py
View file @
84376284
...
...
@@ -162,21 +162,6 @@ def main():
if
rpid
:
raise
Fatal
(
'hostwatch exited unexpectedly: code 0x
%04
x
\n
'
%
rv
)
r
=
[]
w
=
[]
x
=
[]
handlers
=
filter
(
lambda
s
:
s
.
ok
,
handlers
)
for
s
in
handlers
:
s
.
pre_select
(
r
,
w
,
x
)
debug2
(
'Waiting:
%
d[
%
d,
%
d,
%
d] (fullness=
%
d/
%
d)...
\n
'
%
(
len
(
handlers
),
len
(
r
),
len
(
w
),
len
(
x
),
mux
.
fullness
,
mux
.
too_full
))
(
r
,
w
,
x
)
=
select
.
select
(
r
,
w
,
x
)
#log('r=%r w=%r x=%r\n' % (r,w,x))
ready
=
r
+
w
+
x
for
s
in
handlers
:
#debug2('check: %r: %r\n' % (s, s.socks & ready))
if
list_contains_any
(
s
.
socks
,
ready
):
s
.
callback
()
ssnet
.
runonce
(
handlers
,
mux
)
mux
.
check_fullness
()
mux
.
callback
()
ssnet.py
View file @
84376284
...
...
@@ -36,6 +36,17 @@ def _add(l, elem):
l
.
append
(
elem
)
def
_fds
(
l
):
out
=
[]
for
i
in
l
:
try
:
out
.
append
(
i
.
fileno
())
except
AttributeError
:
out
.
append
(
i
)
out
.
sort
()
return
out
def
_nb_clean
(
func
,
*
args
):
try
:
return
func
(
*
args
)
...
...
@@ -43,6 +54,7 @@ def _nb_clean(func, *args):
if
e
.
errno
not
in
(
errno
.
EWOULDBLOCK
,
errno
.
EAGAIN
,
errno
.
EPIPE
):
raise
else
:
debug3
(
'
%
s: err was:
%
s
\n
'
%
(
func
.
__name__
,
e
))
return
None
...
...
@@ -429,3 +441,22 @@ def connect_dst(ip, port):
return
SockWrapper
(
outsock
,
outsock
,
connect_to
=
(
ip
,
port
),
peername
=
'
%
s:
%
d'
%
(
ip
,
port
))
def
runonce
(
handlers
,
mux
):
r
=
[]
w
=
[]
x
=
[]
handlers
=
filter
(
lambda
s
:
s
.
ok
,
handlers
)
for
s
in
handlers
:
s
.
pre_select
(
r
,
w
,
x
)
debug2
(
'Waiting:
%
d r=
%
r w=
%
r x=
%
r (fullness=
%
d/
%
d)
\n
'
%
(
len
(
handlers
),
_fds
(
r
),
_fds
(
w
),
_fds
(
x
),
mux
.
fullness
,
mux
.
too_full
))
(
r
,
w
,
x
)
=
select
.
select
(
r
,
w
,
x
)
debug2
(
' Ready:
%
d r=
%
r w=
%
r x=
%
r
\n
'
%
(
len
(
handlers
),
_fds
(
r
),
_fds
(
w
),
_fds
(
x
)))
ready
=
r
+
w
+
x
for
s
in
handlers
:
if
list_contains_any
(
s
.
socks
,
ready
):
s
.
callback
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment