diff --git a/examples/ipfs_node/Config.toml b/examples/ipfs_node/Config.toml index c19e5d69..d340ff91 100644 --- a/examples/ipfs_node/Config.toml +++ b/examples/ipfs_node/Config.toml @@ -8,7 +8,7 @@ ipfs = "/usr/local/bin/ipfs" [core_module.wasi] - envs = [] + envs = ["IPFS_ADDR=/dns4/relay02.fluence.dev/tcp/15001"] preopened_files = ["./wasm/artifacts"] mapped_dirs = { "tmp" = "./wasm/artifacts" } diff --git a/examples/ipfs_node/src/main.rs b/examples/ipfs_node/src/main.rs index 865d78e3..5fb81000 100644 --- a/examples/ipfs_node/src/main.rs +++ b/examples/ipfs_node/src/main.rs @@ -34,11 +34,11 @@ fn main() { println!("ipfs node interface is\n{}", ipfs_node.get_interface()); - let node_addresses = ipfs_node - .call_module("ipfs_node.wasm", "get_addresses", &[]) + let node_address = ipfs_node + .call_module("ipfs_node.wasm", "get_address", &[]) .unwrap(); - println!("ipfs node addresses are:\n{:?}", node_addresses); + println!("ipfs node address is:\n{:?}", node_address); let result = ipfs_node .call_code( diff --git a/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm b/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm index 67d21f9c..6028f984 100644 Binary files a/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm and b/examples/ipfs_node/wasm/artifacts/wasm_modules/ipfs_node.wasm differ diff --git a/examples/ipfs_node/wasm/ipfs_node/src/main.rs b/examples/ipfs_node/wasm/ipfs_node/src/main.rs index 77fcd5d6..74a9811c 100644 --- a/examples/ipfs_node/wasm/ipfs_node/src/main.rs +++ b/examples/ipfs_node/wasm/ipfs_node/src/main.rs @@ -24,6 +24,7 @@ use crate::result::{RESULT_PTR, RESULT_SIZE}; use crate::path::to_full_path; const RESULT_FILE_PATH: &str = "/tmp/ipfs_rpc_file"; +const IPFS_ADDR_ENV_NAME: &str = "IPFS_ADDR"; pub fn main() { let msg = "ipfs_node.main: WASI initialization finished"; @@ -92,32 +93,24 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { } #[no_mangle] -pub unsafe fn get_addresses() { - let msg = "ipfs_node.get_addresses".to_string(); +pub unsafe fn get_address() { + let msg = "ipfs_node.get_address".to_string(); log_utf8_string(msg.as_ptr() as _, msg.len() as _); - let cmd = "id -f''"; - let result = ipfs(cmd.as_ptr() as _, cmd.len() as _); - - let multiaddrs = if result == 0 { - String::from_raw_parts( - *RESULT_PTR.get_mut() as _, - *RESULT_SIZE.get_mut(), - *RESULT_SIZE.get_mut(), - ) - } else { - "host ipfs call failed".to_string() + let ipfs_address = match std::env::var(IPFS_ADDR_ENV_NAME) { + Ok(addr) => addr, + Err(e) => format!("getting {} env variable failed with error {:?}", IPFS_ADDR_ENV_NAME, e) }; let msg = format!( - "ipfs_node.get_addresses: node addresses are {} \n", - multiaddrs + "ipfs_node.get_address: node address is {} \n", + ipfs_address ); log_utf8_string(msg.as_ptr() as _, msg.len() as _); - *RESULT_PTR.get_mut() = multiaddrs.as_ptr() as _; - *RESULT_SIZE.get_mut() = multiaddrs.len(); - std::mem::forget(multiaddrs); + *RESULT_PTR.get_mut() = ipfs_address.as_ptr() as _; + *RESULT_SIZE.get_mut() = ipfs_address.len(); + std::mem::forget(ipfs_address); } #[link(wasm_import_module = "host")] diff --git a/examples/ipfs_node/wasm/ipfs_node/wit b/examples/ipfs_node/wasm/ipfs_node/wit index 9773b342..bc2b1e61 100644 --- a/examples/ipfs_node/wasm/ipfs_node/wit +++ b/examples/ipfs_node/wasm/ipfs_node/wit @@ -25,10 +25,10 @@ ;; import ipfs put/get function (@interface type (func (param string) (result string))) ;; 8 -;; export ipfs.get_addresses function +;; export ipfs.get_address function (@interface type (func (result string))) ;; 9 -;; export ipfs.get_addresses function +;; export ipfs.get_address function (@interface type (func )) ;; 10 (@interface export "allocate" (func 0)) ;; 0 @@ -40,7 +40,7 @@ (@interface export "put" (func 5)) ;; 6 (@interface export "get" (func 6)) ;; 7 -(@interface export "get_addresses" (func 10)) ;; 8 +(@interface export "get_address" (func 10)) ;; 8 ;; adapter for export function put (@interface func (type 7) @@ -74,7 +74,7 @@ call-core 1 ;; call deallocate ) -;; adapter for export function get_addresses +;; adapter for export function get_address (@interface func (type 9) call-core 8 ;; call self.get call-core 3 ;; call get_result_ptr