当前位置: 首页>>代码示例>>Python>>正文


Python stem.DescriptorUnavailable方法代码示例

本文整理汇总了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 
开发者ID:Tycx2ry,项目名称:llk,代码行数:39,代码来源:control.py

示例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 
开发者ID:freedomofpress,项目名称:securedrop-reachability-monitor,代码行数:58,代码来源:reachability-monitor.py

示例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) 
开发者ID:Tycx2ry,项目名称:llk,代码行数:58,代码来源:control.py

示例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 
开发者ID:Tycx2ry,项目名称:llk,代码行数:53,代码来源:control.py


注:本文中的stem.DescriptorUnavailable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。