Ejemplo n.º 1
0
def test_compute_shared_prefix_bits():
    # When we have less than 2 nodes, the depth is k_id_size.
    nodes = [random_node()]
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size

    # Otherwise the depth is the number of leading bits (in the left-padded binary representation)
    # shared by all node IDs.
    nodes.append(random_node())
    nodes[0].id = int('0b1', 2)
    nodes[1].id = int('0b0', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size - 1

    nodes[0].id = int('0b010', 2)
    nodes[1].id = int('0b110', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size - 3
Ejemplo n.º 2
0
def test_compute_shared_prefix_bits():
    # When we have less than 2 nodes, the depth is k_id_size.
    nodes = [NodeFactory()]
    assert kademlia._compute_shared_prefix_bits(nodes) == KADEMLIA_ID_SIZE

    # Otherwise the depth is the number of leading bits (in the left-padded binary representation)
    # shared by all node IDs.
    nodes.append(NodeFactory())
    nodes[0]._id_int = int('0b1', 2)
    nodes[1]._id_int = int('0b0', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == KADEMLIA_ID_SIZE - 1

    nodes[0]._id_int = int('0b010', 2)
    nodes[1]._id_int = int('0b110', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == KADEMLIA_ID_SIZE - 3
Ejemplo n.º 3
0
def test_compute_shared_prefix_bits():
    # When we have less than 2 nodes, the depth is k_id_size.
    nodes = [random_node()]
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size

    # Otherwise the depth is the number of leading bits (in the left-padded binary representation)
    # shared by all node IDs.
    nodes.append(random_node())
    nodes[0].id = int('0b1', 2)
    nodes[1].id = int('0b0', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size - 1

    nodes[0].id = int('0b010', 2)
    nodes[1].id = int('0b110', 2)
    assert kademlia._compute_shared_prefix_bits(nodes) == kademlia.k_id_size - 3