add configurable timeout to ipfs commands

This commit is contained in:
vms 2020-07-01 18:54:26 +03:00
parent 80afea2094
commit 27d9e5c8f2
4 changed files with 10 additions and 3 deletions

View File

@ -10,7 +10,7 @@ core_modules_dir = "wasm/artifacts/wasm_modules"
ipfs = "/usr/local/bin/ipfs" ipfs = "/usr/local/bin/ipfs"
[core_module.wasi] [core_module.wasi]
envs = ["IPFS_ADDR=/dns4/relay02.fluence.dev/tcp/15001"] envs = ["IPFS_ADDR=/dns4/relay02.fluence.dev/tcp/15001", "timeout=1s"]
preopened_files = ["./wasm/artifacts"] preopened_files = ["./wasm/artifacts"]
mapped_dirs = { "tmp" = "./wasm/artifacts" } mapped_dirs = { "tmp" = "./wasm/artifacts" }

View File

@ -25,6 +25,7 @@ use crate::path::to_full_path;
const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file"; const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file";
const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR"; const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR";
const TIMEOUT_ENV_NAME: &str = "timeout";
pub fn main() { pub fn main() {
let msg = "ipfs_node.main: WASI initialization finished"; let msg = "ipfs_node.main: WASI initialization finished";
@ -42,7 +43,8 @@ pub unsafe fn put(file_path_ptr: *mut u8, file_path_size: usize) {
let file_path = to_full_path(file_path); let file_path = to_full_path(file_path);
let cmd = format!("add -Q {}", file_path); let timeout = std::env::var(TIMEOUT_ENV_NAME).unwrap_or_else(|_| "1s".to_string());
let cmd = format!("add --timeout {} -Q {}", timeout, file_path);
let result = ipfs(cmd.as_ptr() as _, cmd.len() as _); let result = ipfs(cmd.as_ptr() as _, cmd.len() as _);
let hash = if result == 0 { let hash = if result == 0 {
@ -72,7 +74,11 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
let result_file_path = to_full_path(RESULT_FILE_PATH); let result_file_path = to_full_path(RESULT_FILE_PATH);
let cmd = format!("get -o {} {}", result_file_path, hash); let timeout = std::env::var(TIMEOUT_ENV_NAME).unwrap_or_else(|_| "1s".to_string());
let cmd = format!(
"get --timeout {} -o {} {}",
timeout, result_file_path, hash
);
let _result = ipfs(cmd.as_ptr() as _, cmd.len() as _); let _result = ipfs(cmd.as_ptr() as _, cmd.len() as _);
let _output = String::from_raw_parts( let _output = String::from_raw_parts(

View File

@ -41,6 +41,7 @@ where
let mut full_path = std::path::PathBuf::from(to_dir); let mut full_path = std::path::PathBuf::from(to_dir);
// TODO: optimize this // TODO: optimize this
#[warn(clippy::while_let_on_iterator)]
while let Some(component) = components.next() { while let Some(component) = components.next() {
full_path.push(component); full_path.push(component);
} }