diff --git a/Cargo.lock b/Cargo.lock index ae911930..2414ad9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -514,10 +514,9 @@ dependencies = [ [[package]] name = "ipfs_node" version = "0.1.0" - -[[package]] -name = "ipfs_rpc" -version = "0.1.0" +dependencies = [ + "fce", +] [[package]] name = "lazy_static" @@ -1035,6 +1034,14 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasm_ipfs_node" +version = "0.1.0" + +[[package]] +name = "wasm_ipfs_rpc" +version = "0.1.0" + [[package]] name = "wasmer-clif-backend" version = "0.17.0" diff --git a/Cargo.toml b/Cargo.toml index 80be2fe3..d5ceb0fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [workspace] members = [ "crates/fce_wit_interfaces", - "examples/export_test", "examples/ipfs_node", - "examples/ipfs_rpc", + "examples/ipfs_node/wasm/ipfs_node", + "examples/ipfs_node/wasm/ipfs_rpc", + "examples/simple_greeting", "fce", "tools/wit_embedder", ] diff --git a/examples/ipfs_node/Cargo.toml b/examples/ipfs_node/Cargo.toml index 0cbfa3a7..08a6e6a6 100644 --- a/examples/ipfs_node/Cargo.toml +++ b/examples/ipfs_node/Cargo.toml @@ -4,7 +4,5 @@ version = "0.1.0" authors = ["Fluence Labs"] edition = "2018" -[lib] -name = "ipfs_node" -path = "src/lib.rs" -crate-type = ["cdylib"] +[dependencies] +fce = { path = "../../fce" } diff --git a/examples/ipfs_node/src/errors.rs b/examples/ipfs_node/src/errors.rs new file mode 100644 index 00000000..53b8445d --- /dev/null +++ b/examples/ipfs_node/src/errors.rs @@ -0,0 +1,52 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use fce::FCEError; + +use std::io::{Error as IOError, IoSliceMut}; +use std::error::Error; + +#[derive(Debug)] +pub enum NodeError { + /// Various errors related to file io. + IOError(IOError), + + /// WIT doesn't contain such type. + WasmProcessError(FCEError), +} + +impl Error for NodeError {} + +impl std::fmt::Display for NodeError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { + match self { + NodeError::IOError(err) => write!(f, "{}", err), + NodeError::WasmProcessError(err) => write!(f, "{}", err), + } + } +} + +impl From for NodeError { + fn from(err: IOError) -> Self { + NodeError::IOError(err) + } +} + +impl From for NodeError { + fn from(err: FCEError) -> Self { + NodeError::WasmProcessError(err) + } +} diff --git a/examples/ipfs_node/src/lib.rs b/examples/ipfs_node/src/lib.rs index 5d5f6a05..e5fbb7b3 100644 --- a/examples/ipfs_node/src/lib.rs +++ b/examples/ipfs_node/src/lib.rs @@ -14,56 +14,62 @@ * limitations under the License. */ -#![allow(clippy::missing_safety_doc)] +mod node; +mod errors; -mod mem; -mod result; +use fce::IValue; +use fce::FCE; +use fce::FCEError; +use fce::FCEModuleConfig; +use fce::WasmProcess; -use crate::result::{RESULT_PTR, RESULT_SIZE}; +const IPFS_NODE: &str = + "/Users/mike/dev/work/fluence/wasm/fce/target/wasm32-unknown-unknown/release/ipfs_node_wit.wasm"; -#[no_mangle] -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); +const IPFS_RPC: &str = + "/Users/mike/dev/work/fluence/wasm/fce/target/wasm32-unknown-unknown/release/ipfs_rpc_wit.wasm"; - let msg = format!("from Wasm node: file content is {}\n", file_content); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); +fn main() { + let ipfs_node_bytes = std::fs::read(IPFS_NODE).unwrap(); + let ipfs_rpc_bytes = std::fs::read(IPFS_RPC).unwrap(); - let cmd = format!("put {}", file_content); - ipfs(cmd.as_ptr() as _, cmd.len() as _); + let mut fce = FCE::new(); + let config = FCEModuleConfig::default(); - let result = "Hello from IPFS node, take your hash".to_string(); + println!("loading ipfs node module"); + fce.load_module("node", &ipfs_node_bytes, config.clone()) + .expect("module successfully created"); - *RESULT_PTR.get_mut() = result.as_ptr() as _; - *RESULT_SIZE.get_mut() = result.len(); - std::mem::forget(result); + println!("loading ipfs rpc module"); + fce.load_module("rpc", &ipfs_rpc_bytes, config.clone()) + .expect("module successfully created"); + + let result = fce + .call("node_rpc", "invoke", &[IValue::String("aaaa".to_string())]) + .unwrap(); + + println!("execution result {:?}", result); } -#[no_mangle] -pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { - let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size); +/* +fn logger_log_utf8_string(ctx: &mut Ctx, offset: i32, size: i32) { + use wasmer_runtime_core::memory::ptr::{Array, WasmPtr}; - let msg = format!("from Wasm node: file content is {}\n", hash); - log_utf8_string(msg.as_ptr() as _, msg.len() as _); - - let cmd = format!("get {}", hash); - ipfs(cmd.as_ptr() as _, cmd.len() as _); - - let result = "Hello from IPFS node, take your file".to_string(); - - *RESULT_PTR.get_mut() = result.as_ptr() as _; - *RESULT_SIZE.get_mut() = result.len(); - std::mem::forget(result); + let wasm_ptr = WasmPtr::::new(offset as _); + match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) { + Some(msg) => print!("{}", msg), + None => print!("fce logger: incorrect UTF8 string's been supplied to logger"), + } } -#[link(wasm_import_module = "logger")] -extern "C" { - /// Writes a byte string of size bytes that starts from ptr to a logger. - fn log_utf8_string(ptr: i32, size: i32); -} -#[link(wasm_import_module = "host")] -extern "C" { - /// Put a file to ipfs, returns ipfs hash of the file. - fn ipfs(ptr: i32, size: i32); +fn ipfs_call(ctx: &mut Ctx, ptr: i32, size: i32) { + use wasmer_runtime_core::memory::ptr::{Array, WasmPtr}; + + let wasm_ptr = WasmPtr::::new(ptr as _); + match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) { + Some(msg) => println!("host ipfs_call: {}", msg), + None => println!("fce logger: incorrect UTF8 string's been supplied to logger"), + } } +*/ diff --git a/examples/ipfs_node/src/node.rs b/examples/ipfs_node/src/node.rs new file mode 100644 index 00000000..b585d3f3 --- /dev/null +++ b/examples/ipfs_node/src/node.rs @@ -0,0 +1,99 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use super::errors::NodeError; + +use fce::FCE; +use fce::WasmProcess; +use fce::NodeFunction; +use fce::IValue; +use fce::FCEModuleConfig; + +use std::fs; +use std::path::PathBuf; + +pub(crate) struct IpfsNode { + process: FCE, + // names of core modules that is loaded to FCE + module_names: Vec, +} + +pub struct NodeModule<'a> { + pub name: &'a str, + pub functions: Vec>, +} + +impl IpfsNode { + pub fn new(core_modules_dir: PathBuf, _config_file: PathBuf) -> Result { + let mut wasm_process = FCE::new(); + let mut module_names = Vec::new(); + let core_module_config = FCEModuleConfig::default(); + + for entry in fs::read_dir(core_modules_dir)? { + let path = entry?.path(); + if !path.is_dir() { + let module_name = path.file_name().unwrap(); + let module_name = module_name.to_os_string().into_string().unwrap(); + //.ok_or_else(|| Err(NodeError::IOError()))?; + + println!("module name is {}", module_name); + let module_bytes = fs::read(path.clone())?; + + wasm_process.load_module( + module_name.clone(), + &module_bytes, + core_module_config.clone(), + )?; + module_names.push(module_name); + } + } + + Ok(Self { + process: wasm_process, + module_names, + }) + } + + pub fn rpc_call(&mut self, wasm_rpc: &[u8]) -> Result, NodeError> { + let core_module_config = FCEModuleConfig::default(); + let rpc_module_name = "ipfs_rpc"; + + self.process + .load_module(rpc_module_name, wasm_rpc, core_module_config)?; + let call_result = self.process.call( + rpc_module_name, + "invoke", + &[IValue::String("test".to_string())], + )?; + self.process.unload_module(rpc_module_name)?; + + Ok(call_result) + } + + pub fn get_interface(&self) -> Vec { + let mut modules = Vec::with_capacity(self.module_names.len()); + + for module_name in self.module_names.iter() { + let functions = self.process.get_interface(module_name).unwrap(); + modules.push(NodeModule { + name: module_name, + functions, + }) + } + + modules + } +} diff --git a/examples/ipfs_node/wasm/ipfs_node/Cargo.toml b/examples/ipfs_node/wasm/ipfs_node/Cargo.toml new file mode 100644 index 00000000..11b12371 --- /dev/null +++ b/examples/ipfs_node/wasm/ipfs_node/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "wasm_ipfs_node" +version = "0.1.0" +authors = ["Fluence Labs"] +edition = "2018" + +[lib] +name = "wasm_ipfs_node" +path = "src/lib.rs" +crate-type = ["cdylib"] diff --git a/examples/ipfs_node/wasm/ipfs_node/src/lib.rs b/examples/ipfs_node/wasm/ipfs_node/src/lib.rs new file mode 100644 index 00000000..5d5f6a05 --- /dev/null +++ b/examples/ipfs_node/wasm/ipfs_node/src/lib.rs @@ -0,0 +1,69 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#![allow(clippy::missing_safety_doc)] + +mod mem; +mod result; + +use crate::result::{RESULT_PTR, RESULT_SIZE}; + +#[no_mangle] +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); + + let msg = format!("from Wasm node: file content is {}\n", file_content); + log_utf8_string(msg.as_ptr() as _, msg.len() as _); + + let cmd = format!("put {}", file_content); + ipfs(cmd.as_ptr() as _, cmd.len() as _); + + let result = "Hello from IPFS node, take your hash".to_string(); + + *RESULT_PTR.get_mut() = result.as_ptr() as _; + *RESULT_SIZE.get_mut() = result.len(); + std::mem::forget(result); +} + +#[no_mangle] +pub unsafe fn get(hash_ptr: *mut u8, hash_size: usize) { + let hash = String::from_raw_parts(hash_ptr, hash_size, hash_size); + + let msg = format!("from Wasm node: file content is {}\n", hash); + log_utf8_string(msg.as_ptr() as _, msg.len() as _); + + let cmd = format!("get {}", hash); + ipfs(cmd.as_ptr() as _, cmd.len() as _); + + let result = "Hello from IPFS node, take your file".to_string(); + + *RESULT_PTR.get_mut() = result.as_ptr() as _; + *RESULT_SIZE.get_mut() = result.len(); + std::mem::forget(result); +} + +#[link(wasm_import_module = "logger")] +extern "C" { + /// Writes a byte string of size bytes that starts from ptr to a logger. + fn log_utf8_string(ptr: i32, size: i32); +} + +#[link(wasm_import_module = "host")] +extern "C" { + /// Put a file to ipfs, returns ipfs hash of the file. + fn ipfs(ptr: i32, size: i32); +} diff --git a/examples/ipfs_node/src/mem.rs b/examples/ipfs_node/wasm/ipfs_node/src/mem.rs similarity index 100% rename from examples/ipfs_node/src/mem.rs rename to examples/ipfs_node/wasm/ipfs_node/src/mem.rs diff --git a/examples/ipfs_node/src/result.rs b/examples/ipfs_node/wasm/ipfs_node/src/result.rs similarity index 100% rename from examples/ipfs_node/src/result.rs rename to examples/ipfs_node/wasm/ipfs_node/src/result.rs diff --git a/examples/ipfs_node/wit b/examples/ipfs_node/wasm/ipfs_node/wit similarity index 100% rename from examples/ipfs_node/wit rename to examples/ipfs_node/wasm/ipfs_node/wit diff --git a/examples/ipfs_rpc/Cargo.toml b/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml similarity index 72% rename from examples/ipfs_rpc/Cargo.toml rename to examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml index f70c0215..37e2bc95 100644 --- a/examples/ipfs_rpc/Cargo.toml +++ b/examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "ipfs_rpc" +name = "wasm_ipfs_rpc" version = "0.1.0" authors = ["Fluence Labs"] edition = "2018" [lib] -name = "ipfs_rpc" +name = "wasm_ipfs_rpc" path = "src/lib.rs" crate-type = ["cdylib"] diff --git a/examples/ipfs_rpc/src/lib.rs b/examples/ipfs_node/wasm/ipfs_rpc/src/lib.rs similarity index 100% rename from examples/ipfs_rpc/src/lib.rs rename to examples/ipfs_node/wasm/ipfs_rpc/src/lib.rs diff --git a/examples/ipfs_rpc/src/mem.rs b/examples/ipfs_node/wasm/ipfs_rpc/src/mem.rs similarity index 100% rename from examples/ipfs_rpc/src/mem.rs rename to examples/ipfs_node/wasm/ipfs_rpc/src/mem.rs diff --git a/examples/ipfs_rpc/src/result.rs b/examples/ipfs_node/wasm/ipfs_rpc/src/result.rs similarity index 100% rename from examples/ipfs_rpc/src/result.rs rename to examples/ipfs_node/wasm/ipfs_rpc/src/result.rs diff --git a/examples/ipfs_rpc/wit b/examples/ipfs_node/wasm/ipfs_rpc/wit similarity index 100% rename from examples/ipfs_rpc/wit rename to examples/ipfs_node/wasm/ipfs_rpc/wit diff --git a/examples/export_test/Cargo.toml b/examples/simple_greeting/Cargo.toml similarity index 100% rename from examples/export_test/Cargo.toml rename to examples/simple_greeting/Cargo.toml diff --git a/examples/export_test/src/lib.rs b/examples/simple_greeting/src/lib.rs similarity index 100% rename from examples/export_test/src/lib.rs rename to examples/simple_greeting/src/lib.rs diff --git a/examples/export_test/src/mem.rs b/examples/simple_greeting/src/mem.rs similarity index 100% rename from examples/export_test/src/mem.rs rename to examples/simple_greeting/src/mem.rs diff --git a/examples/export_test/src/result.rs b/examples/simple_greeting/src/result.rs similarity index 100% rename from examples/export_test/src/result.rs rename to examples/simple_greeting/src/result.rs diff --git a/examples/export_test/wit b/examples/simple_greeting/wit similarity index 100% rename from examples/export_test/wit rename to examples/simple_greeting/wit diff --git a/fce/src/lib.rs b/fce/src/lib.rs new file mode 100644 index 00000000..32ce8d8a --- /dev/null +++ b/fce/src/lib.rs @@ -0,0 +1,30 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#![warn(rust_2018_idioms)] +#![feature(get_mut_unchecked)] +#![feature(new_uninit)] + +mod vm; +mod misc; +mod wasm_process; + +pub use vm::FCE; +pub use vm::FCEError; +pub use vm::FCEModuleConfig; +pub use vm::IValue; +pub use vm::IType; +pub use wasm_process::WasmProcess; +pub use wasm_process::NodeFunction; diff --git a/fce/src/main.rs b/fce/src/main.rs deleted file mode 100644 index eff6941d..00000000 --- a/fce/src/main.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020 Fluence Labs Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#![warn(rust_2018_idioms)] -#![feature(get_mut_unchecked)] -#![feature(new_uninit)] - -mod vm; -mod misc; - -use vm::IValue; -use vm::FCE; -use vm::FCEModuleConfig; -use vm::FCEService; - -const IPFS_NODE: &str = - "/Users/mike/dev/work/fluence/wasm/fce/target/wasm32-unknown-unknown/release/ipfs_node_wit.wasm"; - -const IPFS_RPC: &str = - "/Users/mike/dev/work/fluence/wasm/fce/target/wasm32-unknown-unknown/release/ipfs_rpc_wit.wasm"; - -fn main() { - let ipfs_node_bytes = std::fs::read(IPFS_NODE).unwrap(); - let ipfs_rpc_bytes = std::fs::read(IPFS_RPC).unwrap(); - - let mut fce = FCE::new(); - let config = FCEModuleConfig::default(); - - println!("loading ipfs node module"); - fce.register_module("node", &ipfs_node_bytes, config.clone()) - .expect("module successfully created"); - - println!("loading ipfs rpc module"); - fce.register_module("rpc", &ipfs_rpc_bytes, config.clone()) - .expect("module successfully created"); - - let result = fce - .call("node_rpc", "invoke", &[IValue::String("aaaa".to_string())]) - .unwrap(); - - println!("execution result {:?}", result); -} - -/* -fn logger_log_utf8_string(ctx: &mut Ctx, offset: i32, size: i32) { - use wasmer_runtime_core::memory::ptr::{Array, WasmPtr}; - - let wasm_ptr = WasmPtr::::new(offset as _); - match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) { - Some(msg) => print!("{}", msg), - None => print!("fce logger: incorrect UTF8 string's been supplied to logger"), - } -} - - -fn ipfs_call(ctx: &mut Ctx, ptr: i32, size: i32) { - use wasmer_runtime_core::memory::ptr::{Array, WasmPtr}; - - let wasm_ptr = WasmPtr::::new(ptr as _); - match wasm_ptr.get_utf8_string(ctx.memory(0), size as _) { - Some(msg) => println!("host ipfs_call: {}", msg), - None => println!("fce logger: incorrect UTF8 string's been supplied to logger"), - } -} -*/ diff --git a/fce/src/vm/errors.rs b/fce/src/vm/errors.rs index 34f3c3d7..0278dacb 100644 --- a/fce/src/vm/errors.rs +++ b/fce/src/vm/errors.rs @@ -145,6 +145,6 @@ impl From for FCEError { impl From<()> for FCEError { fn from(_err: ()) -> Self { - FCEError::IncorrectWIT(format!("failed to parse instructions for adapter type")) + FCEError::IncorrectWIT("failed to parse instructions for adapter type".to_string()) } } diff --git a/fce/src/vm/fce.rs b/fce/src/vm/fce.rs index 47f7f767..e24f9d2e 100644 --- a/fce/src/vm/fce.rs +++ b/fce/src/vm/fce.rs @@ -16,6 +16,8 @@ use super::instance::FCEModule; use super::*; +use crate::WasmProcess; +use crate::NodeFunction; use std::sync::Arc; use std::collections::hash_map::Entry; @@ -40,7 +42,7 @@ impl Default for FCE { } } -impl FCEService for FCE { +impl WasmProcess for FCE { fn call( &mut self, module_name: &str, @@ -56,7 +58,7 @@ impl FCEService for FCE { } } - fn register_module( + fn load_module( &mut self, module_name: S, wasm_bytes: &[u8], @@ -79,7 +81,7 @@ impl FCEService for FCE { } } - fn unregister_module(&mut self, module_name: &str) -> Result<(), FCEError> { + fn unload_module(&mut self, module_name: &str) -> Result<(), FCEError> { match self.modules.entry(module_name.to_string()) { Entry::Vacant(_) => Err(FCEError::NoSuchModule), @@ -89,4 +91,22 @@ impl FCEService for FCE { } } } + + fn get_interface(&self, module_name: &str) -> Result>, FCEError> { + match self.modules.get(module_name) { + Some(module) => { + let signatures = module + .as_ref() + .get_exports_signatures() + .map(|(name, inputs, outputs)| NodeFunction { + name, + inputs, + outputs, + }) + .collect::>(); + Ok(signatures) + } + None => Err(FCEError::NoSuchModule), + } + } } diff --git a/fce/src/vm/instance/fce_module.rs b/fce/src/vm/instance/fce_module.rs index 7aaf3e28..d7290ed7 100644 --- a/fce/src/vm/instance/fce_module.rs +++ b/fce/src/vm/instance/fce_module.rs @@ -110,6 +110,14 @@ impl FCEModule { } } + pub fn get_exports_signatures( + &self, + ) -> impl Iterator, &Vec)> { + self.exports_funcs + .iter() + .map(|(func_name, func)| (func_name, &func.inputs, &func.outputs)) + } + fn instantiate_wit_exports( wit: &FCEWITInterfaces<'_>, ) -> Result, FCEError> { diff --git a/fce/src/vm/mod.rs b/fce/src/vm/mod.rs index 17445a5e..b973c35d 100644 --- a/fce/src/vm/mod.rs +++ b/fce/src/vm/mod.rs @@ -16,13 +16,11 @@ mod fce; mod instance; -mod fce_service; mod config; mod prepare; mod errors; pub use fce::FCE; -pub use fce_service::FCEService; pub use config::FCEModuleConfig; pub use errors::FCEError; pub use instance::{IType, IValue}; diff --git a/fce/src/vm/fce_service.rs b/fce/src/wasm_process.rs similarity index 67% rename from fce/src/vm/fce_service.rs rename to fce/src/wasm_process.rs index 208cd1a3..583553d4 100644 --- a/fce/src/vm/fce_service.rs +++ b/fce/src/wasm_process.rs @@ -14,12 +14,19 @@ * limitations under the License. */ -use super::config::FCEModuleConfig; -use super::errors::FCEError; +use super::FCEModuleConfig; +use super::FCEError; use super::IValue; +use super::IType; -/// Describes a service behaviour in the Fluence network. -pub trait FCEService { +pub struct NodeFunction<'a> { + pub name: &'a str, + pub inputs: &'a Vec, + pub outputs: &'a Vec, +} + +/// Describes a run computation node behaviour in the Fluence network. +pub trait WasmProcess { /// Invokes a module supplying byte array and expecting byte array with some outcome back. fn call( &mut self, @@ -29,7 +36,8 @@ pub trait FCEService { ) -> Result, FCEError>; /// Registers new module in the FCE Service. - fn register_module( + /// TODO: + fn load_module( &mut self, module_name: S, wasm_bytes: &[u8], @@ -39,5 +47,8 @@ pub trait FCEService { S: Into; /// Unregisters previously registered module. - fn unregister_module(&mut self, module_name: &str) -> Result<(), FCEError>; + fn unload_module(&mut self, module_name: &str) -> Result<(), FCEError>; + + /// Returns signatures of all exported functions by this module. + fn get_interface(&self, module_name: &str) -> Result>, FCEError>; }