mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 15:16:41 +00:00
rename chunk.py to hashtree.py
This commit is contained in:
parent
8f58b30db9
commit
d8215e0c6f
@ -7,7 +7,7 @@ from twisted.application import service
|
||||
|
||||
from allmydata.util import idlib, mathutil, hashutil
|
||||
from allmydata.util.assertutil import _assert
|
||||
from allmydata import codec, chunk
|
||||
from allmydata import codec, hashtree
|
||||
from allmydata.Crypto.Cipher import AES
|
||||
from allmydata.uri import unpack_uri
|
||||
from allmydata.interfaces import IDownloadTarget, IDownloader
|
||||
@ -52,7 +52,7 @@ class ValidatedBucket:
|
||||
self.sharenum = sharenum
|
||||
self.bucket = bucket
|
||||
self.share_hash_tree = share_hash_tree
|
||||
self.block_hash_tree = chunk.IncompleteHashTree(num_blocks)
|
||||
self.block_hash_tree = hashtree.IncompleteHashTree(num_blocks)
|
||||
|
||||
def get_block(self, blocknum):
|
||||
d1 = self.bucket.callRemote('get_block', blocknum)
|
||||
@ -193,7 +193,7 @@ class FileDownloader:
|
||||
key = "\x00" * 16
|
||||
self._output = Output(downloadable, key)
|
||||
|
||||
self._share_hashtree = chunk.IncompleteHashTree(total_shares)
|
||||
self._share_hashtree = hashtree.IncompleteHashTree(total_shares)
|
||||
self._share_hashtree.set_hashes({0: roothash})
|
||||
|
||||
self.active_buckets = {} # k: shnum, v: bucket
|
||||
|
@ -3,7 +3,7 @@
|
||||
from zope.interface import implements
|
||||
from twisted.internet import defer
|
||||
from twisted.python import log
|
||||
from allmydata.chunk import HashTree, roundup_pow2
|
||||
from allmydata.hashtree import HashTree, roundup_pow2
|
||||
from allmydata.Crypto.Cipher import AES
|
||||
from allmydata.util import mathutil, hashutil
|
||||
from allmydata.util.assertutil import _assert
|
||||
|
@ -3,13 +3,13 @@
|
||||
from twisted.trial import unittest
|
||||
|
||||
from allmydata.util.hashutil import tagged_hash
|
||||
from allmydata import chunk
|
||||
from allmydata import hashtree
|
||||
|
||||
|
||||
def make_tree(numleaves):
|
||||
leaves = ["%d" % i for i in range(numleaves)]
|
||||
leaf_hashes = [tagged_hash("tag", leaf) for leaf in leaves]
|
||||
ht = chunk.HashTree(leaf_hashes)
|
||||
ht = hashtree.HashTree(leaf_hashes)
|
||||
return ht
|
||||
|
||||
class Complete(unittest.TestCase):
|
||||
@ -43,7 +43,7 @@ class Incomplete(unittest.TestCase):
|
||||
# first create a complete hash tree
|
||||
ht = make_tree(6)
|
||||
# then create a corresponding incomplete tree
|
||||
iht = chunk.IncompleteHashTree(6)
|
||||
iht = hashtree.IncompleteHashTree(6)
|
||||
|
||||
# suppose we wanted to validate leaf[0]
|
||||
# leaf[0] is the same as node[7]
|
||||
@ -61,7 +61,7 @@ class Incomplete(unittest.TestCase):
|
||||
# this should fail because there aren't enough hashes known
|
||||
iht.set_hashes(leaves={0: tagged_hash("tag", "0")},
|
||||
must_validate=True)
|
||||
except chunk.NotEnoughHashesError:
|
||||
except hashtree.NotEnoughHashesError:
|
||||
pass
|
||||
else:
|
||||
self.fail("didn't catch not enough hashes")
|
||||
@ -76,7 +76,7 @@ class Incomplete(unittest.TestCase):
|
||||
try:
|
||||
# this should fail because the hash is just plain wrong
|
||||
iht.set_hashes(leaves={0: tagged_hash("bad tag", "0")})
|
||||
except chunk.BadHashError:
|
||||
except hashtree.BadHashError:
|
||||
pass
|
||||
else:
|
||||
self.fail("didn't catch bad hash")
|
||||
@ -84,20 +84,20 @@ class Incomplete(unittest.TestCase):
|
||||
try:
|
||||
# this should succeed
|
||||
iht.set_hashes(leaves={0: tagged_hash("tag", "0")})
|
||||
except chunk.BadHashError, e:
|
||||
except hashtree.BadHashError, e:
|
||||
self.fail("bad hash: %s" % e)
|
||||
|
||||
try:
|
||||
# this should succeed too
|
||||
iht.set_hashes(leaves={1: tagged_hash("tag", "1")})
|
||||
except chunk.BadHashError:
|
||||
except hashtree.BadHashError:
|
||||
self.fail("bad hash")
|
||||
|
||||
# giving it a bad internal hash should also cause problems
|
||||
iht.set_hashes({13: tagged_hash("bad tag", "x")})
|
||||
try:
|
||||
iht.set_hashes({14: tagged_hash("tag", "14")})
|
||||
except chunk.BadHashError:
|
||||
except hashtree.BadHashError:
|
||||
pass
|
||||
else:
|
||||
self.fail("didn't catch bad hash")
|
||||
@ -110,6 +110,6 @@ class Incomplete(unittest.TestCase):
|
||||
try:
|
||||
# this should succeed
|
||||
iht.set_hashes(leaves={4: tagged_hash("tag", "4")})
|
||||
except chunk.BadHashError, e:
|
||||
except hashtree.BadHashError, e:
|
||||
self.fail("bad hash: %s" % e)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user