Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Network Health
sbws
Commits
9e089b72
Commit
9e089b72
authored
Dec 01, 2018
by
juga
Browse files
relaylist: add property is_unmeasured
parent
7bb7c738
Changes
5
Hide whitespace changes
Inline
Side-by-side
sbws/core/scanner.py
View file @
9e089b72
...
...
@@ -143,7 +143,7 @@ def _pick_ideal_second_hop(relay, dest, rl, cont, is_exit):
log
.
debug
(
'Picking a 2nd hop to measure %s from %d choices. is_exit=%s'
,
relay
.
nickname
,
len
(
candidates
),
is_exit
)
for
min_bw_factor
in
[
2
,
1.75
,
1.5
,
1.25
,
1
]:
min_bw
=
relay
.
bandwidth
*
min_bw_factor
min_bw
=
relay
.
consensus_
bandwidth
*
min_bw_factor
new_candidates
=
stem_utils
.
only_relays_with_bandwidth
(
cont
,
candidates
,
min_bw
=
min_bw
)
if
len
(
new_candidates
)
>
0
:
...
...
@@ -152,15 +152,15 @@ def _pick_ideal_second_hop(relay, dest, rl, cont, is_exit):
'Found %d candidate 2nd hops with at least %sx the bandwidth '
'of %s. Returning %s (bw=%s).'
,
len
(
new_candidates
),
min_bw_factor
,
relay
.
nickname
,
chosen
.
nickname
,
chosen
.
bandwidth
)
chosen
.
nickname
,
chosen
.
consensus_
bandwidth
)
return
chosen
candidates
=
sorted
(
candidates
,
key
=
lambda
r
:
r
.
bandwidth
,
reverse
=
True
)
chosen
=
candidates
[
0
]
log
.
debug
(
'Didn
\'
t find any 2nd hops at least as fast as %s (bw=%s). It
\'
s '
'probably really fast. Returning %s (bw=%s), the fastest '
'candidate we have.'
,
relay
.
nickname
,
relay
.
bandwidth
,
chosen
.
nickname
,
chosen
.
bandwidth
)
'candidate we have.'
,
relay
.
nickname
,
relay
.
consensus_
bandwidth
,
chosen
.
nickname
,
chosen
.
consensus_
bandwidth
)
return
chosen
...
...
sbws/lib/destination.py
View file @
9e089b72
...
...
@@ -184,7 +184,8 @@ class DestinationList:
# Keep the fastest 10% of exits, or 3, whichever is larger
num_keep
=
int
(
max
(
3
,
len
(
possible_exits
)
*
0.1
))
possible_exits
=
sorted
(
possible_exits
,
key
=
lambda
e
:
e
.
bandwidth
,
reverse
=
True
)
possible_exits
,
key
=
lambda
e
:
e
.
consensus_bandwidth
,
reverse
=
True
)
exits
=
possible_exits
[
0
:
num_keep
]
if
len
(
exits
)
<
1
:
log
.
warning
(
"There are no exits to perform usability tests."
)
...
...
sbws/lib/relaylist.py
View file @
9e089b72
...
...
@@ -83,9 +83,16 @@ class Relay:
return
self
.
_from_desc
(
'observed_bandwidth'
)
@
property
def
bandwidth
(
self
):
def
consensus_
bandwidth
(
self
):
return
self
.
_from_ns
(
'bandwidth'
)
@
property
def
consensus_bandwidth_is_unmeasured
(
self
):
# measured appears only votes, unmeasured appears in consensus
# therefore is_unmeasured is needed to know whether the bandwidth
# value in consensus is comming from bwauth measurements or not.
return
self
.
_from_ns
(
'is_unmeasured'
)
@
property
def
address
(
self
):
return
self
.
_from_ns
(
'address'
)
...
...
sbws/util/stem.py
View file @
9e089b72
...
...
@@ -230,10 +230,10 @@ def only_relays_with_bandwidth(controller, relays, min_bw=None, max_bw=None):
assert
max_bw
is
None
or
max_bw
>=
0
ret
=
[]
for
relay
in
relays
:
assert
hasattr
(
relay
,
'bandwidth'
)
if
min_bw
is
not
None
and
relay
.
bandwidth
<
min_bw
:
assert
hasattr
(
relay
,
'
consensus_
bandwidth'
)
if
min_bw
is
not
None
and
relay
.
consensus_
bandwidth
<
min_bw
:
continue
if
max_bw
is
not
None
and
relay
.
bandwidth
>
max_bw
:
if
max_bw
is
not
None
and
relay
.
consensus_
bandwidth
>
max_bw
:
continue
ret
.
append
(
relay
)
return
ret
...
...
tests/integration/lib/test_relaylist.py
View file @
9e089b72
...
...
@@ -11,7 +11,7 @@ def test_relay_properties(persistent_launch_tor):
assert
'Authority'
in
relay
.
flags
assert
not
relay
.
exit_policy
or
not
relay
.
exit_policy
.
is_exiting_allowed
()
assert
relay
.
average_bandwidth
==
1073741824
assert
relay
.
bandwidth
==
0
assert
relay
.
consensus_
bandwidth
==
0
assert
relay
.
address
==
'127.10.0.1'
assert
relay
.
master_key_ed25519
==
\
'wLglSEw9/DHfpNrlrqjVRSnGLVWfnm0vYxkryH4aT6Q'
Write
Preview
Supports
Markdown
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