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
764e1499
Commit
764e1499
authored
7 years ago
by
Matt Traudt
Committed by
Matt Traudt
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Generalize the ability to connect to ip:port over a specific circuit
parent
c780edf2
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
+6
-19
6 additions, 19 deletions
sbws/core/scanner.py
sbws/util/stem.py
+14
-1
14 additions, 1 deletion
sbws/util/stem.py
with
20 additions
and
20 deletions
sbws/core/scanner.py
+
6
−
19
View file @
764e1499
...
...
@@ -9,22 +9,19 @@ 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
..util.sockio
import
(
make_socket
,
close_socket
)
from
sbws.globals
import
(
fail_hard
,
is_initted
,
time_now
)
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
socket
import
time
import
os
import
logging
end_event
=
Event
()
stream_building_lock
=
RLock
()
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -129,24 +126,14 @@ def measure_relay(args, conf, helpers, cb, rl, relay):
relay
,
[
relay
.
fingerprint
,
helper
.
fingerprint
],
helper
.
server_host
,
our_nick
)
circ_fps
=
cb
.
get_circuit_path
(
circ_id
)
# A function that attaches all streams that gets created on
# connect() to the given circuit
listener
=
stem_utils
.
attach_stream_to_circuit_listener
(
cb
.
controller
,
circ_id
)
with
stream_building_lock
:
# Tell stem about our listener so it can attach the stream to the
# circuit when we connect()
stem_utils
.
add_event_listener
(
cb
.
controller
,
listener
,
EventType
.
STREAM
)
s
=
make_socket
(
conf
[
'
tor
'
][
'
socks_host
'
],
conf
.
getint
(
'
tor
'
,
'
socks_port
'
))
# This call blocks until we are connected (or give up). We get attched
# to the right circuit in the background.
connected
=
socket_connect
(
s
,
helper
.
server_host
,
helper
.
server_port
)
stem_utils
.
remove_event_listener
(
cb
.
controller
,
listener
)
s
=
make_socket
(
conf
[
'
tor
'
][
'
socks_host
'
],
conf
.
getint
(
'
tor
'
,
'
socks_port
'
))
connected
=
stem_utils
.
connect_over_circuit
(
cb
.
controller
,
circ_id
,
s
,
helper
.
server_host
,
helper
.
server_port
)
if
not
connected
:
log
.
info
(
'
Unable to connect to %s:%d
'
,
helper
.
server_host
,
helper
.
server_port
)
close_socket
(
s
)
cb
.
close_circuit
(
circ_id
)
return
if
not
authenticate_to_server
(
s
,
helper
.
password
):
...
...
This diff is collapsed.
Click to expand it.
sbws/util/stem.py
+
14
−
1
View file @
764e1499
from
stem.control
import
Controller
from
stem.control
import
(
Controller
,
EventType
)
from
stem
import
(
SocketError
,
InvalidRequest
,
UnsatisfiableRequest
)
from
stem.connection
import
IncorrectSocketType
from
configparser
import
ConfigParser
from
threading
import
RLock
import
logging
from
sbws.util.sockio
import
socket_connect
log
=
logging
.
getLogger
(
__name__
)
stream_building_lock
=
RLock
()
__all__
=
[
'
add_event_listener
'
,
'
remove_event_listener
'
,
...
...
@@ -58,6 +62,15 @@ def remove_event_listener(controller, func):
controller
.
remove_event_listener
(
func
)
def
connect_over_circuit
(
controller
,
circ_id
,
sock
,
host
,
port
):
with
stream_building_lock
:
listener
=
attach_stream_to_circuit_listener
(
controller
,
circ_id
)
add_event_listener
(
controller
,
listener
,
EventType
.
STREAM
)
connected
=
socket_connect
(
sock
,
host
,
port
)
remove_event_listener
(
controller
,
listener
)
return
connected
def
init_controller
(
port
=
None
,
path
=
None
,
set_custom_stream_settings
=
True
):
# make sure only one is set
assert
port
is
not
None
or
path
is
not
None
...
...
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