rename IPFSNode to FluenceFaaS; dir rearranges

This commit is contained in:
vms
2020-06-15 17:22:18 +03:00
parent f8580b3e82
commit b1e7eae29b
34 changed files with 187 additions and 328 deletions

31
Cargo.lock generated
View File

@ -370,7 +370,7 @@ dependencies = [
[[package]]
name = "fce"
version = "0.2.0"
version = "0.1.0"
dependencies = [
"fce_wit_interfaces",
"multimap",
@ -391,6 +391,21 @@ dependencies = [
"wasmer-interface-types",
]
[[package]]
name = "fluence-faas"
version = "0.1.0"
dependencies = [
"cmd_lib",
"fce",
"serde",
"serde_derive",
"serde_json",
"toml",
"wasmer-runtime",
"wasmer-runtime-core",
"wasmer-wasi",
]
[[package]]
name = "gcc"
version = "0.3.55"
@ -517,18 +532,10 @@ dependencies = [
]
[[package]]
name = "ipfs_node_service"
version = "0.2.0"
name = "ipfs_node"
version = "0.1.0"
dependencies = [
"cmd_lib",
"fce",
"serde",
"serde_derive",
"serde_json",
"toml",
"wasmer-runtime",
"wasmer-runtime-core",
"wasmer-wasi",
"fluence-faas",
]
[[package]]

View File

@ -2,11 +2,12 @@
members = [
"crates/fce_wit_interfaces",
"crates/wit_parser",
"engine",
"examples/ipfs_node",
"examples/ipfs_node/wasm/ipfs_node",
"examples/ipfs_node/wasm/ipfs_rpc",
"examples/simple_greeting",
"fce",
"fluence-faas",
"tools/wit_embedder",
]

View File

@ -1,6 +1,6 @@
[package]
name = "fce"
version = "0.2.0"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"

3
engine/README.md Normal file
View File

@ -0,0 +1,3 @@
# Fluence Compute Engine
FCE is intended to run various Wasm binaries. At now, it is in the heavily developing phase.

View File

@ -16,8 +16,6 @@
use super::module::FCEModule;
use super::*;
use crate::WasmProcess;
use crate::NodeFunction;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
@ -28,22 +26,23 @@ pub struct FCE {
modules: HashMap<String, FCEModule>,
}
/// Represent a function type inside FCE.
#[derive(Debug)]
pub struct FCEFunction<'a> {
pub name: &'a str,
pub inputs: &'a Vec<IType>,
pub outputs: &'a Vec<IType>,
}
impl FCE {
pub fn new() -> Self {
Self {
modules: HashMap::new(),
}
}
}
impl Default for FCE {
fn default() -> Self {
Self::new()
}
}
impl WasmProcess for FCE {
fn call(
/// Invoke a function of a module inside FCE by given function name with given arguments.
pub fn call(
&mut self,
module_name: &str,
func_name: &str,
@ -56,7 +55,8 @@ impl WasmProcess for FCE {
}
}
fn load_module<S>(
/// Load a new module inside FCE.
pub fn load_module<S>(
&mut self,
module_name: S,
wasm_bytes: &[u8],
@ -65,8 +65,7 @@ impl WasmProcess for FCE {
where
S: Into<String>,
{
let _prepared_wasm_bytes =
super::prepare::prepare_module(wasm_bytes, config.mem_pages_count)?;
let _prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.mem_pages_count)?;
let module = FCEModule::new(&wasm_bytes, config, &self.modules)?;
@ -79,7 +78,8 @@ impl WasmProcess for FCE {
}
}
fn unload_module(&mut self, module_name: &str) -> Result<(), FCEError> {
/// Unload previously loaded module.
pub fn unload_module(&mut self, module_name: &str) -> Result<(), FCEError> {
match self.modules.entry(module_name.to_string()) {
Entry::Vacant(_) => Err(FCEError::NoSuchModule),
@ -90,12 +90,13 @@ impl WasmProcess for FCE {
}
}
fn get_interface(&self, module_name: &str) -> Result<Vec<NodeFunction<'_>>, FCEError> {
/// Return signatures of all exported by this module functions.
pub fn get_interface(&self, module_name: &str) -> Result<Vec<FCEFunction<'_>>, FCEError> {
match self.modules.get(module_name) {
Some(module) => {
let signatures = module
.get_exports_signatures()
.map(|(name, inputs, outputs)| NodeFunction {
.map(|(name, inputs, outputs)| FCEFunction {
name,
inputs,
outputs,
@ -107,3 +108,9 @@ impl WasmProcess for FCE {
}
}
}
impl Default for FCE {
fn default() -> Self {
Self::new()
}
}

View File

@ -27,14 +27,15 @@
unreachable_patterns
)]
mod vm;
mod config;
mod engine;
mod errors;
mod module;
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;
pub use config::FCEModuleConfig;
pub use engine::FCE;
pub use engine::FCEFunction;
pub use errors::FCEError;
pub use module::IValue;
pub use module::IType;

View File

@ -14,6 +14,6 @@
* limitations under the License.
*/
mod slice_pretty_printer;
mod prepare;
pub use slice_pretty_printer::SlicePrettyPrinter;
pub(crate) use prepare::prepare_module;

View File

@ -18,7 +18,7 @@
// https://github.com/paritytech/substrate/blob/master/srml/contracts/src/wasm/prepare.rs
// https://github.com/nearprotocol/nearcore/blob/master/runtime/near-vm-runner/src/prepare.rs
use super::errors::FCEError;
use crate::FCEError;
use parity_wasm::{
builder, elements,
@ -73,7 +73,7 @@ impl<'a> ModuleBootstrapper {
/// Prepares a Wasm module:
/// - set memory page count
pub fn prepare_module(module: &[u8], mem_pages_count: u32) -> Result<Vec<u8>, FCEError> {
pub(crate) fn prepare_module(module: &[u8], mem_pages_count: u32) -> Result<Vec<u8>, FCEError> {
ModuleBootstrapper::init(module)?
.set_mem_pages_count(mem_pages_count)
.into_wasm()

View File

@ -61,7 +61,7 @@ impl Callable {
}
}
pub struct FCEModule {
pub(crate) struct FCEModule {
// wasmer_instance is needed because WITInstance contains dynamic functions
// that internally keep pointer to Wasmer instance.
#[allow(unused)]
@ -82,7 +82,7 @@ pub struct FCEModule {
}
impl FCEModule {
pub fn new(
pub(crate) fn new(
wasm_bytes: &[u8],
fce_module_config: FCEModuleConfig,
modules: &HashMap<String, FCEModule>,
@ -130,7 +130,11 @@ impl FCEModule {
})
}
pub fn call(&mut self, function_name: &str, args: &[IValue]) -> Result<Vec<IValue>, FCEError> {
pub(crate) fn call(
&mut self,
function_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, FCEError> {
match self.exports_funcs.get_mut(function_name) {
Some(func) => Arc::make_mut(func).call(args),
None => Err(FCEError::NoSuchFunction(format!(
@ -140,7 +144,7 @@ impl FCEModule {
}
}
pub fn get_exports_signatures(
pub(crate) fn get_exports_signatures(
&self,
) -> impl Iterator<Item = (&String, &Vec<IType>, &Vec<IType>)> {
self.exports_funcs.iter().map(|(func_name, func)| {

View File

@ -32,7 +32,7 @@ pub(self) use wasmer_core::types::Value as WValue;
pub(self) mod wit_prelude {
pub(super) use super::wit_instance::WITInstance;
pub(super) use super::exports::WITExport;
pub(super) use crate::vm::FCEError;
pub(super) use crate::FCEError;
pub(super) use super::wit_function::WITFunction;
pub(super) use super::memory::WITMemoryView;
pub(super) use super::memory::WITMemory;

View File

@ -17,7 +17,7 @@
use super::wit_prelude::FCEError;
use super::fce_module::FCEModule;
use super::{IType, IValue, WValue};
use crate::vm::module::fce_module::Callable;
use super::fce_module::Callable;
use wasmer_wit::interpreter::wasm;
use wasmer_core::instance::DynFunc;

View File

@ -1,18 +1,8 @@
[package]
name = "ipfs_node_service"
version = "0.2.0"
name = "ipfs_node"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
[dependencies]
fce = { path = "../../fce" }
wasmer-core = { package = "wasmer-runtime-core", version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
wasmer-runtime = "0.17.0"
wasmer-wasi = "0.17.0"
toml = "0.5.6"
serde = { version = "1.0.111", features = ["derive"] }
serde_json = "1.0.53"
serde_derive = "1.0.111"
cmd_lib = "0.7.8"
fluence-faas = { path = "../../fluence-faas" }

View File

@ -14,16 +14,8 @@
* limitations under the License.
*/
mod node;
mod node_wasm_service;
pub use node::IpfsNode;
pub use node::NodeError;
pub use node::NodePublicInterface;
pub use node::NodeModulePublicInterface;
pub use node_wasm_service::NodeWasmService;
use fce::IValue;
use fluence_faas::FluenceFaaS;
use fluence_faas::IValue;
use std::path::PathBuf;
@ -37,7 +29,7 @@ const IPFS_RPC: &str = "/Users/mike/dev/work/fluence/wasm/fce/bin/wasm_ipfs_rpc_
fn main() {
let ipfs_rpc = std::fs::read(IPFS_RPC).unwrap();
let mut ipfs_node = IpfsNode::new(
let mut ipfs_node = FluenceFaaS::new(
PathBuf::from(IPFS_MODULES_DIR),
PathBuf::from(IPFS_MODULES_CONFIG_PATH),
)
@ -46,13 +38,13 @@ fn main() {
println!("ipfs node interface is\n{}", ipfs_node.get_interface());
let node_addresses = ipfs_node
.core_call("ipfs_node.wasm", "get_addresses", &[])
.call_module("ipfs_node.wasm", "get_addresses", &[])
.unwrap();
println!("ipfs node addresses are:\n{:?}", node_addresses);
let result = ipfs_node
.rpc_call(&ipfs_rpc, "put", &[IValue::String("asdasdasd".to_string())])
.call_code(&ipfs_rpc, "put", &[IValue::String("asdasdasd".to_string())])
.unwrap();
println!("execution result {:?}", result);

View File

@ -1,27 +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.
*/
mod config;
mod errors;
mod imports;
mod ipfs_node;
mod node_public_interface;
mod utils;
pub use ipfs_node::IpfsNode;
pub use errors::NodeError;
pub use node_public_interface::NodePublicInterface;
pub use node_public_interface::NodeModulePublicInterface;

View File

@ -1,38 +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.
*/
use crate::NodeError;
use crate::NodePublicInterface;
use fce::IValue;
pub trait NodeWasmService {
fn rpc_call(
&mut self,
wasm_rpc: &[u8],
func_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, NodeError>;
fn core_call(
&mut self,
module_name: &str,
func_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, NodeError>;
fn get_interface(&self) -> NodePublicInterface;
}

View File

@ -1,37 +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.
*/
pub struct SlicePrettyPrinter<'a>(pub &'a [u8]);
impl<'a> std::fmt::LowerHex for SlicePrettyPrinter<'a> {
fn fmt(&self, fmtr: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
fmtr.write_fmt(format_args!("0x"))?;
for byte in self.0 {
fmtr.write_fmt(format_args!("{:02x}", byte))?;
}
Ok(())
}
}
impl<'a> std::fmt::UpperHex for SlicePrettyPrinter<'a> {
fn fmt(&self, fmtr: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
fmtr.write_fmt(format_args!("0x"))?;
for byte in self.0 {
fmtr.write_fmt(format_args!("{:02X}", byte))?;
}
Ok(())
}
}

View File

@ -1,26 +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.
*/
mod fce;
mod module;
mod config;
mod prepare;
mod errors;
pub use fce::FCE;
pub use config::FCEModuleConfig;
pub use errors::FCEError;
pub use module::{IType, IValue};

View File

@ -1,55 +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.
*/
use super::FCEModuleConfig;
use super::FCEError;
use super::IValue;
use super::IType;
/// Represent a function type inside wasm process.
#[derive(Debug)]
pub struct NodeFunction<'a> {
pub name: &'a str,
pub inputs: &'a Vec<IType>,
pub outputs: &'a Vec<IType>,
}
/// Describe a computation node behaviour in the Fluence network.
pub trait WasmProcess {
/// Invoke a function by given function name with given arguments of a module inside wasm process.
fn call(
&mut self,
module_name: &str,
function_name: &str,
arguments: &[IValue],
) -> Result<Vec<IValue>, FCEError>;
/// Load a new module inside wasm process.
fn load_module<S>(
&mut self,
module_name: S,
wasm_bytes: &[u8],
config: FCEModuleConfig,
) -> Result<(), FCEError>
where
S: Into<String>;
/// Unload previously loaded module.
fn unload_module(&mut self, module_name: &str) -> Result<(), FCEError>;
/// Return signatures of all exported by this module functions.
fn get_interface(&self, module_name: &str) -> Result<Vec<NodeFunction<'_>>, FCEError>;
}

18
fluence-faas/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "fluence-faas"
version = "0.1.0"
authors = ["Fluence Labs"]
edition = "2018"
[dependencies]
fce = { path = "../engine" }
wasmer-core = { package = "wasmer-runtime-core", version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
wasmer-runtime = "0.17.0"
wasmer-wasi = "0.17.0"
toml = "0.5.6"
serde = { version = "1.0.111", features = ["derive"] }
serde_json = "1.0.53"
serde_derive = "1.0.111"
cmd_lib = "0.7.8"

3
fluence-faas/README.md Normal file
View File

@ -0,0 +1,3 @@
# Fluence FaaS
Fluence FaaS is intended to run various Wasm binaries. At now, it is in the heavily developing phase.

View File

@ -20,7 +20,7 @@ use std::io::Error as IOError;
use std::error::Error;
#[derive(Debug)]
pub enum NodeError {
pub enum FaaSError {
/// An error related to config parsing.
ConfigParseError(String),
@ -28,29 +28,29 @@ pub enum NodeError {
IOError(String),
/// WIT doesn't contain such type.
WasmProcessError(FCEError),
EngineError(FCEError),
}
impl Error for NodeError {}
impl Error for FaaSError {}
impl std::fmt::Display for NodeError {
impl std::fmt::Display for FaaSError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
NodeError::ConfigParseError(err_msg) => write!(f, "{}", err_msg),
NodeError::IOError(err_msg) => write!(f, "{}", err_msg),
NodeError::WasmProcessError(err) => write!(f, "{}", err),
FaaSError::ConfigParseError(err_msg) => write!(f, "{}", err_msg),
FaaSError::IOError(err_msg) => write!(f, "{}", err_msg),
FaaSError::EngineError(err) => write!(f, "{}", err),
}
}
}
impl From<IOError> for NodeError {
impl From<IOError> for FaaSError {
fn from(err: IOError) -> Self {
NodeError::IOError(format!("{}", err))
FaaSError::IOError(format!("{}", err))
}
}
impl From<FCEError> for NodeError {
impl From<FCEError> for FaaSError {
fn from(err: FCEError) -> Self {
NodeError::WasmProcessError(err)
FaaSError::EngineError(err)
}
}

View File

@ -14,34 +14,32 @@
* limitations under the License.
*/
use super::errors::NodeError;
use super::node_public_interface::NodePublicInterface;
use super::node_public_interface::NodeModulePublicInterface;
use super::FaaSError;
use super::faas_interface::FaaSInterface;
use super::faas_interface::FaaSModuleInterface;
use fce::FCE;
use fce::WasmProcess;
use fce::IValue;
use super::IValue;
use fce::FCEModuleConfig;
use std::fs;
use std::path::PathBuf;
pub struct IpfsNode {
pub struct FluenceFaaS {
process: FCE,
// names of core modules that is loaded to FCE
// names of core modules loaded to FCE
module_names: Vec<String>,
rpc_module_config: FCEModuleConfig,
faas_code_config: FCEModuleConfig,
}
impl IpfsNode {
impl FluenceFaaS {
pub fn new<P: Into<PathBuf>>(
core_modules_dir: P,
config_file_path: P,
) -> Result<Self, NodeError> {
) -> Result<Self, FaaSError> {
let mut wasm_process = FCE::new();
let mut module_names = Vec::new();
let mut core_modules_config =
super::config::parse_config_from_file(config_file_path.into())?;
let mut core_modules_config = crate::misc::parse_config_from_file(config_file_path.into())?;
for entry in fs::read_dir(core_modules_dir.into())? {
let path = entry?.path();
@ -54,11 +52,11 @@ impl IpfsNode {
let module_name = module_name
.to_os_string()
.into_string()
.map_err(|e| NodeError::IOError(format!("failed to read from {:?} file", e)))?;
.map_err(|e| FaaSError::IOError(format!("failed to read from {:?} file", e)))?;
let module_bytes = fs::read(path.clone())?;
let core_module_config = super::utils::make_wasm_process_config(
let core_module_config = crate::misc::make_wasm_process_config(
core_modules_config.modules_config.remove(&module_name),
)?;
wasm_process.load_module(module_name.clone(), &module_bytes, core_module_config)?;
@ -66,27 +64,25 @@ impl IpfsNode {
}
let rpc_module_config =
super::utils::make_wasm_process_config(core_modules_config.rpc_module_config)?;
crate::misc::make_wasm_process_config(core_modules_config.rpc_module_config)?;
Ok(Self {
process: wasm_process,
module_names,
rpc_module_config,
faas_code_config: rpc_module_config,
})
}
}
impl crate::node_wasm_service::NodeWasmService for IpfsNode {
fn rpc_call(
pub fn call_code(
&mut self,
wasm_rpc: &[u8],
func_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, NodeError> {
) -> Result<Vec<IValue>, FaaSError> {
let rpc_module_name = "ipfs_rpc";
self.process
.load_module(rpc_module_name, wasm_rpc, self.rpc_module_config.clone())?;
.load_module(rpc_module_name, wasm_rpc, self.faas_code_config.clone())?;
let call_result = self.process.call(rpc_module_name, func_name, args)?;
self.process.unload_module(rpc_module_name)?;
@ -94,28 +90,28 @@ impl crate::node_wasm_service::NodeWasmService for IpfsNode {
Ok(call_result)
}
fn core_call(
pub fn call_module(
&mut self,
module_name: &str,
func_name: &str,
args: &[IValue],
) -> Result<Vec<IValue>, NodeError> {
) -> Result<Vec<IValue>, FaaSError> {
self.process
.call(module_name, func_name, args)
.map_err(Into::into)
}
fn get_interface(&self) -> NodePublicInterface {
pub fn get_interface(&self) -> FaaSInterface {
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(NodeModulePublicInterface {
modules.push(FaaSModuleInterface {
name: module_name,
functions,
})
}
NodePublicInterface { modules }
FaaSInterface { modules }
}
}

View File

@ -17,17 +17,17 @@
use std::fmt;
#[derive(Debug)]
pub struct NodePublicInterface<'a> {
pub modules: Vec<NodeModulePublicInterface<'a>>,
pub struct FaaSInterface<'a> {
pub modules: Vec<FaaSModuleInterface<'a>>,
}
#[derive(Debug)]
pub struct NodeModulePublicInterface<'a> {
pub struct FaaSModuleInterface<'a> {
pub name: &'a str,
pub functions: Vec<fce::NodeFunction<'a>>,
pub functions: Vec<fce::FCEFunction<'a>>,
}
impl<'a> fmt::Display for NodePublicInterface<'a> {
impl<'a> fmt::Display for FaaSInterface<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for module in self.modules.iter() {
write!(f, "{}", module)?;
@ -37,7 +37,7 @@ impl<'a> fmt::Display for NodePublicInterface<'a> {
}
}
impl<'a> fmt::Display for NodeModulePublicInterface<'a> {
impl<'a> fmt::Display for FaaSModuleInterface<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "{}", self.name)?;

View File

@ -14,13 +14,15 @@
* limitations under the License.
*/
mod node;
mod node_wasm_service;
mod errors;
mod faas;
mod faas_interface;
mod misc;
pub use fce::IValue;
pub use fce::IType;
pub use node::IpfsNode;
pub use node::NodeError;
pub use node::NodePublicInterface;
pub use node::NodeModulePublicInterface;
pub use node_wasm_service::NodeWasmService;
pub use errors::FaaSError;
pub use faas::FluenceFaaS;
pub use faas_interface::FaaSInterface;
pub use faas_interface::FaaSModuleInterface;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
use super::errors::NodeError;
use crate::FaaSError;
use serde_derive::Deserialize;
use toml::from_slice;
@ -22,20 +22,30 @@ use toml::from_slice;
use std::collections::HashMap;
/*
An example of a config:
An example of the config:
[ipfs_node]
mem_pages_count_count = 100
[[core_module]]
name = "ipfs_node.wasm"
mem_pages_count = 100
logger_enabled = true
[imports]
ipfs = "/usr/bin/ipfs"
[core_module.imports]
mysql = "/usr/bin/mysql"
ipfs = "/usr/local/bin/ipfs"
[wasi]
preopened_files = ["/tmp/file1"]
[mapped_dirs]
tmp = "/tmp"
[core_module.wasi]
envs = []
preopened_files = ["/Users/user/tmp/"]
mapped_dirs = { "tmp" = "/Users/user/tmp" }
[rpc_module]
mem_pages_count = 100
logger_enabled = true
[rpc_module.wasi]
envs = []
preopened_files = ["/Users/user/tmp"]
mapped_dirs = { "tmp" = "/Users/user/tmp" }
*/
#[derive(Deserialize, Debug)]
@ -90,10 +100,10 @@ pub(crate) struct WASIConfig {
pub(crate) fn parse_config_from_file(
config_file_path: std::path::PathBuf,
) -> Result<NodeConfig, NodeError> {
) -> Result<NodeConfig, FaaSError> {
let file_content = std::fs::read(config_file_path)?;
let config: RawCoreModulesConfig =
from_slice(&file_content).map_err(|err| NodeError::ConfigParseError(format!("{}", err)))?;
from_slice(&file_content).map_err(|err| FaaSError::ConfigParseError(format!("{}", err)))?;
let modules_config = config
.core_module

View File

@ -67,6 +67,8 @@ where
let func = move |ctx: &mut Ctx, inputs: &[Value]| -> Vec<Value> {
use wasmer_core::memory::ptr::{Array, WasmPtr};
// this closure is linked to import function that have (i32, i32) -> i32 type -
// it is safe to access input slice without its size checking
let array_ptr = inputs[0].to_u128() as i32;
let array_size = inputs[1].to_u128() as i32;
@ -77,9 +79,9 @@ where
};
unsafe {
init_wasm_func_once!(allocate_func, ctx, i32, i32, ALLOCATE_FUNC_NAME, 4);
init_wasm_func_once!(set_result_ptr_func, ctx, i32, (), SET_PTR_FUNC_NAME, 5);
init_wasm_func_once!(set_result_size_func, ctx, i32, (), SET_SIZE_FUNC_NAME, 6);
init_wasm_func_once!(allocate_func, ctx, i32, i32, ALLOCATE_FUNC_NAME, 2);
init_wasm_func_once!(set_result_ptr_func, ctx, i32, (), SET_PTR_FUNC_NAME, 3);
init_wasm_func_once!(set_result_size_func, ctx, i32, (), SET_SIZE_FUNC_NAME, 4);
let mem_address = call_wasm_func!(allocate_func, result.len() as i32);
write_to_mem(ctx, mem_address as usize, result.as_bytes());

View File

@ -0,0 +1,6 @@
mod imports;
mod utils;
mod config;
pub(crate) use utils::make_wasm_process_config;
pub(crate) use config::parse_config_from_file;

View File

@ -15,7 +15,7 @@
*/
use wasmer_core::vm::Ctx;
use super::errors::NodeError;
use crate::FaaSError;
use super::config::ModuleConfig;
use fce::FCEModuleConfig;
@ -33,7 +33,7 @@ use std::path::PathBuf;
// based on Wasmer: https://github.com/wasmerio/wasmer/blob/081f6250e69b98b9f95a8f62ad6d8386534f3279/lib/runtime-core/src/instance.rs#L863
/// Extract export function from Wasmer instance by name.
pub(super) unsafe fn get_export_func_by_name<'a, Args, Rets>(
pub(crate) unsafe fn get_export_func_by_name<'a, Args, Rets>(
ctx: &'a mut Ctx,
name: &str,
) -> Result<Func<'a, Args, Rets>, ResolveError>
@ -103,9 +103,9 @@ where
}
/// Make FCE config based on parsed raw config.
pub(super) fn make_wasm_process_config(
pub(crate) fn make_wasm_process_config(
config: Option<ModuleConfig>,
) -> Result<FCEModuleConfig, NodeError> {
) -> Result<FCEModuleConfig, FaaSError> {
use super::imports::create_host_import_func;
use super::imports::log_utf8_string;
use wasmer_core::import::Namespace;