Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sbws
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
juga
sbws
Commits
635276e8
Commit
635276e8
authored
7 years ago
by
Matt Traudt
Committed by
Matt Traudt
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Move some functions so other code can use them
parent
82fb154f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sbws/core/scanner.py
+2
-33
2 additions, 33 deletions
sbws/core/scanner.py
sbws/util/sockio.py
+46
-0
46 additions, 0 deletions
sbws/util/sockio.py
with
48 additions
and
33 deletions
sbws/core/scanner.py
+
2
−
33
View file @
635276e8
...
...
@@ -9,15 +9,15 @@ from ..lib.relaylist import RelayList
from
..lib.relayprioritizer
import
RelayPrioritizer
from
..lib.helperrelay
import
HelperRelayList
from
..util.simpleauth
import
authenticate_to_server
from
..util.sockio
import
(
make_socket
,
close_socket
,
socket_connect
)
from
sbws.globals
import
(
fail_hard
,
is_initted
,
time_now
)
from
sbws.globals
import
(
MIN_REQ_BYTES
,
MAX_REQ_BYTES
,
SOCKET_TIMEOUT
)
from
sbws.globals
import
(
MIN_REQ_BYTES
,
MAX_REQ_BYTES
)
import
sbws.util.stem
as
stem_utils
from
stem.control
import
EventType
from
argparse
import
ArgumentDefaultsHelpFormatter
from
multiprocessing.dummy
import
Pool
from
threading
import
Event
from
threading
import
RLock
import
socks
import
socket
import
time
import
os
...
...
@@ -28,37 +28,6 @@ stream_building_lock = RLock()
log
=
logging
.
getLogger
(
__name__
)
def
make_socket
(
socks_host
,
socks_port
):
'''
Make a socket that uses the provided socks5 proxy. Note at this point
the socket hasn
'
t connect()ed anywhere
'''
s
=
socks
.
socksocket
()
s
.
set_proxy
(
socks
.
PROXY_TYPE_SOCKS5
,
socks_host
,
socks_port
)
s
.
settimeout
(
SOCKET_TIMEOUT
)
return
s
def
close_socket
(
s
):
'''
Close the socket, and ignore errors
'''
try
:
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
except
Exception
:
pass
def
socket_connect
(
s
,
addr
,
port
):
'''
connect() to addr:port on the given socket. Unknown compatibility with
IPv6. Works with IPv4 and hostnames
'''
try
:
s
.
connect
((
addr
,
port
))
log
.
debug
(
'
Connected to %s:%d via %d
'
,
addr
,
port
,
s
.
fileno
())
except
(
socket
.
timeout
,
socks
.
GeneralProxyError
,
socks
.
ProxyConnectionError
)
as
e
:
log
.
warning
(
e
)
return
False
return
True
def
tell_server_amount
(
sock
,
expected_amount
):
'''
Returns True on success; else False
'''
assert
expected_amount
>=
MIN_REQ_BYTES
...
...
This diff is collapsed.
Click to expand it.
sbws/util/sockio.py
+
46
−
0
View file @
635276e8
from
sbws.globals
import
SOCKET_TIMEOUT
import
socket
import
socks
import
logging
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -45,3 +47,47 @@ def read_line(s, max_len=None):
if
max_len
is
not
None
and
len
(
chars
)
>=
max_len
:
return
chars
[
0
:
max_len
]
return
chars
def
make_socket
(
socks_host
,
socks_port
):
'''
Make a socket that uses the provided socks5 proxy. Note at this point
the socket hasn
'
t ``connect()``ed anywhere.
:param str socks_host: IP address or hostname of the socks5 proxy to use
:param int socks_port: Port of the socks5 proxy to use
:returns: A socket ready to ``connect()`` somewhere
'''
s
=
socks
.
socksocket
()
s
.
set_proxy
(
socks
.
PROXY_TYPE_SOCKS5
,
socks_host
,
socks_port
)
s
.
settimeout
(
SOCKET_TIMEOUT
)
return
s
def
close_socket
(
s
):
'''
Close the socket, and ignore any errors.
'''
try
:
s
.
shutdown
(
socket
.
SHUT_RDWR
)
s
.
close
()
except
Exception
:
pass
def
socket_connect
(
s
,
addr
,
port
):
'''
``connect()`` to addr:port on the given socket. **addr** can be a hostname,
IPv4, or IPv6 address.
:param socket s: Socket, possibly through a socks5 proxy
:param str addr: host to connect to
:param int port: port to connect to
:returns: True if connect was successful, otherwise False.
'''
try
:
s
.
connect
((
addr
,
port
))
log
.
debug
(
'
Connected to %s:%d via %d
'
,
addr
,
port
,
s
.
fileno
())
except
(
socket
.
timeout
,
socks
.
GeneralProxyError
,
socks
.
ProxyConnectionError
)
as
e
:
log
.
warning
(
e
)
return
False
return
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment