本文整理匯總了Python中stem.DescriptorUnavailable方法的典型用法代碼示例。如果您正苦於以下問題:Python stem.DescriptorUnavailable方法的具體用法?Python stem.DescriptorUnavailable怎麽用?Python stem.DescriptorUnavailable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類stem
的用法示例。
在下文中一共展示了stem.DescriptorUnavailable方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_server_descriptors
# 需要導入模塊: import stem [as 別名]
# 或者: from stem import DescriptorUnavailable [as 別名]
def get_server_descriptors(self, default = UNDEFINED):
"""
get_server_descriptors(default = UNDEFINED)
Provides an iterator for all of the server descriptors that tor currently
knows about.
**As of Tor version 0.2.3.25 relays no longer get server descriptors by
default.** It's advised that you use microdescriptors instead, but if you
really need server descriptors then you can get them by setting
'UseMicrodescriptors 0'.
:param list default: items to provide if the query fails
:returns: iterates over
:class:`~stem.descriptor.server_descriptor.RelayDescriptor` for relays in
the tor network
:raises: :class:`stem.ControllerError` if unable to query tor and no
default was provided
"""
# TODO: We should iterate over the descriptors as they're read from the
# socket rather than reading the whole thing into memory.
#
# https://trac.torproject.org/8248
desc_content = self.get_info('desc/all-recent', get_bytes = True)
if not desc_content:
if not self._is_server_descriptors_available():
raise stem.ControllerError(SERVER_DESCRIPTORS_UNSUPPORTED)
else:
raise stem.DescriptorUnavailable('Descriptor information is unavailable, tor might still be downloading it')
for desc in stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_content)):
yield desc
示例2: check_instances
# 需要導入模塊: import stem [as 別名]
# 或者: from stem import DescriptorUnavailable [as 別名]
def check_instances(self, instances, timeout=30):
"""Visits each SD found in the directory and records its version
string or the string 'unreachable', as well as relevant circuit
information and descriptor information."""
opener = build_opener(SocksiPyHandler(socks.SOCKS5, "127.0.0.1", 9050))
for instance in instances:
hs_url = instance.get("ths_address")
try:
response = opener.open("http://"+hs_url,
timeout=timeout).read().decode()
version_str = search("Powered by SecureDrop [0-9.]+",
response).group(0)
instance["version"] = version_str.split()[-1][:-1]
except (socks.SOCKS5Error, socks.GeneralProxyError,
urllib.error.URLError):
instance["version"] = "unreachable"
try:
# The reason that we don't call the
# get_hidden_service_descriptor method on all URLs is that
# it's unreliable for services that are actually up.
# Basically, the method will never return or timeout. With
# services that cannot be reached, it usually quickly
# fails with the stem.DescriptorUnavailable exception. This
# seems to be the leading cause of unreachability.
hs_desc = self.controller.get_hidden_service_descriptor(hs_url)
instance["intro_pts"] = hs_desc.introduction_points_content.decode()
except stem.DescriptorUnavailable:
instance["intro_pts"] = "descriptor unavailable"
print(instance)
continue
pass
intro_circs = []
rend_circs = []
for circuit in self.controller.get_circuits():
if circuit.purpose == "HS_CLIENT_INTRO":
intro_circs.append(dict(path=circuit.path,
reason=circuit.reason,
remote_reason=circuit.remote_reason))
if circuit.purpose == "HS_CLIENT_REND":
rend_circs.append(dict(path=circuit.path,
state=circuit.hs_state,
reason=circuit.reason,
remote_reason=circuit.remote_reason))
self.controller.close_circuit(circuit.id)
instance["intro_circs"] = intro_circs
instance["rend_circs"] = rend_circs
if instance["version"] == "unreachable":
print(instance)
return instances
示例3: get_microdescriptor
# 需要導入模塊: import stem [as 別名]
# 或者: from stem import DescriptorUnavailable [as 別名]
def get_microdescriptor(self, relay = None, default = UNDEFINED):
"""
get_microdescriptor(relay = None, default = UNDEFINED)
Provides the microdescriptor for the relay with the given fingerprint or
nickname. If the relay identifier could be either a fingerprint *or*
nickname then it's queried as a fingerprint.
If no **relay** is provided then this defaults to ourselves. Remember that
this requires that we've retrieved our own descriptor from remote
authorities so this both won't be available for newly started relays and
may be up to around an hour out of date.
.. versionchanged:: 1.3.0
Changed so we'd fetch our own descriptor if no 'relay' is provided.
:param str relay: fingerprint or nickname of the relay to be queried
:param object default: response if the query fails
:returns: :class:`~stem.descriptor.microdescriptor.Microdescriptor` for the given relay
:raises:
* :class:`stem.DescriptorUnavailable` if unable to provide a descriptor
for the given relay
* :class:`stem.ControllerError` if unable to query the descriptor
* **ValueError** if **relay** doesn't conform with the pattern for being
a fingerprint or nickname
An exception is only raised if we weren't provided a default response.
"""
if relay is None:
try:
relay = self.get_info('fingerprint')
except stem.ControllerError as exc:
raise stem.ControllerError('Unable to determine our own fingerprint: %s' % exc)
if stem.util.tor_tools.is_valid_fingerprint(relay):
query = 'md/id/%s' % relay
elif stem.util.tor_tools.is_valid_nickname(relay):
query = 'md/name/%s' % relay
else:
raise ValueError("'%s' isn't a valid fingerprint or nickname" % relay)
try:
desc_content = self.get_info(query, get_bytes = True)
except stem.InvalidArguments as exc:
if str(exc).startswith('GETINFO request contained unrecognized keywords:'):
raise stem.DescriptorUnavailable("Tor was unable to provide the descriptor for '%s'" % relay)
else:
raise exc
if not desc_content:
raise stem.DescriptorUnavailable('Descriptor information is unavailable, tor might still be downloading it')
return stem.descriptor.microdescriptor.Microdescriptor(desc_content)
示例4: get_network_statuses
# 需要導入模塊: import stem [as 別名]
# 或者: from stem import DescriptorUnavailable [as 別名]
def get_network_statuses(self, default = UNDEFINED):
"""
get_network_statuses(default = UNDEFINED)
Provides an iterator for all of the router status entries that tor
currently knows about.
This provides
:class:`~stem.descriptor.router_status_entry.RouterStatusEntryMicroV3`
instances if tor is using microdescriptors...
::
controller.get_conf('UseMicrodescriptors', '0') == '1'
... and :class:`~stem.descriptor.router_status_entry.RouterStatusEntryV3`
otherwise.
:param list default: items to provide if the query fails
:returns: iterates over
:class:`~stem.descriptor.router_status_entry.RouterStatusEntry` for
relays in the tor network
:raises: :class:`stem.ControllerError` if unable to query tor and no
default was provided
"""
# TODO: We should iterate over the descriptors as they're read from the
# socket rather than reading the whole thing into memory.
#
# https://trac.torproject.org/8248
if self.get_conf('UseMicrodescriptors', '0') == '1':
desc_class = stem.descriptor.router_status_entry.RouterStatusEntryMicroV3
else:
desc_class = stem.descriptor.router_status_entry.RouterStatusEntryV3
desc_content = self.get_info('ns/all', get_bytes = True)
if not desc_content:
raise stem.DescriptorUnavailable('Descriptor information is unavailable, tor might still be downloading it')
desc_iterator = stem.descriptor.router_status_entry._parse_file(
io.BytesIO(desc_content),
True,
entry_class = desc_class,
)
for desc in desc_iterator:
yield desc