コード例 #1
0
def test_excludenodes():
    controller = MockController()
    state = VanguardState("tests/state.mock2")

    # - Load a routerlist using stem
    routers = list(
        stem.descriptor.parse_file(
            "tests/cached-microdesc-consensus",
            document_handler=stem.descriptor.DocumentHandler.ENTRIES))
    weights = get_consensus_weights("tests/cached-microdesc-consensus")
    (sorted_r, dict_r) = state.sort_and_index_routers(routers)

    state.consensus_update(routers, weights, ExcludeNodes(controller))
    sanity_check(state)

    #   * IP, CIDR, quad-mask
    controller.exclude_nodes = \
         str(dict_r[state.layer2[0].idhex].address)+","+\
         str(dict_r[state.layer2[1].idhex].address)+"/24,"+\
         str(dict_r[state.layer2[2].idhex].address)+"/255.255.255.0"
    removed2 = [
        state.layer2[0].idhex, state.layer2[1].idhex, state.layer2[2].idhex
    ]

    for r in removed2:
        assert r in map(lambda x: x.idhex, state.layer2)
    state.consensus_update(routers, weights, ExcludeNodes(controller))
    sanity_check(state)
    for r in removed2:
        assert not r in map(lambda x: x.idhex, state.layer2)

    #   * GeoIP case mismatch
    controller.exclude_nodes = "{Us}"
    controller.exclude_unknown = "auto"
    controller.get_info_vals["ip-to-country/" +
                             dict_r[state.layer2[1].idhex].address] = "us"
    controller.get_info_vals["ip-to-country/ipv4-available"] = "1"
    removed2 = state.layer2[1].idhex
    keep2 = state.layer2[0].idhex
    state.consensus_update(routers, weights, ExcludeNodes(controller))

    sanity_check(state)
    assert keep2 in map(lambda x: x.idhex, state.layer2)
    assert not removed2 in map(lambda x: x.idhex, state.layer2)

    #   * Nicks
    controller.exclude_nodes = \
         str(dict_r[state.layer2[0].idhex].nickname)

    removed2 = state.layer2[0].idhex
    keep2 = state.layer2[1].idhex
    state.consensus_update(routers, weights, ExcludeNodes(controller))
    sanity_check(state)
    assert not removed2 in map(lambda x: x.idhex, state.layer2)
    assert keep2 in map(lambda x: x.idhex, state.layer2)
コード例 #2
0
def test_new_vanguards():
  state = VanguardState("tests/state.mock2")

  # - Load a routerlist using stem
  routers = list(stem.descriptor.parse_file("tests/cached-microdesc-consensus",
                 document_handler =
                    stem.descriptor.DocumentHandler.ENTRIES))
  weights = get_consensus_weights("tests/cached-microdesc-consensus")

  # - Perform basic rank checks from sort_and_index
  (sorted_r, dict_r) = state.sort_and_index_routers(routers)
  for i in xrange(len(sorted_r)-1):
    assert sorted_r[i].measured >= sorted_r[i+1].measured

  state.consensus_update(routers, weights, ExcludeNodes(MockController()))
  sanity_check(state)

  replacement_checks(state, routers, weights)