]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
mutable: cheap padding hack to make zfec tolerate short files
authorBrian Warner <warner@lothar.com>
Thu, 8 Nov 2007 11:30:37 +0000 (04:30 -0700)
committerBrian Warner <warner@lothar.com>
Thu, 8 Nov 2007 11:30:37 +0000 (04:30 -0700)
src/allmydata/mutable.py

index d7a0d669cf1e1b33f94b842cc812dd87b4a5eb0a..d73e6c1297c63bead56e9b00b13a210ec0ea91ef 100644 (file)
@@ -891,10 +891,16 @@ class Publish:
 
         # now apply FEC
         self.MAX_SEGMENT_SIZE = 1024*1024
+        data_length = len(crypttext)
+        if len(crypttext) < 10:
+            # TODO: FEC doesn't handle short (or empty) strings very well, so
+            # give it something longer and we'll trim the results later. For
+            # some reason I suspect the lower limit is k**2
+            crypttext = crypttext + "\x00"*(10-len(crypttext))
+
         segment_size = min(self.MAX_SEGMENT_SIZE, len(crypttext))
         # this must be a multiple of self.required_shares
-        segment_size = mathutil.next_multiple(segment_size,
-                                                   required_shares)
+        segment_size = mathutil.next_multiple(segment_size, required_shares)
         self.num_segments = mathutil.div_ceil(len(crypttext), segment_size)
         assert self.num_segments == 1 # SDMF restrictions
         fec = codec.CRSEncoder()
@@ -913,7 +919,7 @@ class Publish:
         d.addCallback(lambda shares_and_shareids:
                       (shares_and_shareids,
                        required_shares, total_shares,
-                       segment_size, len(crypttext),
+                       segment_size, data_length,
                        target_info) )
         return d