Пример #1
0
 def create_subtask_results_accepted_list(  # pylint: disable=no-self-use
     self,
     task_to_compute_1,
     task_to_compute_2,
     subtask_1_signed_by=REQUESTOR_PRIVATE_KEY,
     subtask_2_signed_by=REQUESTOR_PRIVATE_KEY,
 ) -> list:
     subtask_results_accepted_1 = SubtaskResultsAcceptedFactory(
         payment_ts="2018-02-05 12:00:16",
         report_computed_task=ReportComputedTaskFactory(
             task_to_compute=task_to_compute_1
         )
     )
     sign_message(subtask_results_accepted_1, subtask_1_signed_by)
     subtask_results_accepted_2 = SubtaskResultsAcceptedFactory(
         payment_ts="2018-02-05 12:00:16",
         report_computed_task=ReportComputedTaskFactory(
             task_to_compute=task_to_compute_2
         )
     )
     sign_message(subtask_results_accepted_2, subtask_2_signed_by)
     subtask_results_accepted_list = [
         subtask_results_accepted_1,
         subtask_results_accepted_2,
     ]
     return subtask_results_accepted_list
Пример #2
0
def force_report_computed_task(task_to_compute):
    report_computed_task = ReportComputedTaskFactory()
    report_computed_task.task_to_compute = task_to_compute
    sign_message(report_computed_task, PROVIDER_PRIVATE_KEY)

    force_report_computed_task  = ForceReportComputedTask()
    force_report_computed_task.report_computed_task = report_computed_task
    return force_report_computed_task
 def setUp(self):
     self.time = datetime.datetime.strptime("2017-11-17 10:00:00", "%Y-%m-%d %H:%M:%S")
     self.deadline = 10
     self.authorized_client_public_key = b'7' * 64
     self.report_computed_task = ReportComputedTaskFactory(
         task_to_compute__compute_task_def__deadline=parse_datetime_to_timestamp(self.time) + self.deadline
     )
Пример #4
0
 def _get_deserialized_report_computed_task(
     self,
     subtask_id: str = '2',
     task_id: str = '1',
     task_to_compute: Optional[TaskToCompute] = None,
     size: int = 1,
     package_hash: str = 'sha1:4452d71687b6bc2c9389c3349fdc17fbd73b833b',
     timestamp: Optional[str] = None,
     signer_private_key: Optional[bytes] = None,
     frames: Optional[List[int]] = None,
 ) -> ReportComputedTask:
     """ Returns ReportComputedTask deserialized. """
     with freeze_time(timestamp or get_timestamp_string()):
         report_computed_task = ReportComputedTaskFactory(
             task_to_compute=(
                 task_to_compute or self._get_deserialized_task_to_compute(
                     subtask_id=subtask_id,
                     task_id=task_id,
                     frames=frames if frames is not None else [1])),
             package_hash=package_hash,
             size=size,
         )
     report_computed_task = self._sign_message(
         report_computed_task,
         signer_private_key
         if signer_private_key is not None else self.PROVIDER_PRIVATE_KEY,
     )
     return report_computed_task
def ack_report_computed_task(task_to_compute):
    ack_report_computed_task = AckReportComputedTask()
    ack_report_computed_task.report_computed_task = ReportComputedTaskFactory()
    ack_report_computed_task.report_computed_task.task_to_compute = task_to_compute
    sign_message(ack_report_computed_task.report_computed_task,
                 PROVIDER_PRIVATE_KEY)
    return ack_report_computed_task
