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

Python3 #107

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions bwscanner/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def random_path_to_exit(exit_relay, relays):
return candidate_relays[0:2] + [exit_relay]


# pylint: disable=no-member
class CircuitGenerator(object):
def __init__(self, state):
self.state = state
# FIXME: don't we want to remove the exits from the list of relays?
self.relays = list(set(r for r in state.routers.values() if r))
self.relays = list(set(r for r in list(state.routers.values()) if r))
self.exits = [relay for relay in self.relays if is_valid_exit(relay)]

def __iter__(self):
Expand All @@ -41,7 +42,11 @@ def __iter__(self):
def next(self):
raise NotImplementedError

def __next__(self):
return self.next()


# pylint: disable=no-member
class TwoHop(CircuitGenerator):
"""
Select two hop circuits with the relay to be measured and a random exit
Expand All @@ -63,7 +68,7 @@ def circuit_generator():
choose an exit relay of similar bandwidth for the circuit
"""
num_relays = len(self.relays)
relay_subset = range(this_partition-1, num_relays, partitions)
relay_subset = list(range(this_partition-1, num_relays, partitions))
log.info("Performing a measurement scan with {count} relays.", count=len(relay_subset))

# Choose relays in a random order fromm the relays in this partition set.
Expand Down Expand Up @@ -108,3 +113,6 @@ def exit_by_bw(self, relay):

def next(self):
return self._circgen.next()

def __next__(self):
return self.next()
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ click==6.6
pyOpenSSL==17.5.0
service-identity==16.0.0
stem>=1.4.0
Twisted==16.2.0
txsocksx==1.15.0.2
Twisted==16.6.0
txtorcon==0.20.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def get_version():
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Topic :: System :: Networking',
'Topic :: Internet :: Proxy Servers',
'Topic :: Internet',
Expand All @@ -48,7 +49,6 @@ def get_version():
'test': ['tox', 'pytest'],
'doc': ['sphinx', 'pylint']
},
python_requires=">=2.7",
# data_files = [('path', ['filename'])]
data_files=[],
entry_points={
Expand Down
6 changes: 3 additions & 3 deletions test/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_send_multiple_chunk_size(self):
test_data = {'test_method': 'test_send_chunk_size'}
num_chunks = randint(121, 212)
deferreds = []
for _ in xrange(chunk_size*num_chunks):
for _ in range(chunk_size*num_chunks):
deferreds += [self.result_sink.send(test_data)]

def validate(_, dirname, fnames):
Expand All @@ -42,7 +42,7 @@ def test_send_chunk_size(self):
self.result_sink = ResultSink(self.tmpdir, chunk_size=chunk_size)
test_data = {'test_method': 'test_send_chunk_size'}
deferreds = []
for _ in xrange(chunk_size):
for _ in range(chunk_size):
deferreds += [self.result_sink.send(test_data)]

def validate(_, dirname, fnames):
Expand All @@ -65,7 +65,7 @@ def test_end_flush(self):
self.result_sink = ResultSink(self.tmpdir, chunk_size=chunk_size)
test_data = {'test_method': 'test_send_chunk_size'}
deferreds = []
for _ in xrange(chunk_size + 3):
for _ in range(chunk_size + 3):
deferreds += [self.result_sink.send(test_data)]

def validate(_, dirname, fnames):
Expand Down