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
2c21c8a2
Commit
2c21c8a2
authored
6 years ago
by
Matt Traudt
Browse files
Options
Downloads
Patches
Plain Diff
Try to avoid some persistent exceptions when checking exit policies
parent
96be8c37
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sbws/lib/relaylist.py
+25
-4
25 additions, 4 deletions
sbws/lib/relaylist.py
with
25 additions
and
4 deletions
sbws/lib/relaylist.py
+
25
−
4
View file @
2c21c8a2
import
sbws.util.stem
as
stem_utils
from
stem
import
Flag
from
stem
import
DescriptorUnavailable
from
stem.util.connection
import
is_valid_ipv4_address
from
stem.util.connection
import
is_valid_ipv6_address
import
random
import
time
import
logging
from
sbws.globals
import
resolve
log
=
logging
.
getLogger
(
__name__
)
class
RelayList
:
'''
Keeps a list of all relays in the current Tor network and updates it
...
...
@@ -89,10 +93,27 @@ class RelayList:
assert
is_valid_ipv4_address
(
host
)
or
is_valid_ipv6_address
(
host
)
exits
=
[]
for
exit
in
self
.
exits
:
policy
=
exit
.
exit_policy
if
exit
.
exit_policy
\
else
c
.
get_microdescriptor
(
relay
=
exit
.
fingerprint
).
exit_policy
if
policy
is
not
None
and
policy
.
can_exit_to
(
host
,
port
):
exits
.
append
(
exit
)
# If we have the exit policy already, easy
if
exit
.
exit_policy
:
policy
=
exit
.
exit_policy
else
:
# Otherwise ask Tor for the microdescriptor and assume the exit
# won't work if the desc isn't available
try
:
fp
=
exit
.
fingerprint
policy
=
c
.
get_microdescriptor
(
fp
).
exit_policy
except
DescriptorUnavailable
as
e
:
log
.
debug
(
e
)
continue
# There's a weird KeyError we sometimes hit when checking
# policy.can_exit_to()... so catch that and log about it. Maybe
# someday it can be fixed?
try
:
if
policy
is
not
None
and
policy
.
can_exit_to
(
port
=
port
):
exits
.
append
(
exit
)
except
KeyError
as
e
:
log
.
exception
(
'
Got that KeyError in stem again...: %s
'
,
e
)
continue
return
exits
def
random_relay
(
self
):
...
...
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