Set current peer id for aquamarine stepper (#31)

This commit is contained in:
vms 2020-10-01 20:16:16 +03:00 committed by GitHub
parent 7174906784
commit abcdb37c91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -25,6 +25,7 @@ use std::path::PathBuf;
const AQUAMARINE_WASM_FILE_NAME: &str = "aquamarine";
const CALL_SERVICE_NAME: &str = "call_service";
const CURRENT_PEER_ID_ENV_NAME: &str = "CURRENT_PEER_ID";
unsafe impl Send for AquamarineVM {}
@ -49,13 +50,20 @@ impl AquamarineVM {
let mut host_imports = HashMap::new();
host_imports.insert(String::from(CALL_SERVICE_NAME), config.call_service);
let aquamarine_module_config = FaaSModuleConfig {
let mut aquamarine_module_config = FaaSModuleConfig {
mem_pages_count: None,
logger_enabled: true,
host_imports,
wasi: None,
};
let mut envs = HashMap::new();
envs.insert(
CURRENT_PEER_ID_ENV_NAME.as_bytes().to_vec(),
config.current_peer_id.into_bytes(),
);
aquamarine_module_config.extend_wasi_envs(envs);
let mut aquamarine_wasm_dir = config.aquamarine_wasm_path;
// faas config requires a path to the directory with Wasm modules
aquamarine_wasm_dir.pop();
@ -90,7 +98,7 @@ impl AquamarineVM {
}
let ret_code = match record_values.remove(0) {
IValue::I32(ret_code) => ret_code,
IValue::S32(ret_code) => ret_code,
v => return Err(AquamarineVMError::AquamarineResultError(format!("expected i32 for ret_code, got {:?}", v))),
};

View File

@ -24,4 +24,7 @@ pub struct AquamarineVMConfig {
/// Descriptor of a closure that will be invoked on call_service call from Aquamarine stepper.
pub call_service: HostImportDescriptor,
/// Current peer id.
pub current_peer_id: String,
}