def test(self, hash_func_for_type): # Setup siblings = [] siblings.append(create_mock_full({"isLeft": True, "hash": "10s10"})) siblings.append(create_mock_full({"isLeft": False, "hash": "30s300"})) p = create_mock_full({ "ifID": 2, "epoch": 0, "nonce": b"s20", "siblings": siblings, "prevRoot": "p", "nextRoot": "n", "hashType": 0 }) rev_info = create_mock_full({"p": p}) hashes = [ "20s20", "10s1020s20", "10s1020s2030s300", "p10s1020s2030s300", "10s1020s2030s300n" ] hash_func = create_mock_full(side_effect=hashes) hash_func_for_type.return_value = hash_func # Call hash01, hash12 = ConnectedHashTree.get_possible_hashes(rev_info) # Tests ntools.eq_(hash01, "p10s1020s2030s300") ntools.eq_(hash12, "10s1020s2030s300n")
def _remove_revoked_segments(self, rev_info): """ Try the previous and next hashes as possible astokens, and delete any segment that matches :param rev_info: The revocation info :type rev_info: RevocationInfo """ if ConnectedHashTree.verify_epoch( rev_info.p.epoch) != ConnectedHashTree.EPOCH_OK: return (hash01, hash12) = ConnectedHashTree.get_possible_hashes(rev_info) if_id = rev_info.p.ifID with self.htroot_if2seglock: down_segs_removed = 0 core_segs_removed = 0 up_segs_removed = 0 for h in (hash01, hash12): for sid in self.htroot_if2seg.pop((h, if_id), []): if self.down_segments.delete( sid) == DBResult.ENTRY_DELETED: down_segs_removed += 1 if self.core_segments.delete( sid) == DBResult.ENTRY_DELETED: core_segs_removed += 1 if not self.topology.is_core_as: if (self.up_segments.delete(sid) == DBResult.ENTRY_DELETED): up_segs_removed += 1 logging.debug( "Removed segments revoked by [%s]: UP: %d DOWN: %d CORE: %d" % (rev_info.short_desc(), up_segs_removed, down_segs_removed, core_segs_removed))
def test(self): # Setup siblings = [] siblings.append(create_mock_full({"isLeft": True, "hash": "10s10"})) siblings.append(create_mock_full({"isLeft": False, "hash": "30s300"})) p = create_mock_full({ "ifID": 2, "epoch": 0, "nonce": b"s20", "siblings": siblings, "prevRoot": "p", "nextRoot": "n" }) revProof = create_mock_full({"p": p}) hashes = [ "20s20", "10s1020s20", "10s1020s2030s300", "p10s1020s2030s300", "10s1020s2030s300n" ] hash_new = create_mock_full({"digest()...": hashes}) hash_func = create_mock_full({"new()": hash_new}) # Call hash01, hash12 = ConnectedHashTree.get_possible_hashes( revProof, hash_func) # Tests ntools.eq_(hash01, "p10s1020s2030s300") ntools.eq_(hash12, "10s1020s2030s300n")