예제 #1
0
파일: node.py 프로젝트: ducki2p/tahoe-lafs
    def _decode_blocks(self, segnum, blocks):
        tail = (segnum == self.num_segments-1)
        codec = self._codec
        block_size = self.block_size
        decoded_size = self.segment_size
        if tail:
            # account for the padding in the last segment
            codec = CRSDecoder()
            k, N = self._verifycap.needed_shares, self._verifycap.total_shares
            codec.set_params(self.tail_segment_padded, k, N)
            block_size = self.tail_block_size
            decoded_size = self.tail_segment_padded

        shares = []
        shareids = []
        for (shareid, share) in blocks.iteritems():
            assert len(share) == block_size
            shareids.append(shareid)
            shares.append(share)
        del blocks

        start = now()
        d = codec.decode(shares, shareids)   # segment
        del shares
        def _process(buffers):
            decodetime = now() - start
            segment = "".join(buffers)
            assert len(segment) == decoded_size
            del buffers
            if tail:
                segment = segment[:self.tail_segment_size]
            return (segment, decodetime)
        d.addCallback(_process)
        return d
예제 #2
0
    def _decode_blocks(self, segnum, blocks):
        start = now()
        tail = (segnum == self.num_segments-1)
        codec = self._codec
        block_size = self.block_size
        decoded_size = self.segment_size
        if tail:
            # account for the padding in the last segment
            codec = CRSDecoder()
            k, N = self._verifycap.needed_shares, self._verifycap.total_shares
            codec.set_params(self.tail_segment_padded, k, N)
            block_size = self.tail_block_size
            decoded_size = self.tail_segment_padded

        shares = []
        shareids = []
        for (shareid, share) in blocks.items():
            assert len(share) == block_size
            shareids.append(shareid)
            shares.append(share)
        del blocks

        d = codec.decode(shares, shareids)   # segment
        del shares
        def _process(buffers):
            decodetime = now() - start
            segment = b"".join(buffers)
            assert len(segment) == decoded_size
            del buffers
            if tail:
                segment = segment[:self.tail_segment_size]
            self._download_status.add_misc_event("decode", start, now())
            return (segment, decodetime)
        d.addCallback(_process)
        return d
예제 #3
0
 def _decode_multiple(res):
     log.msg("_decode_multiple")
     # make sure we can re-use the decoder object
     shares1 = random.sample(self.shares, required_shares)
     sharesl1 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
     shares1 = [ x[0] for x in sharesl1 ]
     shareids1 = [ x[1] for x in sharesl1 ]
     sharesl2 = random.sample(list(zip(self.shares, self.shareids)), required_shares)
     shares2 = [ x[0] for x in sharesl2 ]
     shareids2 = [ x[1] for x in sharesl2 ]
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares1, shareids1)
     d1.addCallback(_check_data)
     d1.addCallback(lambda res: dec.decode(shares2, shareids2))
     d1.addCallback(_check_data)
     return d1
예제 #4
0
 def _decode_multiple(res):
     log.msg("_decode_multiple")
     # make sure we can re-use the decoder object
     shares1 = random.sample(self.shares, required_shares)
     sharesl1 = random.sample(zip(self.shares, self.shareids), required_shares)
     shares1 = [ x[0] for x in sharesl1 ]
     shareids1 = [ x[1] for x in sharesl1 ]
     sharesl2 = random.sample(zip(self.shares, self.shareids), required_shares)
     shares2 = [ x[0] for x in sharesl2 ]
     shareids2 = [ x[1] for x in sharesl2 ]
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares1, shareids1)
     d1.addCallback(_check_data)
     d1.addCallback(lambda res: dec.decode(shares2, shareids2))
     d1.addCallback(_check_data)
     return d1
예제 #5
0
 def _decode(shares_and_shareids):
     (shares, shareids) = shares_and_shareids
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares, shareids)
     return d1
예제 #6
0
 def _decode((shares, shareids)):
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares, shareids)
     return d1
예제 #7
0
 def _decode(shares_and_shareids):
     (shares, shareids) = shares_and_shareids
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares, shareids)
     return d1
예제 #8
0
 def _decode((shares, shareids)):
     dec = CRSDecoder()
     dec.set_params(*params)
     d1 = dec.decode(shares, shareids)
     return d1