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