From f767597d01bcb94a857b0072654a676863547188 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sun, 27 Oct 2019 22:36:37 +0100 Subject: [PATCH] wip elois --- bin/dunitrust-server/src/main.rs | 2 +- lib/modules/gva/src/context.rs | 18 +++++++++++------- lib/modules/gva/src/lib.rs | 9 ++++----- lib/modules/gva/src/schema.rs | 1 - lib/modules/gva/src/webserver.rs | 7 ++----- lib/modules/ws2p-v1-legacy/src/lib.rs | 2 ++ 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/bin/dunitrust-server/src/main.rs b/bin/dunitrust-server/src/main.rs index 5fac4425..00c91cef 100644 --- a/bin/dunitrust-server/src/main.rs +++ b/bin/dunitrust-server/src/main.rs @@ -63,7 +63,7 @@ macro_rules! durs_cli_main { #[cfg(not(target_arch = "arm"))] fn main() { durs_cli_main!(durs_plug!( - [WS2PModule], + [WS2Pv1Module, WS2PModule], [TuiModule, GvaModule /*, SkeletonModule ,DasaModule*/] )) } diff --git a/lib/modules/gva/src/context.rs b/lib/modules/gva/src/context.rs index 5b96d091..29955f75 100644 --- a/lib/modules/gva/src/context.rs +++ b/lib/modules/gva/src/context.rs @@ -36,14 +36,18 @@ impl Context { } } -pub unsafe fn init(db: BcDbRo) { - CONTEXT.replace(Context::new(db)); +pub fn init(db: BcDbRo) { + unsafe { + CONTEXT.replace(Context::new(db)); + } } -pub unsafe fn get_context() -> &'static Context { - if let Some(ref context) = CONTEXT { - context - } else { - fatal_error!("GVA: no context"); +pub fn get_context() -> &'static Context { + unsafe { + if let Some(ref context) = CONTEXT { + context + } else { + fatal_error!("GVA: no context"); + } } } diff --git a/lib/modules/gva/src/lib.rs b/lib/modules/gva/src/lib.rs index 9d0fe4ec..5798b72e 100644 --- a/lib/modules/gva/src/lib.rs +++ b/lib/modules/gva/src/lib.rs @@ -13,8 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. - -/// Gva Module +//! Gva Module #![deny( missing_docs, @@ -54,7 +53,7 @@ use std::sync::mpsc; use std::thread; use std::time::{Duration, SystemTime}; -pub static MODULE_NAME: &str = "gva"; +static MODULE_NAME: &str = "gva"; #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] /// Gva Module Configuration @@ -176,7 +175,7 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { Some(new_gva_conf) } fn start( - _soft_meta_datas: &SoftwareMetaDatas<DuRsConf>, + soft_meta_datas: &SoftwareMetaDatas<DuRsConf>, _keys: RequiredKeysContent, _conf: Self::ModuleConf, router_sender: mpsc::Sender<RouterThreadMessage<DursMsg>>, @@ -247,7 +246,7 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { } }); - let smd: SoftwareMetaDatas<DuRsConf> = _soft_meta_datas.clone(); + let smd: SoftwareMetaDatas<DuRsConf> = soft_meta_datas.clone(); thread::spawn(move || { let _ = webserver::start_web_server(&smd); }); diff --git a/lib/modules/gva/src/schema.rs b/lib/modules/gva/src/schema.rs index d1ac802b..22165dcf 100644 --- a/lib/modules/gva/src/schema.rs +++ b/lib/modules/gva/src/schema.rs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. - use crate::context::Context; use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::traits::Document; diff --git a/lib/modules/gva/src/webserver.rs b/lib/modules/gva/src/webserver.rs index 327c8b9e..81f84b1b 100644 --- a/lib/modules/gva/src/webserver.rs +++ b/lib/modules/gva/src/webserver.rs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. - use crate::context; use crate::schema::*; use actix_web::{middleware, web, App, Error, HttpResponse, HttpServer}; @@ -38,7 +37,7 @@ fn graphql( st: web::Data<Arc<Schema>>, data: web::Json<GraphQLRequest>, ) -> impl Future<Item = HttpResponse, Error = Error> { - let context = unsafe { crate::context::get_context() }; + let context = crate::context::get_context(); web::block(move || { let res = data.execute(&st, context); Ok::<_, serde_json::error::Error>(serde_json::to_string(&res)?) @@ -61,9 +60,7 @@ pub fn start_web_server(_soft_meta_datas: &SoftwareMetaDatas<DuRsConf>) -> std:: // Instanciate the context let db_path = durs_conf::get_blockchain_db_path(_soft_meta_datas.profile_path.clone()); if let Ok(db) = durs_bc_db_reader::open_db_ro(&std::path::Path::new(&db_path)) { - unsafe { - context::init(db); - } + context::init(db); } else { fatal_error!("GVA: fail to open DB."); }; diff --git a/lib/modules/ws2p-v1-legacy/src/lib.rs b/lib/modules/ws2p-v1-legacy/src/lib.rs index 055465eb..3da15c08 100644 --- a/lib/modules/ws2p-v1-legacy/src/lib.rs +++ b/lib/modules/ws2p-v1-legacy/src/lib.rs @@ -505,6 +505,8 @@ impl DursModule<DuRsConf, DursMsg> for WS2Pv1Module { // Get start time let start_time = SystemTime::now(); + info!("Start WS2P1 Module."); + // Get key_pair let key_pair = if let RequiredKeysContent::NetworkKeyPair(key_pair) = keys { key_pair -- GitLab