Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 3427727

Browse files
committed
remove OnionRoutedAgent and OnionRoutedTCPEndpoint
1 parent d62dca2 commit 3427727

5 files changed

Lines changed: 5 additions & 177 deletions

File tree

bwscanner/attacher.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,93 +6,6 @@
66
from bwscanner.logger import log
77

88

9-
@implementer(IStreamAttacher)
10-
class SOCKSClientStreamAttacher(CircuitListenerMixin, StreamListenerMixin):
11-
"""
12-
An attacher that builds a chosen path for a client identified by
13-
its source port and ip address.
14-
"""
15-
16-
def __init__(self, state):
17-
"""
18-
Instantiates a SOCKSClientStreamAttacher with a
19-
txtorcon.torstate.TorState instance.
20-
"""
21-
self.state = state
22-
self.waiting_circuits = {}
23-
self.expected_streams = {}
24-
self.state.add_stream_listener(self)
25-
self.state.add_circuit_listener(self)
26-
27-
def create_circuit(self, host, port, path, using_guards=False):
28-
"""
29-
Specify the path for streams created on a specific client
30-
SOCKS connection.
31-
32-
Returns a deferred that calls back with the constructed circuit
33-
or errs back with a failure instance.
34-
"""
35-
circ_deferred = defer.Deferred()
36-
key = (str(host), int(port))
37-
self.expected_streams[key] = circ_deferred
38-
39-
def add_to_waiting(circ):
40-
self.waiting_circuits[circ.id] = (circ, circ_deferred)
41-
return circ
42-
43-
circuit_build = self.state.build_circuit(
44-
path, using_guards=using_guards)
45-
circuit_build.addCallback(add_to_waiting)
46-
return circ_deferred
47-
48-
def attach_stream(self, stream, _):
49-
"""
50-
Attaches a NEW stream to the circuit created for it by matching the
51-
source address and source port of the SOCKS client connection to the
52-
corresponding circuit in the expected_streams dictionary.
53-
54-
Returns a deferred that calls back with the appropriate circuit,
55-
or None if there is no matching entry.
56-
57-
Note, Tor can be configured to leave streams unattached by setting
58-
the "__LeaveStreamsUnattached" torrc option to "1".
59-
"""
60-
try:
61-
key = (str(stream.source_addr), int(stream.source_port))
62-
return self.expected_streams.pop(key)
63-
except KeyError:
64-
# We didn't expect this stream, so let Tor handle it
65-
return None
66-
67-
def circuit_built(self, circuit):
68-
"""
69-
Calls back the deferred awaiting the circuit build with the
70-
circuit object.
71-
"""
72-
if circuit.purpose != "GENERAL":
73-
return
74-
try:
75-
(_, circ_deferred) = self.waiting_circuits.pop(circuit.id)
76-
circ_deferred.callback(circuit)
77-
except KeyError:
78-
pass
79-
80-
def circuit_failed(self, circuit, **kw):
81-
"""
82-
Calls the errback of the deferred waiting the circuit build if the
83-
circuit build failed. The failure reason is contained in the circuit
84-
object. The corresponding state in waiting_circuits is removed.
85-
86-
If the circuit failure did not correspond to a circuit requested
87-
by create_circuit, it is ignored.
88-
"""
89-
try:
90-
(circ, circ_deferred) = self.waiting_circuits.pop(circuit.id)
91-
circ_deferred.errback(circ)
92-
except KeyError:
93-
pass
94-
95-
969
class StreamClosedListener(StreamListenerMixin):
9710
"""
9811
Closes the contained circuit if the listened stream closes.

test/template.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from twisted.trial import unittest
66

77
from bwscanner import circuit
8-
from bwscanner.attacher import SOCKSClientStreamAttacher, connect_to_tor
8+
from bwscanner.attacher import connect_to_tor
99

1010

1111
class TorTestCase(unittest.TestCase):
@@ -18,9 +18,6 @@ def setUp(self):
1818
circuit_build_timeout=30,
1919
)
2020

21-
self.attacher = SOCKSClientStreamAttacher(self.tor_state)
22-
yield self.tor_state.set_attacher(self.attacher, reactor)
23-
2421
@property
2522
def routers(self):
2623
return list(set(self.tor_state.routers.values()))
@@ -35,7 +32,6 @@ def random_path(self):
3532

3633
@defer.inlineCallbacks
3734
def tearDown(self):
38-
yield self.tor_state.set_attacher(None, reactor)
3935
yield self.tor_state.protocol.quit()
4036
# seems to leave dirty reactor otherwise?
4137
yield self.tor_state.protocol.transport.loseConnection()

test/test_attacher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def listen(self, _):
5050

5151

5252
class TestSOCKSClientStreamAttacher(TorTestCase):
53+
skip = "deprecated"
54+
5355
@defer.inlineCallbacks
5456
def setUp(self):
5557
yield super(TestSOCKSClientStreamAttacher, self).setUp()

test/test_fetcher.py

Lines changed: 0 additions & 84 deletions
This file was deleted.

test/test_listener.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def setUp(self):
3737
@defer.inlineCallbacks
3838
def test_circuit_lifecycle(self):
3939
path = self.random_path()
40-
circ = yield self.attacher.create_circuit('127.0.0.1', 1234, path)
40+
circ = yield self.tor_state.build_circuit(path)
41+
yield circ.when_built()
4142
self.assertIsInstance(circ, Circuit)
4243
self.assertEqual(circ.path, path)
4344
circuit_lifecycle = self.circuit_event_listener.circuits[circ]

0 commit comments

Comments
 (0)