Пример #6
0
 def create_subtask_results_accepted_list(  # pylint: disable=no-self-use
     self,
     task_to_compute_1,
     task_to_compute_2,
     subtask_1_signed_by=REQUESTOR_PRIVATE_KEY,
     subtask_2_signed_by=REQUESTOR_PRIVATE_KEY,
 ) -> list:
     with freeze_time():
         subtask_results_accepted_1 = SubtaskResultsAcceptedFactory(
             report_computed_task=ReportComputedTaskFactory(
                 task_to_compute=task_to_compute_1))
         sign_message(subtask_results_accepted_1, subtask_1_signed_by)
         subtask_results_accepted_2 = SubtaskResultsAcceptedFactory(
             report_computed_task=ReportComputedTaskFactory(
                 task_to_compute=task_to_compute_2))
         sign_message(subtask_results_accepted_2, subtask_2_signed_by)
         subtask_results_accepted_list = [
             subtask_results_accepted_1,
             subtask_results_accepted_2,
         ]
     return subtask_results_accepted_list
Пример #7
0
def create_report_computed_task() -> ReportComputedTask:
    current_time = get_current_utc_timestamp()

    task_to_compute = create_signed_task_to_compute(
        timestamp=timestamp_to_isoformat(current_time),
        deadline=(current_time + 100),
        price=10000,
    )

    report_computed_task = ReportComputedTaskFactory(
        task_to_compute=task_to_compute,
    )
    sign_message(report_computed_task, PROVIDER_PRIVATE_KEY)
    return report_computed_task
 def test_that_file_transfer_token_for_concent_is_never_out_of_date(self):
     report_computed_task = ReportComputedTaskFactory()
     token = create_file_transfer_token_for_concent(
         subtask_id=report_computed_task.subtask_id,
         source_package_path=get_storage_source_file_path(
             subtask_id=report_computed_task.subtask_id,
             task_id=report_computed_task.task_id,
         ),
         source_size=report_computed_task.task_to_compute.size,
         source_package_hash=report_computed_task.task_to_compute.package_hash,
         result_package_path=get_storage_result_file_path(
             subtask_id=report_computed_task.subtask_id,
             task_id=report_computed_task.task_id,
         ),
         result_size=report_computed_task.size,
         result_package_hash=report_computed_task.package_hash,
         operation=FileTransferToken.Operation.download,
     )
     self.assertTrue(token.timestamp < token.token_expiration_deadline)
    def setUp(self):
        super().setUp()

        task_id = self._get_uuid()
        subtask_id = self._get_uuid()

        report_computed_task = ReportComputedTaskFactory(subtask_id=subtask_id,
                                                         task_id=task_id)

        self.subtask = store_subtask(
            task_id=task_id,
            subtask_id=subtask_id,
            provider_public_key=self.PROVIDER_PUBLIC_KEY,
            requestor_public_key=self.REQUESTOR_PUBLIC_KEY,
            state=Subtask.SubtaskState.ADDITIONAL_VERIFICATION,
            next_deadline=get_current_utc_timestamp() +
            settings.CONCENT_MESSAGING_TIME,
            task_to_compute=report_computed_task.task_to_compute,
            report_computed_task=report_computed_task)
Пример #10
0
    def setUp(self):
        super().setUp()

        (self.PROVIDER_PRIVATE_KEY,
         self.PROVIDER_PUBLIC_KEY) = generate_ecc_key_pair()
        (self.REQUESTOR_PRIVATE_KEY,
         self.REQUESTOR_PUBLIC_KEY) = generate_ecc_key_pair()

        self.task_to_compute = TaskToComputeFactory()

        self.subtask = store_subtask(
            task_id=self.task_to_compute.task_id,
            subtask_id=self.task_to_compute.subtask_id,
            provider_public_key=self.PROVIDER_PUBLIC_KEY,
            requestor_public_key=self.REQUESTOR_PUBLIC_KEY,
            state=Subtask.SubtaskState.ADDITIONAL_VERIFICATION,
            next_deadline=get_current_utc_timestamp() +
            settings.CONCENT_MESSAGING_TIME,
            task_to_compute=self.task_to_compute,
            report_computed_task=ReportComputedTaskFactory(
                task_to_compute=self.task_to_compute, ))
