Пример #1
0
    def _getInitialEndpoints(self):
        '''Get an initial set of servers to download the network status
        documents from.

        First try reading from the "cached-consensus" file. If this isn't
        successful for any reason fallback to using the directory
        authorities.

        This is only called on instantiation, and any future downloads will
        already have a fresh set of V2Dir endpoints.

        .. note: We just use the directory authorities defined in stem.

        :returns: **list** containing either RouterStatusEntry objects with
            the 'V2Dir' flag or DirectoryAuthorities
        '''
        endpoints = None
        try:
            with open(DEF.CONSENSUS_CACHE_FILE, 'rb') as f:
                data = f.read()
            old_consensus = NetworkStatusDocumentV3(data)
            endpoints = self._extractV2DirEndpoints(old_consensus)
            msg = "Found {} V2Dir endpoints in cached-consensus."
            logging.debug(msg.format(len(endpoints)))
        except (IOError, ValueError) as e:
            logging.debug("Error reading from cached-consensus: {}".format(e))
            logging.debug("Falling back to directory authorities.")

        return list(endpoints) if endpoints else get_authorities().values()
Пример #2
0
    def _getInitialEndpoints(self):
        '''Get an initial set of servers to download the network status
        documents from.

        First try reading from the "cached-consensus" file. If this isn't
        successful for any reason fallback to using the directory
        authorities.

        This is only called on instantiation, and any future downloads will
        already have a fresh set of V2Dir endpoints.

        .. note: We just use the directory authorities defined in stem.

        :returns: **list** containing either RouterStatusEntry objects with
            the 'V2Dir' flag or DirectoryAuthorities
        '''
        endpoints = None
        try:
            with open(DEF.CONSENSUS_CACHE_FILE, 'rb') as f:
                data = f.read()
            old_consensus = NetworkStatusDocumentV3(data)
            endpoints = self._extractV2DirEndpoints(old_consensus)
            msg = "Found {} V2Dir endpoints in cached-consensus."
            logging.debug(msg.format(len(endpoints)))
        except (IOError, ValueError) as e:
            logging.debug("Error reading from cached-consensus: {}".format(e))
            logging.debug("Falling back to directory authorities.")

        return list(endpoints) if endpoints else get_authorities().values()
Пример #3
0
    def tutorial_example():
      from stem.descriptor import remote

      # request votes from all the bandwidth authorities

      queries = {}
      downloader = remote.DescriptorDownloader()

      for authority in remote.get_authorities().values():
        if authority.is_bandwidth_authority:
          queries[authority.nickname] = downloader.query(
            '/tor/status-vote/current/authority',
            endpoints = [(authority.address, authority.dir_port)],
          )

      for authority_name, query in queries.items():
        try:
          print("Getting %s's vote from %s:" % (authority_name, query.download_url))

          measured, unmeasured = 0, 0

          for desc in query.run():
            if desc.measured:
              measured += 1
            else:
              unmeasured += 1

          print('  %i measured entries and %i unmeasured' % (measured, unmeasured))
        except Exception as exc:
          print('  failed to get the vote (%s)' % exc)
Пример #4
0
    def tutorial_example():
      from stem.descriptor import remote

      # request votes from all the bandwidth authorities

      queries = {}
      downloader = remote.DescriptorDownloader()

      for authority in remote.get_authorities().values():
        if authority.is_bandwidth_authority:
          queries[authority.nickname] = downloader.query(
            '/tor/status-vote/current/authority',
            endpoints = [(authority.address, authority.dir_port)],
          )

      for authority_name, query in queries.items():
        try:
          print("Getting %s's vote from %s:" % (authority_name, query.download_url))

          measured, unmeasured = 0, 0

          for desc in query.run():
            if desc.measured:
              measured += 1
            else:
              unmeasured += 1

          print('  %i measured entries and %i unmeasured' % (measured, unmeasured))
        except Exception as exc:
          print("  failed to get the vote (%s)" % exc)
