Esempio n. 1
0
def smoke_test_topkey():
    """ Smoke test top key functions. """
    # To binary rep...
    bytes0 = top_key_tuple_to_bytes(TOP)
    bytes1 = top_key_tuple_to_bytes(TOP, 0xcc)

    # Check salting.
    assert bytes0 != bytes1
    assert len(bytes0) == len(bytes1)

    # ... and back
    assert bytes_to_top_key_tuple(bytes0)[0] == TOP
    assert bytes_to_top_key_tuple(bytes1)[0] == TOP

    dump_top_key_tuple(TOP)
Esempio n. 2
0
def smoke_test_topkey():
    """ Smoke test top key functions. """
    # To binary rep...
    bytes0 = top_key_tuple_to_bytes(TOP)
    bytes1 = top_key_tuple_to_bytes(TOP, 0xCC)

    # Check salting.
    assert bytes0 != bytes1
    assert len(bytes0) == len(bytes1)

    # ... and back
    assert bytes_to_top_key_tuple(bytes0)[0] == TOP
    assert bytes_to_top_key_tuple(bytes1)[0] == TOP

    dump_top_key_tuple(TOP)
Esempio n. 3
0
    def get_top_key_tuple(self):
        """ Get the python rep of the data required to insert a new URI
            with the updated graph CHK(s). """
        graph = self.parent.ctx.graph
        assert not graph is None

        # REDFLAG: graph redundancy hard coded to 2.
        chks = (self.get_result(0)[1]['URI'], self.get_result(1)[1]['URI'])

        # Slow.
        updates = get_top_key_updates(graph, self.parent.ctx.repo)

        # Head revs are more important because they allow us to
        # check whether the local repo is up to date.

        # Walk from the oldest to the newest update discarding
        # base revs, then head revs until the binary rep will
        # fit in an ssk.
        index = len(updates) - 1
        zorch_base = True
        while (len(topkey.top_key_tuple_to_bytes(
            (chks, updates))) >= MAX_SSK_LEN and index >= 0):
            victim = list(updates[index])
            # djk20090628 -- There was a bad b_ug here until c47cb6a56d80 which
            #                caused revs not to be discarded. This resulted in
            #                topkey data which was larger than expected.
            #
            # Discard versions
            victim[1 + int(zorch_base)] = victim[1 + int(zorch_base)][:1]
            victim[4 + int(zorch_base)] = False
            updates[index] = tuple(victim)
            if not zorch_base:
                zorch_base = True
                index -= 1
                continue
            zorch_base = False

        assert len(topkey.top_key_tuple_to_bytes(
            (chks, updates))) < MAX_SSK_LEN

        return (chks, updates)
Esempio n. 4
0
    def get_top_key_tuple(self):
        """ Get the python rep of the data required to insert a new URI
            with the updated graph CHK(s). """
        graph = self.parent.ctx.graph
        assert not graph is None

        # REDFLAG: graph redundancy hard coded to 2.
        chks = (self.get_result(0)[1]['URI'], self.get_result(1)[1]['URI'])

        # Slow.
        updates = get_top_key_updates(graph, self.parent.ctx.repo)

        # Head revs are more important because they allow us to
        # check whether the local repo is up to date.

        # Walk from the oldest to the newest update discarding
        # base revs, then head revs until the binary rep will
        # fit in an ssk.
        index = len(updates) - 1
        zorch_base = True
        while (len(topkey.top_key_tuple_to_bytes((chks, updates))) >= MAX_SSK_LEN
               and index >= 0):
            victim = list(updates[index])
            # djk20090628 -- There was a bad b_ug here until c47cb6a56d80 which
            #                caused revs not to be discarded. This resulted in
            #                topkey data which was larger than expected.
            #
            # Discard versions
            victim[1 + int(zorch_base)] = victim[1 + int(zorch_base)][:1]
            victim[4 + int(zorch_base)] = False
            updates[index] = tuple(victim)
            if not zorch_base:
                zorch_base = True
                index -= 1
                continue
            zorch_base = False

        assert len(topkey.top_key_tuple_to_bytes((chks, updates))) < MAX_SSK_LEN

        return (chks, updates)