]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Raise NotEnoughSharesError if there are initially not enough shares for a mutable...
authorDaira Hopwood <david-sarah@jacaranda.org>
Fri, 10 May 2013 21:40:00 +0000 (22:40 +0100)
committerDaira Hopwood <david-sarah@jacaranda.org>
Tue, 14 May 2013 22:20:46 +0000 (23:20 +0100)
We also change the order of setting up attributes in Retrieve so that _raise_notenoughshareserror() can be called from _setup_download.

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
src/allmydata/mutable/retrieve.py

index 26d1747becc807de7b187c891bd069e793a9bbbd..108560ee621ee1fcb43932449650e565cbcc63e9 100644 (file)
@@ -241,8 +241,8 @@ class Retrieve:
         self._done_deferred = defer.Deferred()
         self._offset = offset
         self._read_length = size
-        self._setup_download()
         self._setup_encoding_parameters()
+        self._setup_download()
         self.log("starting download")
         self._started_fetching = time.time()
         # The download process beyond this is a state machine.
@@ -296,12 +296,18 @@ class Retrieve:
                                            self._storage_index, shnum, None)
             reader.server = server
             self.readers[shnum] = reader
-        assert len(self.remaining_sharemap) >= k
+
+        if len(self.remaining_sharemap) < k:
+            self._raise_notenoughshareserror()
 
         self.shares = {} # maps shnum to validated blocks
         self._active_readers = [] # list of active readers for this dl.
         self._block_hash_trees = {} # shnum => hashtree
 
+        for i in xrange(self._total_shares):
+            # So we don't have to do this later.
+            self._block_hash_trees[i] = hashtree.IncompleteHashTree(self._num_segments)
+
         # We need one share hash tree for the entire file; its leaves
         # are the roots of the block hash trees for the shares that
         # comprise it, and its root is in the verinfo.
@@ -317,8 +323,6 @@ class Retrieve:
         segment with. I return the plaintext associated with that
         segment.
         """
-        # shnum => block hash tree. Unused, but setup_encoding_parameters will
-        # want to set this.
         self._block_hash_trees = None
         self._setup_encoding_parameters()
 
@@ -384,11 +388,6 @@ class Retrieve:
                  (k, n, self._num_segments, self._segment_size,
                   self._tail_segment_size))
 
-        if self._block_hash_trees is not None:
-            for i in xrange(self._total_shares):
-                # So we don't have to do this later.
-                self._block_hash_trees[i] = hashtree.IncompleteHashTree(self._num_segments)
-
         # Our last task is to tell the downloader where to start and
         # where to stop. We use three parameters for that:
         #   - self._start_segment: the segment that we need to start