From 45a9c52fde5c8f48f0e6d6b360bc2abcd4c84bd1 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Sun, 17 Apr 2022 16:48:44 -0500 Subject: [PATCH] Fix verify bugs --- disk_jumble/src/disk_jumble/verify.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/disk_jumble/src/disk_jumble/verify.py b/disk_jumble/src/disk_jumble/verify.py index 60a53e5..e9faef5 100644 --- a/disk_jumble/src/disk_jumble/verify.py +++ b/disk_jumble/src/disk_jumble/verify.py @@ -89,7 +89,10 @@ def _get_v1_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li """, (disk_id, block_ranges) ) - infos = [_TorrentInfo.build(id_, info) for (id_, info) in cursor] + infos = [ + _TorrentInfo.build(bytes(id_), bencode.decode(bytes(info))) + for (id_, info) in cursor + ] for i in infos: assert i.piece_length % BLOCK_SIZE == 0, f"entity {i.id.hex()} has invalid piece length" @@ -153,13 +156,14 @@ def _get_v1_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li if any(crypt_key is not None for (*_, crypt_key) in rows): raise NotImplementedError("verify of encrypted data") - for (piece_num, ranges) in itertools.groupby(rows, lambda t: t[0]): + for (piece_num, piece_rows) in itertools.groupby(rows, lambda t: t[0]): + block_ranges = [range(r.lower, r.upper) for (r, _) in piece_rows] run = _V1Run( entity_id = info.id, entity_length = info.length, piece_length = info.piece_length, piece_num = piece_num, - block_ranges = [range(r.lower, r.upper) for r in ranges], + block_ranges = block_ranges, hash = info.hashes[piece_num], ) @@ -237,13 +241,13 @@ def _get_v2_worklist(conn, disk_id: int, block_ranges: List[NumericRange]) -> Li return [ _V2Run( - entity_id = entity_id, + entity_id = bytes(entity_id), entity_length = entity_length, piece_num = piece_num, block_ranges = [range(block, block + 1)], - hash = hash_, + hash = bytes(hash_), ) - for (entity_id, entity_length, piece_num, block, entity_length, hash_, crypt_key) in rows + for (entity_id, entity_length, piece_num, block, entity_length, hash_, _) in rows ] -- 2.30.2