mirror of
https://github.com/fluencelabs/marine.git
synced 2025-06-28 22:21:38 +00:00
repair put/get
This commit is contained in:
@ -22,7 +22,7 @@ use crate::result::{RESULT_PTR, RESULT_SIZE};
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const RPC_TMP_FILEPATH: &str = "/tmp/ipfs_rpc_file";
|
||||
const RPC_TMP_FILEPATH: &str = "/Users/mike/dev/work/fluence/wasm/tmp/ipfs_rpc_file";
|
||||
|
||||
pub fn main() {
|
||||
println!("ipfs_rpc.main: WASI initialization finished");
|
||||
@ -30,9 +30,11 @@ pub fn main() {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe fn invoke(_ptr: *mut u8, _size: usize) {
|
||||
println!("ipfs_rpc.invoke: invoke called");
|
||||
let msg = "ipfs_rpc.invoke: invoke called\n";
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
|
||||
let result = "IFPFS_RPC wasm example, it allows to:\ninvoke\nput\nget".to_string();
|
||||
|
||||
let result = "IPFS_RPC wasm example, it allow:\nput\nget".to_string();
|
||||
*RESULT_PTR.get_mut() = result.as_ptr() as _;
|
||||
*RESULT_SIZE.get_mut() = result.len();
|
||||
std::mem::forget(result);
|
||||
@ -43,13 +45,15 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
||||
let file_content =
|
||||
String::from_raw_parts(file_content_ptr, file_content_size, file_content_size);
|
||||
|
||||
println!("ipfs_rpc.put: file_content is {}\n", file_content);
|
||||
let msg = format!("ipfs_rpc.put: file_content is {}\n", file_content);
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
|
||||
let rpc_tmp_filepath = RPC_TMP_FILEPATH.to_string();
|
||||
|
||||
let r = fs::write(PathBuf::from(rpc_tmp_filepath.clone()), file_content);
|
||||
if let Err(e) = r {
|
||||
println!("{}", e);
|
||||
let msg: String = e.to_string();
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
}
|
||||
|
||||
ipfs_put(rpc_tmp_filepath.as_ptr() as _, rpc_tmp_filepath.len() as _);
|
||||
@ -61,7 +65,8 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
||||
*RESULT_SIZE.get_mut(),
|
||||
);
|
||||
|
||||
println!("ipfs_rpc.put: file add with hash {}\n", hash);
|
||||
let msg = format!("ipfs_rpc.put: file add with hash {}\n", hash);
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
|
||||
*RESULT_PTR.get_mut() = hash.as_ptr() as _;
|
||||
*RESULT_SIZE.get_mut() = hash.len();
|
||||
@ -72,7 +77,8 @@ pub unsafe fn put(file_content_ptr: *mut u8, file_content_size: usize) {
|
||||
pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
|
||||
let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size);
|
||||
|
||||
println!("ipfs_rpc.get: getting file with hash {}\n", hash);
|
||||
let msg = format!("ipfs_rpc.get: getting file with hash {}\n", hash);
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
|
||||
ipfs_get(hash.as_ptr() as _, hash.len() as _);
|
||||
|
||||
@ -82,7 +88,8 @@ pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) {
|
||||
*RESULT_SIZE.get_mut(),
|
||||
);
|
||||
|
||||
println!("ipfs_rpc.get: reading file from {}\n", file_path);
|
||||
let msg = format!("ipfs_rpc.get: reading file from {}\n", file_path);
|
||||
log_utf8_string(msg.as_ptr() as _, msg.len() as _);
|
||||
|
||||
let file_content = fs::read(file_path).unwrap_or_else(|_| b"error while reading file".to_vec());
|
||||
|
||||
|
@ -50,8 +50,8 @@
|
||||
(@interface import "ipfs_node.wasm" "get" (func (type 5)))
|
||||
(@interface import "ipfs_node.wasm" "put" (func (type 6)))
|
||||
|
||||
(@interface import "ipfs_node.wasm" "get" (func (type 7))) ;; 7
|
||||
(@interface import "ipfs_node.wasm" "put" (func (type 8))) ;; 8
|
||||
(@interface import "ipfs_node.wasm" "get" (func (type 7))) ;; 9
|
||||
(@interface import "ipfs_node.wasm" "put" (func (type 8))) ;; 10
|
||||
|
||||
;; adapter for export invoke function
|
||||
(@interface func (type 2)
|
||||
@ -106,7 +106,7 @@
|
||||
arg.get 0
|
||||
arg.get 1
|
||||
string.lift_memory
|
||||
call-core 7 ;; call ipfs_node.get that returns string
|
||||
call-core 9 ;; call ipfs_node.get that returns string
|
||||
dup
|
||||
string.size
|
||||
call-core 0 ;; call allocate
|
||||
@ -121,7 +121,7 @@
|
||||
arg.get 0
|
||||
arg.get 1
|
||||
string.lift_memory
|
||||
call-core 8 ;; call ipfs_node.put that returns string
|
||||
call-core 10 ;; call ipfs_node.put that returns string
|
||||
dup
|
||||
string.size
|
||||
call-core 0 ;; call allocate
|
||||
|
Reference in New Issue
Block a user