예제 #1
0
    def _verify_all_shares(self, servermap):
        # read every byte of each share
        #
        # This logic is going to be very nearly the same as the
        # downloader. I bet we could pass the downloader a flag that
        # makes it do this, and piggyback onto that instead of
        # duplicating a bunch of code.
        #
        # Like:
        #  r = Retrieve(blah, blah, blah, verify=True)
        #  d = r.download()
        #  (wait, wait, wait, d.callback)
        #
        #  Then, when it has finished, we can check the servermap (which
        #  we provided to Retrieve) to figure out which shares are bad,
        #  since the Retrieve process will have updated the servermap as
        #  it went along.
        #
        #  By passing the verify=True flag to the constructor, we are
        #  telling the downloader a few things.
        #
        #  1. It needs to download all N shares, not just K shares.
        #  2. It doesn't need to decrypt or decode the shares, only
        #     verify them.
        if not self.best_version:
            return

        r = Retrieve(self._node, self._storage_broker, servermap,
                     self.best_version, verify=True)
        d = r.download()
        d.addCallback(self._process_bad_shares)
        return d
예제 #2
0
 def do_download(self, servermap, version=None):
     if version is None:
         version = servermap.best_recoverable_version()
     r = Retrieve(self._fn, self._storage_broker, servermap, version)
     c = consumer.MemoryConsumer()
     d = r.download(consumer=c)
     d.addCallback(lambda mc: "".join(mc.chunks))
     return d
예제 #3
0
 def _do_retrieve(servermap):
     self.failUnless(servermap.get_problems())
     self.failUnless("pubkey doesn't match fingerprint" in str(
         servermap.get_problems()[0]))
     ver = servermap.best_recoverable_version()
     r = Retrieve(self._fn, self._storage_broker, servermap, ver)
     c = consumer.MemoryConsumer()
     return r.download(c)
예제 #4
0
 def _try_once_to_download_version(self, servermap, version,
                                   fetch_privkey=False):
     r = Retrieve(self, servermap, version, fetch_privkey)
     if self._history:
         self._history.notify_retrieve(r.get_status())
     d = r.download()
     d.addCallback(self._downloaded_version)
     return d
예제 #5
0
 def do_download(self, servermap, version=None):
     if version is None:
         version = servermap.best_recoverable_version()
     r = Retrieve(self._fn, self._storage_broker, servermap, version)
     c = consumer.MemoryConsumer()
     d = r.download(consumer=c)
     d.addCallback(lambda mc: "".join(mc.chunks))
     return d
예제 #6
0
 def _do_retrieve(servermap):
     self.failUnless(servermap.get_problems())
     self.failUnless("pubkey doesn't match fingerprint"
                     in str(servermap.get_problems()[0]))
     ver = servermap.best_recoverable_version()
     r = Retrieve(self._fn, self._storage_broker, servermap, ver)
     c = consumer.MemoryConsumer()
     return r.download(c)
예제 #7
0
 def _read(self, consumer, offset=0, size=None, fetch_privkey=False):
     """
     I am the serialized companion of read.
     """
     r = Retrieve(self._node, self._storage_broker, self._servermap,
                  self._version, fetch_privkey)
     if self._history:
         self._history.notify_retrieve(r.get_status())
     d = r.download(consumer, offset, size)
     return d
예제 #8
0
 def _try_once_to_download_version(self,
                                   servermap,
                                   version,
                                   fetch_privkey=False):
     r = Retrieve(self, servermap, version, fetch_privkey)
     if self._history:
         self._history.notify_retrieve(r.get_status())
     d = r.download()
     d.addCallback(self._downloaded_version)
     return d
예제 #9
0
 def _read(self, consumer, offset=0, size=None, fetch_privkey=False):
     """
     I am the serialized companion of read.
     """
     r = Retrieve(self._node, self._storage_broker, self._servermap,
                  self._version, fetch_privkey)
     if self._history:
         self._history.notify_retrieve(r.get_status())
     d = r.download(consumer, offset, size)
     return d
예제 #10
0
    def _decode_and_decrypt_segments(self, ignored, data, offset):
        """
        After the servermap update, I take the encrypted and encoded
        data that the servermap fetched while doing its update and
        transform it into decoded-and-decrypted plaintext that can be
        used by the new uploadable. I return a Deferred that fires with
        the segments.
        """
        r = Retrieve(self._node, self._storage_broker, self._servermap,
                     self._version)
        # decode: takes in our blocks and salts from the servermap,
        # returns a Deferred that fires with the corresponding plaintext
        # segments. Does not download -- simply takes advantage of
        # existing infrastructure within the Retrieve class to avoid
        # duplicating code.
        sm = self._servermap
        # XXX: If the methods in the servermap don't work as
        # abstractions, you should rewrite them instead of going around
        # them.
        update_data = sm.update_data
        start_segments = {} # shnum -> start segment
        end_segments = {} # shnum -> end segment
        blockhashes = {} # shnum -> blockhash tree
        for (shnum, original_data) in update_data.iteritems():
            data = [d[1] for d in original_data if d[0] == self._version]
            # data is [(blockhashes,start,end)..]

            # Every data entry in our list should now be share shnum for
            # a particular version of the mutable file, so all of the
            # entries should be identical.
            datum = data[0]
            assert [x for x in data if x != datum] == []

            # datum is (blockhashes,start,end)
            blockhashes[shnum] = datum[0]
            start_segments[shnum] = datum[1] # (block,salt) bytestrings
            end_segments[shnum] = datum[2]

        d1 = r.decode(start_segments, self._start_segment)
        d2 = r.decode(end_segments, self._end_segment)
        d3 = defer.succeed(blockhashes)
        return deferredutil.gatherResults([d1, d2, d3])
예제 #11
0
    def _decode_and_decrypt_segments(self, ignored, data, offset):
        """
        After the servermap update, I take the encrypted and encoded
        data that the servermap fetched while doing its update and
        transform it into decoded-and-decrypted plaintext that can be
        used by the new uploadable. I return a Deferred that fires with
        the segments.
        """
        r = Retrieve(self._node, self._storage_broker, self._servermap,
                     self._version)
        # decode: takes in our blocks and salts from the servermap,
        # returns a Deferred that fires with the corresponding plaintext
        # segments. Does not download -- simply takes advantage of
        # existing infrastructure within the Retrieve class to avoid
        # duplicating code.
        sm = self._servermap
        # XXX: If the methods in the servermap don't work as
        # abstractions, you should rewrite them instead of going around
        # them.
        update_data = sm.update_data
        start_segments = {} # shnum -> start segment
        end_segments = {} # shnum -> end segment
        blockhashes = {} # shnum -> blockhash tree
        for (shnum, original_data) in update_data.iteritems():
            data = [d[1] for d in original_data if d[0] == self._version]
            # data is [(blockhashes,start,end)..]

            # Every data entry in our list should now be share shnum for
            # a particular version of the mutable file, so all of the
            # entries should be identical.
            datum = data[0]
            assert [x for x in data if x != datum] == []

            # datum is (blockhashes,start,end)
            blockhashes[shnum] = datum[0]
            start_segments[shnum] = datum[1] # (block,salt) bytestrings
            end_segments[shnum] = datum[2]

        d1 = r.decode(start_segments, self._start_segment)
        d2 = r.decode(end_segments, self._end_segment)
        d3 = defer.succeed(blockhashes)
        return deferredutil.gatherResults([d1, d2, d3])