hs-min-mixed 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # This network generates a random mix of tor versions each time it is run
  2. # You'll need at least 8 runs to cover all possibilities
  3. import random
  4. rng = random.SystemRandom()
  5. # We have to use the same tags for old and new versions, otherwise switching
  6. # between them at random does not work
  7. OLD_TOR="tor-stable"
  8. # By default, Authorities are not configured as exits
  9. Authority = Node(tag="a", authority=1, relay=1, torrc="authority.tmpl")
  10. OldAuthority = Node(tag="a", authority=1, relay=1, torrc="authority.tmpl",
  11. tor=OLD_TOR)
  12. NonExitRelay = Node(tag="r", relay=1, torrc="relay-non-exit.tmpl")
  13. OldNonExitRelay = Node(tag="r", relay=1, torrc="relay-non-exit.tmpl",
  14. tor=OLD_TOR)
  15. Client = Node(tag="c", client=1, torrc="client.tmpl")
  16. OldClient = Node(tag="c", client=1, torrc="client.tmpl", tor=OLD_TOR)
  17. HS = Node(tag="h", hs=1, torrc="hs.tmpl")
  18. OldHS = Node(tag="h", hs=1, torrc="hs.tmpl", tor=OLD_TOR)
  19. # Choose old or new Relay, Client, and HS at random
  20. OldNewNonExitRelay = rng.choice([OldNonExitRelay, NonExitRelay])
  21. OldNewClient = rng.choice([OldClient, Client])
  22. OldNewHS = rng.choice([OldHS, HS])
  23. def version(node):
  24. if node._env["tor"] == Authority._env["tor"]:
  25. return "new"
  26. elif node._env["tor"] == OldAuthority._env["tor"]:
  27. return "old"
  28. else:
  29. return "unk"
  30. # Every time chutney takes an action, it will pick versions at random
  31. # It will likely choose different versions for each action
  32. # This could be confusing, so log a message each time
  33. print(("Chose 1 %s authority, 1 %s authority, %d %s non-exit relay, " +
  34. "%d %s non-exit relay, 1 %s client and 1 %s hidden service")
  35. % (version(Authority),
  36. version(OldAuthority),
  37. 2 if OldNewNonExitRelay == NonExitRelay else 1,
  38. version(NonExitRelay),
  39. 2 if OldNewNonExitRelay == OldNonExitRelay else 1,
  40. version(OldNonExitRelay),
  41. version(OldNewClient),
  42. version(OldNewHS)))
  43. # A hidden service needs 5 authorities/relays to ensure it can build HS
  44. # connections:
  45. # a minimum path length of 3, plus the client-nominated rendezvous point,
  46. # plus a seperate introduction point
  47. NODES = Authority.getN(1) + OldAuthority.getN(1) + NonExitRelay.getN(1) + \
  48. OldNonExitRelay.getN(1) + OldNewNonExitRelay.getN(1) + \
  49. OldNewClient.getN(1) + OldNewHS.getN(1)
  50. ConfigureNodes(NODES)