basic-min-mixed 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # This network generates a random mix of tor versions each time it is run
  2. # You'll need at least 4 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. ExitRelay = Node(tag="r", relay=1, exit=1, torrc="relay.tmpl")
  13. OldExitRelay = Node(tag="r", relay=1, exit=1, torrc="relay.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. # Choose old or new Exit and Client at random
  18. OldNewExitRelay = rng.choice([OldExitRelay, ExitRelay])
  19. OldNewClient = rng.choice([OldClient, Client])
  20. def version(node):
  21. if node._env["tor"] == Authority._env["tor"]:
  22. return "new"
  23. elif node._env["tor"] == OldAuthority._env["tor"]:
  24. return "old"
  25. else:
  26. return "unk"
  27. # Every time chutney takes an action, it will pick versions at random
  28. # It will likely choose different versions for each action
  29. # This could be confusing, so log a message each time
  30. print("Chose 1 %s authority, 1 %s authority, 1 %s exit and 1 %s client"
  31. % (version(Authority),
  32. version(OldAuthority),
  33. version(OldNewExitRelay),
  34. version(OldNewClient)))
  35. # The minimum number of authorities/relays/exits is 3, the minimum path length
  36. NODES = Authority.getN(1) + OldAuthority.getN(1) + OldExitRelay.getN(1) + OldClient.getN(1)
  37. ConfigureNodes(NODES)