]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
encode: start to fix a few problems, still a lot of work left to go
authorBrian Warner <warner@lothar.com>
Thu, 14 Dec 2006 11:31:17 +0000 (04:31 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 14 Dec 2006 11:31:17 +0000 (04:31 -0700)
src/allmydata/chunk.py
src/allmydata/encode_new.py
src/allmydata/test/test_encode.py

index 59495b43ec6c42caf17c7d5d3ab34a78106e3b55..3ee903e5048bf53f31cbed0b6af049331d07569e 100644 (file)
@@ -135,7 +135,7 @@ class CompleteBinaryTreeMixin:
 
   def needed_for(self, i):
     """
-    Return a list of nodes that are necessary for the hash chain.
+    Return a list of node indices that are necessary for the hash chain.
     """
     if i < 0 or i >= len(self):
       raise IndexError('index out of range: ' + repr(i))
index c7396c7e648657ccfd4f775d503f5ece0dff5129..4e13b21ce159ffffbfef7dd694fe487c8118e14a 100644 (file)
@@ -2,7 +2,7 @@
 
 import math
 from twisted.internet import defer
-from allmydata.chunk import HashTree
+from allmydata.chunk import HashTree, roundup_pow2
 from Crypto.Cipher import AES
 import sha
 
@@ -160,8 +160,13 @@ class Encoder(object):
         self.root_hash = t[0]
         # now send just the necessary pieces out to each shareholder
         for i in range(self.num_shares):
-            needed_hash_indices = t.needed_for(i)
-            dl.append(self.send_one_share_hash_tree(i, needed_hash_indices))
+            # the HashTree is given a list of leaves: 0,1,2,3..n .
+            # These become nodes A+0,A+1,A+2.. of the tree, where A=n-1
+            tree_width = roundup_pow2(self.num_shares)
+            base_index = i + tree_width - 1
+            needed_hash_indices = t.needed_for(base_index)
+            hashes = [(hi, t[hi]) for hi in needed_hash_indices]
+            dl.append(self.send_one_share_hash_tree(i, hashes))
         return defer.DeferredList(dl)
 
     def send_one_share_hash_tree(self, share_num, needed_hashes):
index f37cc68bf97f5a279cc98126455514af8d452b13..5af27b7f45a04ea4607074cff517597f1f38f6f7 100644 (file)
@@ -7,6 +7,10 @@ from cStringIO import StringIO
 
 class MyEncoder(encode_new.Encoder):
     def send(self, share_num, methname, *args, **kwargs):
+        if False and share_num < 10:
+            print "send[%d].%s()" % (share_num, methname)
+            if methname == "put_share_hashes":
+                print " ", [i for i,h in args[0]]
         return defer.succeed(None)
 
 class Encode(unittest.TestCase):