Пример #5
0
    def _scheduledConsensusUpdate(self, initial=False):
        logging.debug("MicroconsensusManager running scheduled consensus " "update.")
        if initial is True or self._consensus is None:
            v2dirs = _readV2DirsFromCacheFile() or get_authorities().values()
        else:
            v2dirs = getV2DirsFromConsensus(self._consensus)

        try:
            self._consensus = yield self._downloadMicroconsensus(v2dirs)
        except ConsensusDownloadFailed as e:
            logging.debug(e)
            from twisted.internet import reactor

            reactor.callLater(SLEEP, self._scheduledConsensusUpdate, initial)
            return

        self._scheduleNextConsensusDownload()
        self._servePendingRequests()
        self._serveConsensusDownloadCallbacks()
Пример #6
0
    def _scheduledConsensusUpdate(self, initial=False):
        logging.debug("MicroconsensusManager running scheduled consensus "
                      "update.")
        if initial is True or self._consensus is None:
            v2dirs = _readV2DirsFromCacheFile() or get_authorities().values()
        else:
            v2dirs = getV2DirsFromConsensus(self._consensus)

        try:
            self._consensus = yield self._downloadMicroconsensus(v2dirs)
        except ConsensusDownloadFailed as e:
            logging.debug(e)
            from twisted.internet import reactor
            reactor.callLater(SLEEP, self._scheduledConsensusUpdate, initial)
            return

        self._scheduleNextConsensusDownload()
        self._servePendingRequests()
        self._serveConsensusDownloadCallbacks()
Пример #7
0
    def tutorial_example():
      from stem.descriptor import DocumentHandler, remote

      # Query all authority votes asynchronously.

      downloader = remote.DescriptorDownloader(document_handler = DocumentHandler.DOCUMENT)
      queries = OrderedDict()

      for name, authority in remote.get_authorities().items():
        if authority.v3ident is None:
          continue  # authority doens't vote if it lacks a v3ident

        queries[name] = downloader.get_vote(authority)

      # Wait for the votes to finish being downloaded, this produces a dictionary of
      # authority nicknames to their vote.

      votes = dict((name, query.run()[0]) for (name, query) in queries.items())

      # Get a superset of all the fingerprints in all the votes.

      all_fingerprints = set()

      for vote in votes.values():
        all_fingerprints.update(vote.routers.keys())

      # Finally, compare moria1's votes to maatuska.

      for fingerprint in all_fingerprints:
        moria1_vote = votes['moria1'].routers.get(fingerprint)
        maatuska_vote = votes['maatuska'].routers.get(fingerprint)

        if not moria1_vote and not maatuska_vote:
          print("both moria1 and maatuska haven't voted about %s" % fingerprint)
        elif not moria1_vote:
          print("moria1 hasn't voted about %s" % fingerprint)
        elif not maatuska_vote:
          print("maatuska hasn't voted about %s" % fingerprint)
        elif 'Running' in moria1_vote.flags and 'Running' not in maatuska_vote.flags:
          print("moria1 has the Running flag but maatuska doesn't: %s" % fingerprint)
        elif 'Running' in maatuska_vote.flags and 'Running' not in moria1_vote.flags:
          print("maatuska has the Running flag but moria1 doesn't: %s" % fingerprint)
Пример #8
0
    def tutorial_example():
      from stem.descriptor import DocumentHandler, remote

      # Query all authority votes asynchronously.

      downloader = remote.DescriptorDownloader(document_handler = DocumentHandler.DOCUMENT)
      queries = OrderedDict()

      for name, authority in remote.get_authorities().items():
        if authority.v3ident is None:
          continue  # authority doens't vote if it lacks a v3ident

        queries[name] = downloader.get_vote(authority)

      # Wait for the votes to finish being downloaded, this produces a dictionary of
      # authority nicknames to their vote.

      votes = dict((name, query.run()[0]) for (name, query) in queries.items())

      # Get a superset of all the fingerprints in all the votes.

      all_fingerprints = set()

      for vote in votes.values():
        all_fingerprints.update(vote.routers.keys())

      # Finally, compare moria1's votes to maatuska.

      for fingerprint in all_fingerprints:
        moria1_vote = votes['moria1'].routers.get(fingerprint)
        maatuska_vote = votes['maatuska'].routers.get(fingerprint)

        if not moria1_vote and not maatuska_vote:
          print("both moria1 and maatuska haven't voted about %s" % fingerprint)
        elif not moria1_vote:
          print("moria1 hasn't voted about %s" % fingerprint)
        elif not maatuska_vote:
          print("maatuska hasn't voted about %s" % fingerprint)
        elif 'Running' in moria1_vote.flags and 'Running' not in maatuska_vote.flags:
          print("moria1 has the Running flag but maatuska doesn't: %s" % fingerprint)
        elif 'Running' in maatuska_vote.flags and 'Running' not in moria1_vote.flags:
          print("maatuska has the Running flag but moria1 doesn't: %s" % fingerprint)
