Skip to content

Commit

Permalink
Report changed workload (crustio#234)
Browse files Browse the repository at this point in the history
* Report changed workload

* Add restart test case

* Change makefile
  • Loading branch information
TonyCode2012 authored Sep 30, 2020
1 parent 0116569 commit 320d2e2
Show file tree
Hide file tree
Showing 32 changed files with 1,184 additions and 168 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ build:
test:
@$(MAKE) -C test/unit test --no-print-directory

integration_test:
@$(MAKE) -C test/integration test --no-print-directory
build_test:
@$(MAKE) -C test/integration build --no-print-directory

functionality_test:
@$(MAKE) -C test/integration functionality_test --no-print-directory

clean:
@$(MAKE) -C src/ clean --no-print-directory
Expand Down
2 changes: 2 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ printf "%s%s\n\n" "$pad" '/____/ |__/|__/\____/_/ /_/|_|\___/_/ /_/_/ /_/__

verbose INFO "Version -----------------$newversion-------------------"

disown -r

# check previous crust-sworker
checkOldCrustTee

Expand Down
2 changes: 2 additions & 0 deletions scripts/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ crust_env_file=$realsworkerdir/etc/environment
sgx_env_file=/opt/intel/sgxsdk/environment


disown -r

. $scriptdir/utils.sh

#trap "success_exit" INT
Expand Down
20 changes: 20 additions & 0 deletions src/app/ecalls/ECalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ std::unordered_map<std::string, int> g_task_priority_um = {
{"Ecall_get_signed_order_report", 0},
{"Ecall_confirm_file", 0},
{"Ecall_delete_file", 0},
{"Ecall_handle_report_result", 0},
{"Ecall_seal_file", 1},
{"Ecall_unseal_file", 1},
{"Ecall_srd_decrease", 1},
Expand Down Expand Up @@ -582,6 +583,25 @@ sgx_status_t Ecall_delete_file(sgx_enclave_id_t eid, crust_status_t *status, con
return ret;
}

/**
* @description: Delete file
* @param flag -> Report result
*/
sgx_status_t Ecall_handle_report_result(sgx_enclave_id_t eid)
{
sgx_status_t ret = SGX_SUCCESS;
if (SGX_SUCCESS != (ret = try_get_enclave(__FUNCTION__)))
{
return ret;
}

ret = ecall_handle_report_result(eid);

free_enclave(__FUNCTION__);

return ret;
}

/**
* @description: Get enclave id information
*/
Expand Down
2 changes: 2 additions & 0 deletions src/app/ecalls/ECalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ sgx_status_t Ecall_confirm_file(sgx_enclave_id_t eid, crust_status_t *status, co

sgx_status_t Ecall_delete_file(sgx_enclave_id_t eid, crust_status_t *status, const char *hash);

sgx_status_t Ecall_handle_report_result(sgx_enclave_id_t eid);

sgx_status_t Ecall_get_signed_order_report(sgx_enclave_id_t eid, crust_status_t *status);

sgx_status_t Ecall_id_get_info(sgx_enclave_id_t eid);
Expand Down
16 changes: 16 additions & 0 deletions src/app/process/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ void storage_add_delete(std::string hash)
}
});
}

/**
* @description: Add delete meaningful file task
* @param hash -> Meaningful file root hash
*/
void report_add_callback()
{
sgx_enclave_id_t eid = global_eid;
std::async(std::launch::async, [eid](){
sgx_status_t sgx_status = SGX_SUCCESS;
if (SGX_SUCCESS != (sgx_status = Ecall_handle_report_result(eid)))
{
p_log->err("Report result failed!Invoke SGX API failed!Error code:%lx\n", sgx_status);
}
});
}
1 change: 1 addition & 0 deletions src/app/process/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern "C"

void storage_add_confirm(std::string hash);
void storage_add_delete(std::string hash);
void report_add_callback();

#if defined(__cplusplus)
}
Expand Down
1 change: 1 addition & 0 deletions src/app/process/WorkReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void work_report_loop(void)
else
{
p_log->info("Send work report to crust chain successfully!\n");
report_add_callback();
}
}
else if (crust_status == CRUST_BLOCK_HEIGHT_EXPIRED)
Expand Down
1 change: 1 addition & 0 deletions src/app/process/WorkReport.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "CrustStatus.h"
#include "FormatUtils.h"
#include "Data.h"
#include "Storage.h"

#define REPORT_BLOCK_HEIGHT_BASE 300
#define BLOCK_INTERVAL 6
Expand Down
9 changes: 9 additions & 0 deletions src/enclave/Enclave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ crust_status_t ecall_delete_file(const char *hash)
return ret;
}

/**
* @description: Set work report result
* @param flag -> Report result
*/
void ecall_handle_report_result()
{
Workload::get_instance()->handle_report_result();
}

