mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-01 10:46:42 +00:00
mdmf: clean up boolean expressions, correct typos, remove self._paused, and don't unconditionally initialize block hash trees, asll as suggested by davidsarahs' review comments
This commit is contained in:
parent
fa6a768bc1
commit
a1a334e1a0
@ -105,9 +105,8 @@ class Retrieve:
|
|||||||
# during repair, we may be called upon to grab the private key, since
|
# during repair, we may be called upon to grab the private key, since
|
||||||
# it wasn't picked up during a verify=False checker run, and we'll
|
# it wasn't picked up during a verify=False checker run, and we'll
|
||||||
# need it for repair to generate a new version.
|
# need it for repair to generate a new version.
|
||||||
self._need_privkey = fetch_privkey or verify
|
self._need_privkey = verify or (fetch_privkey
|
||||||
if self._node.get_privkey() and not verify:
|
and not self._node.get_privkey())
|
||||||
self._need_privkey = False
|
|
||||||
|
|
||||||
if self._need_privkey:
|
if self._need_privkey:
|
||||||
# TODO: Evaluate the need for this. We'll use it if we want
|
# TODO: Evaluate the need for this. We'll use it if we want
|
||||||
@ -126,9 +125,7 @@ class Retrieve:
|
|||||||
# 3. When we are validating readers, we need to validate the
|
# 3. When we are validating readers, we need to validate the
|
||||||
# signature on the prefix. Do we? We already do this in the
|
# signature on the prefix. Do we? We already do this in the
|
||||||
# servermap update?
|
# servermap update?
|
||||||
self._verify = False
|
self._verify = verify
|
||||||
if verify:
|
|
||||||
self._verify = True
|
|
||||||
|
|
||||||
self._status = RetrieveStatus()
|
self._status = RetrieveStatus()
|
||||||
self._status.set_storage_index(self._storage_index)
|
self._status.set_storage_index(self._storage_index)
|
||||||
@ -140,8 +137,7 @@ class Retrieve:
|
|||||||
self._status.set_size(datalength)
|
self._status.set_size(datalength)
|
||||||
self._status.set_encoding(k, N)
|
self._status.set_encoding(k, N)
|
||||||
self.readers = {}
|
self.readers = {}
|
||||||
self._paused = False
|
self._pause_deferred = None
|
||||||
self._paused_deferred = None
|
|
||||||
self._offset = None
|
self._offset = None
|
||||||
self._read_length = None
|
self._read_length = None
|
||||||
self.log("got seqnum %d" % self.verinfo[0])
|
self.log("got seqnum %d" % self.verinfo[0])
|
||||||
@ -167,7 +163,7 @@ class Retrieve:
|
|||||||
data for it to handle. I make the downloader stop producing new
|
data for it to handle. I make the downloader stop producing new
|
||||||
data until my resumeProducing method is called.
|
data until my resumeProducing method is called.
|
||||||
"""
|
"""
|
||||||
if self._paused:
|
if self._pause_deferred is not None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# fired when the download is unpaused.
|
# fired when the download is unpaused.
|
||||||
@ -175,7 +171,6 @@ class Retrieve:
|
|||||||
self._status.set_status("Paused")
|
self._status.set_status("Paused")
|
||||||
|
|
||||||
self._pause_deferred = defer.Deferred()
|
self._pause_deferred = defer.Deferred()
|
||||||
self._paused = True
|
|
||||||
|
|
||||||
|
|
||||||
def resumeProducing(self):
|
def resumeProducing(self):
|
||||||
@ -183,10 +178,9 @@ class Retrieve:
|
|||||||
I am called by my download target once it is ready to begin
|
I am called by my download target once it is ready to begin
|
||||||
receiving data again.
|
receiving data again.
|
||||||
"""
|
"""
|
||||||
if not self._paused:
|
if self._pause_deferred is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._paused = False
|
|
||||||
p = self._pause_deferred
|
p = self._pause_deferred
|
||||||
self._pause_deferred = None
|
self._pause_deferred = None
|
||||||
self._status.set_status(self._old_status)
|
self._status.set_status(self._old_status)
|
||||||
@ -202,7 +196,7 @@ class Retrieve:
|
|||||||
the Deferred fires immediately. Otherwise, the Deferred fires
|
the Deferred fires immediately. Otherwise, the Deferred fires
|
||||||
when the downloader is unpaused.
|
when the downloader is unpaused.
|
||||||
"""
|
"""
|
||||||
if self._paused:
|
if self._pause_deferred is not None:
|
||||||
d = defer.Deferred()
|
d = defer.Deferred()
|
||||||
self._pause_deferred.addCallback(lambda ignored: d.callback(res))
|
self._pause_deferred.addCallback(lambda ignored: d.callback(res))
|
||||||
return d
|
return d
|
||||||
@ -278,7 +272,6 @@ class Retrieve:
|
|||||||
assert len(self.remaining_sharemap) >= k
|
assert len(self.remaining_sharemap) >= k
|
||||||
|
|
||||||
self.log("starting download")
|
self.log("starting download")
|
||||||
self._paused = False
|
|
||||||
self._started_fetching = time.time()
|
self._started_fetching = time.time()
|
||||||
|
|
||||||
self._add_active_peers()
|
self._add_active_peers()
|
||||||
@ -302,10 +295,10 @@ class Retrieve:
|
|||||||
segment with. I return the plaintext associated with that
|
segment with. I return the plaintext associated with that
|
||||||
segment.
|
segment.
|
||||||
"""
|
"""
|
||||||
# shnum => block hash tree. Unusued, but setup_encoding_parameters will
|
# shnum => block hash tree. Unused, but setup_encoding_parameters will
|
||||||
# want to set this.
|
# want to set this.
|
||||||
# XXX: Make it so that it won't set this if we're just decoding.
|
# XXX: Make it so that it won't set this if we're just decoding.
|
||||||
self._block_hash_trees = {}
|
self._block_hash_trees = None
|
||||||
self._setup_encoding_parameters()
|
self._setup_encoding_parameters()
|
||||||
# This is the form expected by decode.
|
# This is the form expected by decode.
|
||||||
blocks_and_salts = blocks_and_salts.items()
|
blocks_and_salts = blocks_and_salts.items()
|
||||||
@ -370,6 +363,7 @@ class Retrieve:
|
|||||||
(k, n, self._num_segments, self._segment_size,
|
(k, n, self._num_segments, self._segment_size,
|
||||||
self._tail_segment_size))
|
self._tail_segment_size))
|
||||||
|
|
||||||
|
if self._block_hash_trees is not None:
|
||||||
for i in xrange(self._total_shares):
|
for i in xrange(self._total_shares):
|
||||||
# So we don't have to do this later.
|
# So we don't have to do this later.
|
||||||
self._block_hash_trees[i] = hashtree.IncompleteHashTree(self._num_segments)
|
self._block_hash_trees[i] = hashtree.IncompleteHashTree(self._num_segments)
|
||||||
|
Loading…
Reference in New Issue
Block a user