File: votes_by_bandwidth_authorities.py

package info (click to toggle)
python-stem 1.8.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,152 kB
  • sloc: python: 33,747; java: 312; makefile: 124; sh: 14
file content (32 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import stem.descriptor.remote
import stem.directory

# request votes from all the bandwidth authorities

queries = {}
downloader = stem.descriptor.remote.DescriptorDownloader()

for authority in stem.directory.Authority.from_cache().values():
  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

    if measured == 0:
      print('  %s is not a bandwidth authority' % authority_name)
    else:
      print('  %i measured entries and %i unmeasured' % (measured, unmeasured))
  except Exception as exc:
    print("  failed to get the vote (%s)" % exc)