From: Daira Hopwood Date: Fri, 10 May 2013 21:40:00 +0000 (+0100) Subject: Raise NotEnoughSharesError if there are initially not enough shares for a mutable... X-Git-Tag: allmydata-tahoe-1.10.1a1~245 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty//%22%3C?a=commitdiff_plain;h=cf52c512c53af02276c25f45d0f2dfe74125e10d;p=tahoe-lafs%2Ftahoe-lafs.git Raise NotEnoughSharesError if there are initially not enough shares for a mutable retrieve. refs #1742 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 --- diff --git a/src/allmydata/mutable/retrieve.py b/src/allmydata/mutable/retrieve.py index 26d1747b..108560ee 100644 --- a/src/allmydata/mutable/retrieve.py +++ b/src/allmydata/mutable/retrieve.py @@ -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