Beispiel #1
0
    def make_splitfile_metadata_request(self, edge, tag):
        """ Makes a StatefulRequest for the Freenet metadata for the
            CHK corresponding to an edge in the update graph.

            Helper function used by InsertingBundles state.
        """
        request = StatefulRequest(self.parent)
        request.tag = tag
        # TRICKY: Clear control bytes to get the raw CHK contents,
        # disabling Freenet metadata handling.
        uri = clear_control_bytes(self.parent.ctx.graph.get_chk(edge))
        request.in_params.definition = GET_DEF
        request.in_params.fcp_params = self.parent.params.copy()
        request.in_params.fcp_params['URI'] = uri
        self.set_cancel_time(request)
        return request
Beispiel #2
0
    def make_splitfile_metadata_request(self, edge, tag):
        """ Makes a StatefulRequest for the Freenet metadata for the
            CHK corresponding to an edge in the update graph.

            Helper function used by InsertingBundles state.
        """
        request = StatefulRequest(self.parent)
        request.tag = tag
        # TRICKY: Clear control bytes to get the raw CHK contents,
        # disabling Freenet metadata handling.
        uri = clear_control_bytes(self.parent.ctx.graph.get_chk(edge))
        request.in_params.definition = GET_DEF
        request.in_params.fcp_params = self.parent.params.copy()
        request.in_params.fcp_params['URI'] = uri
        self.set_cancel_time(request)
        return request
Beispiel #3
0
    def make_request(self, candidate):
        """ RetryingRequestList implementation. """
        uri = self.blocks[candidate[0]][1][candidate[1]]
        if candidate[2]:
            # Just top block.
            uri = clear_control_bytes(uri)

        request = CandidateRequest(self.parent)
        request.tag = str(candidate) # Hmmm
        request.candidate = candidate
        request.in_params.fcp_params = self.parent.params.copy()

        request.in_params.definition = GET_DEF
        request.in_params.fcp_params['URI'] = uri
        out_file = os.path.join(
            os.path.join(self.parent.ctx['ARCHIVE_CACHE_DIR'],
                         TMP_DIR), make_id())
        request.in_params.file_name = out_file

        self.parent.ctx.set_cancel_time(request)
        self.history.started_request(candidate)
        return request
Beispiel #4
0
    def make_request(self, candidate):
        """ Implementation of RetryingRequestList virtual. """
        #print "CANDIDATE: ", candidate
        assert len(candidate) >= 7
        candidate[
            1] += 1  # Keep track of the number of times it has been tried
        # tag == edge, but what if we don't have an edge yet?
        request = CandidateRequest(self.parent)
        request.in_params.fcp_params = self.parent.params.copy()

        uri = candidate[0]
        if candidate[2]:
            uri = clear_control_bytes(uri)
        request.in_params.fcp_params['URI'] = uri

        request.in_params.definition = GET_DEF
        request.in_params.file_name = (make_temp_file(
            self.parent.ctx.bundle_cache.base_dir))
        self.parent.ctx.set_cancel_time(request)

        # Set tag
        if not candidate[3] is None:
            request.tag = candidate[3]  # Edge
        else:
            # REDFLAG: Do better!
            # Some random digit string.
            request.tag = request.in_params.file_name[-12:]

        # Set candidate
        request.candidate = candidate

        #print "make_request --", request.tag, candidate[0]
        # Tags must be unique or we will loose requests!
        assert not request.tag in self.pending

        #request.in_params.fcp_params['MaxSize'] = ???

        return request
    def make_request(self, candidate):
        """ Implementation of RetryingRequestList virtual. """
        #print "CANDIDATE: ", candidate
        assert len(candidate) >= 7
        candidate[1] += 1 # Keep track of the number of times it has been tried
        # tag == edge, but what if we don't have an edge yet?
        request = CandidateRequest(self.parent)
        request.in_params.fcp_params = self.parent.params.copy()

        uri = candidate[0]
        if candidate[2]:
            uri = clear_control_bytes(uri)
        request.in_params.fcp_params['URI'] = uri

        request.in_params.definition = GET_DEF
        request.in_params.file_name = (
            make_temp_file(self.parent.ctx.bundle_cache.base_dir))
        self.parent.ctx.set_cancel_time(request)

        # Set tag
        if not candidate[3] is None:
            request.tag = candidate[3] # Edge
        else:
            # REDFLAG: Do better!
            # Some random digit string.
            request.tag = request.in_params.file_name[-12:]

        # Set candidate
        request.candidate = candidate

        #print "make_request --", request.tag, candidate[0]
        # Tags must be unique or we will loose requests!
        assert not request.tag in self.pending

        #request.in_params.fcp_params['MaxSize'] = ???

        return request
Beispiel #6
0
    def make_request(self, candidate):
        """ RetryingRequestList implementation. """
        #print "CREATED: ", candidate
        entry = self.files[candidate[0]]
        request = CandidateRequest(self.parent)
        request.tag = str(candidate) # Hmmm
        request.candidate = candidate
        request.in_params.fcp_params = self.parent.params.copy()

        request.in_params.definition = PUT_FILE_DEF
        request.in_params.fcp_params['URI'] = 'CHK@'

        if candidate[1] == 0:
            # Simple insert.
            request.in_params.file_name = entry[0]
            request.in_params.send_data = True
            # IMPORTANT: Don't add metadata to < 32K blocks to avoid redirect.
            if entry[1] >= FREENET_BLOCK_LEN:
                request.in_params.fcp_params['Metadata.ContentType'] = (
                   ARC_MIME_TYPE_FMT % 0)

            if entry[1] == FREENET_BLOCK_LEN:
                # UT hits this code path.
                #print "HIT len==FREENET_BLOCK_LEN case"
                # IMPORTANT: Special case len == FREENET_BLOCK_LEN
                # PAD to force splitfile insertion, so that we can salt.
                in_file = open(entry[0],'rb')
                try:
                    # Read raw data and add one zero pad byte.
                    request.in_params.send_data = in_file.read() + PAD_BYTE
                    assert (len(request.in_params.send_data) ==
                            FREENET_BLOCK_LEN + 1)
                    request.in_params.file_name = None # i.e. from string above.
                finally:
                    in_file.close()

        elif candidate[1] == 1:
            # Redundant insert.
            if entry[1] < FREENET_BLOCK_LEN:
                in_file = open(entry[0],'rb')
                try:
                    # Read raw data and add one zero pad byte.
                    request.in_params.send_data = in_file.read() + PAD_BYTE
                finally:
                    in_file.close()
            else:
                # Salted metadata.
                assert not entry[3] is None
                request.in_params.send_data = (
                    twiddle_metadata_salting(entry[3], ARC_METADATA_MARKER))
        elif candidate[1] == 2:
            # Raw topkey request
            assert entry[2][0] != None
            request.in_params.definition = GET_DEF
            request.in_params.fcp_params['MaxSize'] = FREENET_BLOCK_LEN
            request.in_params.fcp_params['URI'] = (
                clear_control_bytes(entry[2][0]))
        else:
            raise ValueError("Bad candidate: " + candidate)

        self.parent.ctx.set_cancel_time(request)
        return request