Пример #9
0
#!/usr/bin/env python
from stem.descriptor.remote import get_authorities
dirs = get_authorities()
for dir in dirs.keys():
    print ''
    print 'Nombre del nodo: %s \n, Direccion IP: %s \n, OR_PORT: %s \n, DIR_PORT: %s \n, Fingerprint: %s \n, V3Ident (Votar en el consenso) %s ' % (
        dirs[dir].nickname, dirs[dir].address, dirs[dir].or_port,
        dirs[dir].dir_port, dirs[dir].fingerprint, dirs[dir].v3ident)
Пример #10
0
from stem.descriptor import DocumentHandler, remote

# Query all authority votes asynchronously.

downloader = remote.DescriptorDownloader(document_handler = DocumentHandler.DOCUMENT)
queries = {}

for name, authority in remote.get_authorities().items():
  if authority.v3ident is None:
    continue  # authority doesn't vote if it lacks a v3ident

  queries[name] = downloader.get_vote(authority)

# Wait for the votes to finish being downloaded, this produces a dictionary of
# authority nicknames to their vote.

votes = dict((name, query.run()[0]) for (name, query) in queries.items())

# Get a superset of all the fingerprints in all the votes.

all_fingerprints = set()

for vote in votes.values():
  all_fingerprints.update(vote.routers.keys())

# Finally, compare moria1's votes to maatuska.

for fingerprint in all_fingerprints:
  moria1_vote = votes['moria1'].routers.get(fingerprint)
  maatuska_vote = votes['maatuska'].routers.get(fingerprint)
Пример #11
0
from collections import OrderedDict
from stem.descriptor import DocumentHandler, remote

# Query all authority votes asynchronously.

downloader = remote.DescriptorDownloader(
    document_handler=DocumentHandler.DOCUMENT)

# An ordered dictionary ensures queries are finished in the order they were
# added.

queries = OrderedDict()

for name, authority in remote.get_authorities().items():
    if authority.v3ident is None:
        continue  # authority doesn't vote if it lacks a v3ident

    queries[name] = downloader.get_vote(authority)

# Wait for the votes to finish being downloaded, this produces a dictionary of
# authority nicknames to their vote.

votes = dict((name, query.run()[0]) for (name, query) in queries.items())

# Get a superset of all the fingerprints in all the votes.

all_fingerprints = set()

for vote in votes.values():
    all_fingerprints.update(vote.routers.keys())
from stem.descriptor import remote

# request votes from all the bandwidth authorities

queries = {}
downloader = remote.DescriptorDownloader()

for authority in remote.get_authorities().values():
  if authority.is_bandwidth_authority:
    queries[authority.nickname] = downloader.query(
      '/tor/status-vote/current/authority',
      endpoints = [(authority.address, authority.dir_port)],
    )

for authority_name, query in queries.items():
  try:
    print("Getting %s's vote from %s:" % (authority_name, query.download_url))

    measured, unmeasured = 0, 0

    for desc in query.run():
      if desc.measured:
        measured += 1
      else:
        unmeasured += 1

    print('  %i measured entries and %i unmeasured' % (measured, unmeasured))
  except Exception as exc:
    print("  failed to get the vote (%s)" % exc)
Пример #13
0
from stem.descriptor import remote

# request votes from all the bandwidth authorities

queries = {}
downloader = remote.DescriptorDownloader()

for authority in remote.get_authorities().values():
    if authority.is_bandwidth_authority:
        queries[authority.nickname] = downloader.query(
            '/tor/status-vote/current/authority',
            endpoints=[(authority.address, authority.dir_port)],
        )

for authority_name, query in queries.items():
    try:
        print("Getting %s's vote from %s:" %
              (authority_name, query.download_url))

        measured, unmeasured = 0, 0

        for desc in query.run():
            if desc.measured:
                measured += 1
            else:
                unmeasured += 1

        print('  %i measured entries and %i unmeasured' %
              (measured, unmeasured))
    except Exception as exc:
        print("  failed to get the vote (%s)" % exc)