From 9da7cc09576fb06b8245f0197935cb71db69de28 Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 12 Jun 2020 01:59:50 +0300 Subject: [PATCH] introduce NodeWasmService trait --- Cargo.lock | 4 +-- examples/ipfs_node/Cargo.toml | 4 +-- examples/ipfs_node/src/lib.rs | 8 +++-- examples/ipfs_node/src/main.rs | 8 ++++- .../src/node/{node.rs => ipfs_node.rs} | 8 +++-- examples/ipfs_node/src/node/mod.rs | 4 +-- examples/ipfs_node/src/node_wasm_service.rs | 31 +++++++++++++++++++ 7 files changed, 55 insertions(+), 12 deletions(-) rename examples/ipfs_node/src/node/{node.rs => ipfs_node.rs} (94%) create mode 100644 examples/ipfs_node/src/node_wasm_service.rs diff --git a/Cargo.lock b/Cargo.lock index 8a8685d3..a480a068 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,8 +517,8 @@ dependencies = [ ] [[package]] -name = "ipfs_node" -version = "0.1.0" +name = "ipfs_node_service" +version = "0.2.0" dependencies = [ "cmd_lib", "fce", diff --git a/examples/ipfs_node/Cargo.toml b/examples/ipfs_node/Cargo.toml index e7715903..9a87a776 100644 --- a/examples/ipfs_node/Cargo.toml +++ b/examples/ipfs_node/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "ipfs_node" -version = "0.1.0" +name = "ipfs_node_service" +version = "0.2.0" authors = ["Fluence Labs"] edition = "2018" diff --git a/examples/ipfs_node/src/lib.rs b/examples/ipfs_node/src/lib.rs index 3af6831c..2c262c5b 100644 --- a/examples/ipfs_node/src/lib.rs +++ b/examples/ipfs_node/src/lib.rs @@ -13,10 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#![feature(pattern)] mod node; +mod node_wasm_service; pub use fce::IValue; -pub use node::*; +pub use node::IpfsNode; +pub use node::NodeError; +pub use node::NodePublicInterface; +pub use node::NodeModulePublicInterface; +pub use node_wasm_service::NodeWasmService; diff --git a/examples/ipfs_node/src/main.rs b/examples/ipfs_node/src/main.rs index 009ad510..533f0f75 100644 --- a/examples/ipfs_node/src/main.rs +++ b/examples/ipfs_node/src/main.rs @@ -15,9 +15,15 @@ */ 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 node::IpfsNode; use std::path::PathBuf; diff --git a/examples/ipfs_node/src/node/node.rs b/examples/ipfs_node/src/node/ipfs_node.rs similarity index 94% rename from examples/ipfs_node/src/node/node.rs rename to examples/ipfs_node/src/node/ipfs_node.rs index b5d968de..86da79ce 100644 --- a/examples/ipfs_node/src/node/node.rs +++ b/examples/ipfs_node/src/node/ipfs_node.rs @@ -46,7 +46,7 @@ impl IpfsNode { for entry in fs::read_dir(core_modules_dir.into())? { let path = entry?.path(); if path.is_dir() { - // just pass directories + // just skip directories continue; } @@ -74,8 +74,10 @@ impl IpfsNode { rpc_module_config, }) } +} - pub fn rpc_call( +impl crate::node_wasm_service::NodeWasmService for IpfsNode { + fn rpc_call( &mut self, wasm_rpc: &[u8], func_name: &str, @@ -92,7 +94,7 @@ impl IpfsNode { Ok(call_result) } - pub fn get_interface(&self) -> NodePublicInterface { + fn get_interface(&self) -> NodePublicInterface { let mut modules = Vec::with_capacity(self.module_names.len()); for module_name in self.module_names.iter() { diff --git a/examples/ipfs_node/src/node/mod.rs b/examples/ipfs_node/src/node/mod.rs index f7cb11b2..a624f79c 100644 --- a/examples/ipfs_node/src/node/mod.rs +++ b/examples/ipfs_node/src/node/mod.rs @@ -17,11 +17,11 @@ mod config; mod errors; mod imports; -mod node; +mod ipfs_node; mod node_public_interface; mod utils; -pub use node::IpfsNode; +pub use ipfs_node::IpfsNode; pub use errors::NodeError; pub use node_public_interface::NodePublicInterface; pub use node_public_interface::NodeModulePublicInterface; diff --git a/examples/ipfs_node/src/node_wasm_service.rs b/examples/ipfs_node/src/node_wasm_service.rs new file mode 100644 index 00000000..e5dc1bcf --- /dev/null +++ b/examples/ipfs_node/src/node_wasm_service.rs @@ -0,0 +1,31 @@ +/* + * 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, NodeError>; + + fn get_interface(&self) -> NodePublicInterface; +}