Пример #11
0
 def _get_deserialized_report_computed_task(
     self,
     subtask_id: str = '2',
     task_id: str = '1',
     task_to_compute = None,
     size: int = 1,
     package_hash: str = 'sha1:4452d71687b6bc2c9389c3349fdc17fbd73b833b',
     timestamp: int = None,
 ):
     """ Returns ReportComputedTask deserialized. """
     with freeze_time(timestamp or self._get_timestamp_string()):
         report_computed_task = ReportComputedTaskFactory(
             task_to_compute=(
                 task_to_compute or self._get_deserialized_task_to_compute(
                     subtask_id=subtask_id,
                     task_id=task_id,
                 )
             ),
             package_hash=package_hash,
             size=size,
         )
     return report_computed_task
Пример #12
0
def get_force_get_task_result(task_id, subtask_id, current_time,
                              cluster_consts, size, package_hash):
    task_to_compute = create_signed_task_to_compute(
        task_id=task_id,
        subtask_id=subtask_id,
        deadline=current_time,
        price=0,
    )

    with freeze_time(timestamp_to_isoformat(current_time - 1)):
        report_computed_task = ReportComputedTaskFactory(
            task_to_compute=task_to_compute,
            size=size,
            package_hash=package_hash,
            subtask_id=subtask_id,
        )
        sign_message(report_computed_task, PROVIDER_PRIVATE_KEY)

    with freeze_time(timestamp_to_isoformat(current_time)):
        force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=report_computed_task, )

    return force_get_task_result
Пример #13
0
 def store_report_computed_task_as_subtask(self, current_time, task_id,
                                           deadline, next_deadline,
                                           subtask_state):  # pylint: disable=no-self-use
     subtask_id = task_id + '1'
     file_content = '1'
     file_size = len(file_content)
     file_check_sum = 'sha1:' + hashlib.sha1(
         file_content.encode()).hexdigest()
     task_to_compute = self._get_deserialized_task_to_compute(
         task_id=task_id,
         subtask_id=subtask_id,
         deadline=deadline,
         price=0,
         timestamp=parse_timestamp_to_utc_datetime(current_time),
         signer_private_key=self.REQUESTOR_PRIVATE_KEY)
     report_computed_task = ReportComputedTaskFactory(
         task_to_compute=task_to_compute,
         size=file_size,
         package_hash=file_check_sum,
         subtask_id=subtask_id,
         sign__privkey=self.PROVIDER_PRIVATE_KEY,
     )
     force_get_task_result = ForceGetTaskResult(
         report_computed_task=report_computed_task, )
     store_subtask(
         task_id=report_computed_task.task_to_compute.task_id,
         subtask_id=report_computed_task.task_to_compute.subtask_id,
         provider_public_key=hex_to_bytes_convert(
             report_computed_task.task_to_compute.provider_public_key),
         requestor_public_key=hex_to_bytes_convert(
             report_computed_task.task_to_compute.requestor_public_key),
         state=subtask_state,
         next_deadline=next_deadline,
         task_to_compute=report_computed_task.task_to_compute,
         report_computed_task=report_computed_task,
         force_get_task_result=force_get_task_result,
     )
Пример #14
0
def get_force_get_task_result(
    current_time: int,
    size: int,
    package_hash: str,
) -> message.concents.ForceGetTaskResult:
    task_to_compute = create_signed_task_to_compute(
        deadline=current_time,
        price=1,
    )

    with freeze_time(timestamp_to_isoformat(current_time - 1)):
        report_computed_task = ReportComputedTaskFactory(
            task_to_compute=task_to_compute,
            size=size,
            package_hash=package_hash,
        )
        sign_message(report_computed_task, PROVIDER_PRIVATE_KEY)

    with freeze_time(timestamp_to_isoformat(current_time)):
        force_get_task_result = message.concents.ForceGetTaskResult(
            report_computed_task=report_computed_task,
        )

    return force_get_task_result
Пример #15
0
 def setUp(self):
     self.report_computed_task = ReportComputedTaskFactory()
     store_report_computed_task_as_subtask(self.report_computed_task)