/**
* @description: Get enclave id information
*/
Expand Down
1 change: 1 addition & 0 deletions src/enclave/Enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enclave {
public crust_status_t ecall_unseal_file([in, count=files_num] char **files, size_t files_num, [in, string] const char *p_dir, [out, size=path_len] char *p_new_path, uint32_t path_len);
public crust_status_t ecall_confirm_file([in, string] const char *hash);
public crust_status_t ecall_delete_file([in, string] const char *hash);
public void ecall_handle_report_result();

public void ecall_id_get_info();
public void ecall_get_workload();
Expand Down
30 changes: 11 additions & 19 deletions src/enclave/identity/Identity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ crust_status_t id_verify_iasreport(char **IASReport, size_t size)
status = CRUST_SIGN_PUBKEY_FAILED;
goto cleanup;
}

// Get tee identity and store it outside of tee
id_json[IAS_CERT] = certchain_1;
id_json[IAS_SIG] = ias_sig;
Expand Down Expand Up @@ -924,16 +924,16 @@ crust_status_t id_store_metadata()
meta_len += wl->srd_path2hashs_m.size() * (128 + 4);
meta_len += strlen(TEE_PRIVATE_TAG) + 5
+ strlen(ID_WORKLOAD) + 5
+ strlen(ID_KEY_PAIR) + 5
+ strlen(ID_REPORT_SLOT) + 5
+ strlen(ID_CHAIN_ACCOUNT_ID) + 5
+ strlen(ID_FILE) + 5;
size_t file_item_len = strlen(FILE_HASH) + 3 + 64 + 3
+ strlen(FILE_OLD_HASH) + 3 + 64 + 3
+ strlen(FILE_SIZE) + 3 + 14 + 1
+ strlen(FILE_OLD_SIZE) + 3 + 14 + 1
+ strlen(FILE_BLOCK_NUM) + 3 + 14 + 4
+ strlen(FILE_STATUS) + 16 + 4
+ strlen(ID_KEY_PAIR) + 3 + 256 + 3
+ strlen(ID_REPORT_SLOT) + 3 + 20 + 1
+ strlen(ID_CHAIN_ACCOUNT_ID) + 3 + 64 + 3
+ strlen(ID_FILE) + 3;
size_t file_item_len = strlen(FILE_HASH) + 3 + strlen(HASH_TAG) + 64 + 3
+ strlen(FILE_OLD_HASH) + 3 + strlen(HASH_TAG) + 64 + 3
+ strlen(FILE_SIZE) + 3 + 12 + 1
+ strlen(FILE_OLD_SIZE) + 3 + 12 + 1
+ strlen(FILE_BLOCK_NUM) + 3 + 6 + 1
+ strlen(FILE_STATUS) + 3 + 3 + 3
+ 2;
meta_len += wl->checked_files.size() * file_item_len;
uint8_t *meta_buf = (uint8_t *)enc_malloc(meta_len);
Expand Down Expand Up @@ -1094,14 +1094,6 @@ crust_status_t id_restore_metadata()
g_is_set_account_id = true;
just_after_restart = true;

// Show workload
json::JSON wl_json = json::JSON::Load(wl->get_workload());
std::string wl_str = wl_json.dump();
replace(wl_str, "\"{", "{");
replace(wl_str, "}\"", " }");
remove_char(wl_str, '\\');
log_info("Workload:\n%s\n", wl_str.c_str());

return CRUST_SUCCESS;
}

Expand Down
21 changes: 17 additions & 4 deletions src/enclave/include/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
#define FILE_OLD_HASH "old_hash"
#define FILE_BLOCK_NUM "block_num"
#define FILE_STATUS "status"
#define FILE_STATUS_LOST "lost"
#define FILE_STATUS_VALID "valid"
#define FILE_STATUS_UNCONFIRMED "unconfirmed"
#define FILE_STATUS_UNCONFIRMED '0'
#define FILE_STATUS_VALID '1'
#define FILE_STATUS_LOST '2'
#define FILE_STATUS_DELETED '3'
// Current status
#define CURRENT_STATUS 0
// Wait to sync status
#define WAITING_STATUS 1
// Old status
#define ORIGIN_STATUS 2

// For DB data
#define DB_SRD_INFO "srd_info"
Expand All @@ -46,11 +53,17 @@

// For work report
#define WORKREPORT_PUB_KEY "pub_key"
#define WORKREPORT_PRE_PUB_KEY "pre_pub_key"
#define WORKREPORT_BLOCK_HEIGHT "block_height"
#define WORKREPORT_BLOCK_HASH "block_hash"
#define WORKREPORT_RESERVED "reserved"
#define WORKREPORT_FILES "files"
#define WORKREPORT_FILES_SIZE "files_size"
#define WORKREPORT_RESERVED_ROOT "reserved_root"
#define WORKREPORT_FILES_ROOT "files_root"
#define WORKREPORT_FILES_ADDED "added_files"
#define WORKREPORT_FILES_DELETED "deleted_files"
#define WORKREPORT_SIG "sig"
#define WORKREPORT_FILE_LIMIT 1000

// For order report
#define ORDERREPORT_FILES "files"
Expand Down
Loading

0 comments on commit 320d2e2

Please sign in to comment.