Example: mesatee_services/fns/sgx_trusted_lib/src/trusted_worker/private_join_and_compute.rs
- Only use sgx-compatible crates.
- No I/O or network capabilities.
- Single: Only one customer participates in this computation task
- Multiparty: More than two customers participate in this computation task
Convention
fn function_name(
helper: &mut WorkerHelper, //crate::trait_defs::WorkerHelper
input: WorkerInput, //crate::trait_defs::WorkerInput
) -> Result<String> //mesatee_core::Result
pub struct WorkerInput {
pub function_name: String, //function name
pub input_files: Vec<String>, //input file ids; files are saved in the TDFS
pub payload: Option<String>, //dynamic input, provided by the user who invokes the task
}
Read a file with file id
trait WorkerHelper {
fn read_file(&mut self, file_id: &str) -> Result<Vec<u8>>;
}
Note:
The function doesn't know who provides the payload/file. The file-id/payload can belong to any participatant in this task
There are four types of output
-
A String returned to the user who invokes the task. It's the return value of the function
fn function_name( helper: &mut WorkerHelper, //crate::trait_defs::WorkerHelper input: WorkerInput, //crate::trait_defs::WorkerInput ) -> Result<String> //mesatee_core::Result
-
Save the content to the TDFS for the task creator.
The file id will be saved to the task. The function return value doesn't need to contain the file id.
trait WorkerHelper { fn save_file_for_task_creator(&mut self, data: &[u8]) -> Result<String>; } // return value is the file id
-
Save the content to the TDFS for the owner of one input file.
The file id will be saved to the task. The function return value doesn't need to contain the file id.
trait WorkerHelper { fn save_file_for_file_owner(&mut self, data: &[u8], file_id: &str) -> Result<String>; } // return value is the file id
-
Save the content to the TDFS for all the participatants.
The file id will be saved to the task. The function return value doesn't need to contain the file id.
Only the last one will be saved in the task.
trait WorkerHelper { fn save_file_for_all_participants(&mut self, data: &<u8>) -> Result<String>; } // return value is the file id
In mesatee_services/fns/sgx_trusted_lib/src/trusted_worker/mod.rs
dispatcher.insert(
"function_name".to_string(),
mod_name::function_name,
);
If the function is a multiparty function, it needs to be marked in the Task Management Service
In mesatee_services/tms/sgx_trusted_lib/src/tms_external.rs
"psi" | "concat" | "swap_file" | "private_join_and_compute" | "your_function" => FunctionType::Multiparty