]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/mutable/layout.py
layout.py: fix MDMF share layout documentation
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / mutable / layout.py
index 02069edd1780a5a6908aaf025838e27932b7d824..e2fa6d68d585c9e50980a58c2b989c6954a03d65 100644 (file)
@@ -1,5 +1,5 @@
 
-import struct, math
+import struct
 from allmydata.mutable.common import NeedMoreDataError, UnknownVersionError
 from allmydata.interfaces import HASH_SIZE, SALT_SIZE, SDMF_VERSION, \
                                  MDMF_VERSION, IMutableSlotWriter
@@ -499,7 +499,7 @@ class SDMFSlotWriteProxy:
         """
         for k in ["sharedata", "encprivkey", "signature", "verification_key",
                   "share_hash_chain", "block_hash_tree"]:
-            assert k in self._share_pieces
+            assert k in self._share_pieces, (self.shnum, k, self._share_pieces.keys())
         # This is the only method that actually writes something to the
         # remote server.
         # First, we need to pack the share into data that we can write
@@ -548,10 +548,10 @@ MDMFOFFSETS_LENGTH = struct.calcsize(MDMFOFFSETS)
 PRIVATE_KEY_SIZE = 1220
 SIGNATURE_SIZE = 260
 VERIFICATION_KEY_SIZE = 292
-# We know we won't have more than 256 shares, and we know that we won't
-# need to store more than lg 256 of them to validate, so that's our
-# bound. We add 1 to the int cast to round to the next integer.
-SHARE_HASH_CHAIN_SIZE = int(math.log(HASH_SIZE * 256)) + 1
+# We know we won't have more than 256 shares, and we know that we won't need
+# to store more than ln2(256) hash-chain nodes to validate, so that's our
+# bound. Each node requires 2 bytes of node-number plus 32 bytes of hash.
+SHARE_HASH_CHAIN_SIZE = (2+HASH_SIZE)*mathutil.log_ceil(256, 2)
 
 class MDMFSlotWriteProxy:
     implements(IMutableSlotWriter)
@@ -567,7 +567,7 @@ class MDMFSlotWriteProxy:
     # offset:     size:       name:
     #-- signed part --
     # 0           1           version number (01)
-    # 1           8           sequence number 
+    # 1           8           sequence number
     # 9           32          share tree root hash
     # 41          1           The "k" encoding parameter
     # 42          1           The "N" encoding parameter
@@ -575,18 +575,22 @@ class MDMFSlotWriteProxy:
     # 51          8           The data length of the original plaintext
     #-- end signed part --
     # 59          8           The offset of the encrypted private key
-    # 67          8           The offset of the signature
-    # 75          8           The offset of the verification key
-    # 83          8           The offset of the end of the v. key.
-    # 92          8           The offset of the share data 
-    # 100         8           The offset of the block hash tree
-    # 108         8           The offset of the share hash chain
-    # 116         8           The offset of EOF
-    # 
-    # followed by the encrypted private key, signature, verification
-    # key, share hash chain, data, and block hash tree. We order the
-    # fields that way to make smart downloaders -- downloaders which
-    # prempetively read a big part of the share -- possible.
+    # 67          8           The offset of the share hash chain
+    # 75          8           The offset of the signature
+    # 83          8           The offset of the verification key
+    # 91          8           The offset of the end of the v. key.
+    # 99          8           The offset of the share data
+    # 107         8           The offset of the block hash tree
+    # 115         8           The offset of EOF
+    # 123         var         encrypted private key
+    # var         var         share hash chain
+    # var         var         signature
+    # var         var         verification key
+    # var         large       share data
+    # var         var         block hash tree
+    #
+    # We order the fields that way to make smart downloaders -- downloaders
+    # which prempetively read a big part of the share -- possible.
     #
     # The checkstring is the first three fields -- the version number,
     # sequence number, root hash and root salt hash. This is consistent