diff --git a/src/allmydata/immutable/checker.py b/src/allmydata/immutable/checker.py index c565bc3..77edff8 100644 --- a/src/allmydata/immutable/checker.py +++ b/src/allmydata/immutable/checker.py @@ -159,7 +159,7 @@ class Checker(log.PrefixingLogMixin): self._share_hash_tree = hashtree.IncompleteHashTree(self._verifycap.total_shares) self._share_hash_tree.set_hashes({0: vup.share_root_hash}) - vrbp = download.ValidatedReadBucketProxy(sharenum, b, self._share_hash_tree, vup.num_segments, vup.block_size, vup.share_size) + vrbp = download.ValidatedReadBucketProxy(sharenum, b, self._share_hash_tree, vup.num_segments, vup.block_size, vup.share_size, self._verifycap.storage_index) ds = [] for blocknum in range(vup.num_segments): diff --git a/src/allmydata/immutable/download.py b/src/allmydata/immutable/download.py index 9dfc0bb..efb5454 100644 --- a/src/allmydata/immutable/download.py +++ b/src/allmydata/immutable/download.py @@ -318,7 +318,8 @@ class ValidatedReadBucketProxy(log.PrefixingLogMixin): My get_block() method is used by BlockDownloaders. """ - def __init__(self, sharenum, bucket, share_hash_tree, num_blocks, block_size, share_size): + def __init__(self, sharenum, bucket, share_hash_tree, num_blocks, block_size, share_size, + storage_index): """ share_hash_tree is required to have already been initialized with the root hash (the number-0 hash), using the share_root_hash from the UEB """ precondition(share_hash_tree[0] is not None, share_hash_tree) @@ -331,6 +332,7 @@ class ValidatedReadBucketProxy(log.PrefixingLogMixin): self.block_size = block_size self.share_size = share_size self.block_hash_tree = hashtree.IncompleteHashTree(self.num_blocks) + self.storage_index = storage_index def get_block(self, blocknum): # the first time we use this bucket, we need to fetch enough elements @@ -408,6 +410,15 @@ class ValidatedReadBucketProxy(log.PrefixingLogMixin): # likely a programming error self.log("hash failure in block=%d, shnum=%d on %s" % (blocknum, self.sharenum, self.bucket)) + try: + fn = ("logs/badhash-from-%s-SI-%s-shnum-%d-blocknum-%d" % + (idlib.shortnodeid_b2a(self.bucket._peerid), + base32.b2a(self.storage_index), self.sharenum, blocknum)) + f = open(fn, "wb") + f.write(blockdata) + f.close() + except Exception, e: + self.log(" (unable to write blockdata: %s)" % (e,)) if self.block_hash_tree.needed_hashes(blocknum): self.log(""" failure occurred when checking the block_hash_tree. This suggests that either the block data was bad, or that the @@ -923,7 +934,10 @@ class CiphertextDownloader(log.PrefixingLogMixin): def _download_all_segments(self, res): for sharenum, bucket in self._share_buckets: - vbucket = ValidatedReadBucketProxy(sharenum, bucket, self._share_hash_tree, self._vup.num_segments, self._vup.block_size, self._vup.share_size) + vbucket = ValidatedReadBucketProxy(sharenum, bucket, self._share_hash_tree, + self._vup.num_segments, + self._vup.block_size, self._vup.share_size, + self._storage_index) self._share_vbuckets.setdefault(sharenum, set()).add(vbucket) # after the above code, self._share_vbuckets contains enough