Skip to content
Snippets Groups Projects
Commit 76d96cb2 authored by Éloïs's avatar Éloïs
Browse files

[ref] gva: remove unused code

parent e85d2552
No related branches found
No related tags found
1 merge request!226Resolve "GVA: create skeleton & implement current Block request"
...@@ -62,7 +62,6 @@ use durs_module::{ ...@@ -62,7 +62,6 @@ use durs_module::{
ModuleStaticName, RequiredKeys, RequiredKeysContent, RouterThreadMessage, SoftwareMetaDatas, ModuleStaticName, RequiredKeys, RequiredKeysContent, RouterThreadMessage, SoftwareMetaDatas,
}; };
//use durs_module::*;
use durs_network::events::NetworkEvent; use durs_network::events::NetworkEvent;
use durs_network_documents::host::Host; use durs_network_documents::host::Host;
...@@ -114,19 +113,6 @@ impl Merge for GvaUserConf { ...@@ -114,19 +113,6 @@ impl Merge for GvaUserConf {
} }
} }
#[derive(Debug, Copy, Clone)]
/// Message from others thread of gva module
pub enum GvaThreadMsg {}
#[derive(Debug, Clone)]
/// Format of messages received by the gva module
pub enum GvaMsg {
/// Message from another module
DursMsg(Box<DursMsg>),
/// Message from others thread of gva module
GvaThreadMsg(GvaThreadMsg),
}
#[derive(StructOpt, Debug, Clone)] #[derive(StructOpt, Debug, Clone)]
#[structopt(name = "gva", setting(structopt::clap::AppSettings::ColoredHelp))] #[structopt(name = "gva", setting(structopt::clap::AppSettings::ColoredHelp))]
/// Gva subcommand options /// Gva subcommand options
...@@ -139,14 +125,9 @@ pub struct GvaOpt { ...@@ -139,14 +125,9 @@ pub struct GvaOpt {
pub port: Option<u16>, pub port: Option<u16>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Copy, Clone)]
/// Data that the Gva module needs to cache /// Data that the Gva module needs to cache
pub struct GvaModuleDatas { pub struct GvaModuleDatas {}
/// Sender of all child threads (except the proxy thread)
pub child_threads: Vec<mpsc::Sender<GvaMsg>>,
/// Any data
pub field: usize,
}
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
/// Gva module /// Gva module
...@@ -228,72 +209,31 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { ...@@ -228,72 +209,31 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
let host = Host::parse(&conf.host).map_err(|_| GvaError::InvalidHost)?; let host = Host::parse(&conf.host).map_err(|_| GvaError::InvalidHost)?;
// Instanciate Gva module datas // Instanciate Gva module datas
let datas = GvaModuleDatas { let _datas = GvaModuleDatas {};
child_threads: Vec::new(),
field: 3,
};
// Create gva main thread channel // Create gva main thread channel
let (gva_sender, gva_receiver): (mpsc::Sender<GvaMsg>, mpsc::Receiver<GvaMsg>) = let (gva_sender, gva_receiver): (mpsc::Sender<DursMsg>, mpsc::Receiver<DursMsg>) =
mpsc::channel(); mpsc::channel();
// Create proxy channel
let (proxy_sender, proxy_receiver): (mpsc::Sender<DursMsg>, mpsc::Receiver<DursMsg>) =
mpsc::channel();
// Launch a proxy thread that transform DursMsgContent() to GvaMsg::DursMsgContent(DursMsgContent())
let router_sender_clone = router_sender.clone();
let gva_sender_clone = gva_sender.clone();
thread::spawn(move || {
// Send gva module registration to router thread // Send gva module registration to router thread
router_sender_clone router_sender
.send(RouterThreadMessage::ModuleRegistration { .send(RouterThreadMessage::ModuleRegistration {
static_name: ModuleStaticName(MODULE_NAME), static_name: ModuleStaticName(MODULE_NAME),
sender: proxy_sender, // Messages sent by the router will be received by your proxy thread sender: gva_sender, // Messages sent by the router will be received by your proxy thread
roles: vec![ModuleRole::UserInterface], // Roles assigned to your module roles: vec![ModuleRole::UserInterface], // Roles assigned to your module
events_subscription: vec![ModuleEvent::NewValidBlock], // Events to which your module subscribes events_subscription: vec![ModuleEvent::NewValidBlock], // Events to which your module subscribes
reserved_apis_parts: vec![], reserved_apis_parts: vec![],
endpoints: vec![], endpoints: vec![],
}) })
.expect("Fatal error : gva module fail to register to router !"); // The registration of your module must be successful, in case of failure the program must be interrupted. .expect("Fatal error : gva module fail to register to router !"); // The registration of this module must be successful, in case of failure the program must be interrupted.
// If we are here it means that your module has successfully registered, we indicate it in the debug level log, it can be helpful. // If we are here it means that this module has successfully registered,
// we indicate it in the debug level log, it can be helpful.
debug!("Send gva module registration to router thread."); debug!("Send gva module registration to router thread.");
/*
* Main loop of your proxy thread
*/
loop {
match proxy_receiver.recv() {
Ok(message) => {
let stop = if let DursMsg::Stop = message {
true
} else {
false
};
if gva_sender_clone
.send(GvaMsg::DursMsg(Box::new(message)))
.is_err()
{
// Log error
warn!("Gva proxy : fail to relay DursMsg to gva main thread !")
}
if stop {
break;
}
}
Err(e) => {
// Log error
warn!("{}", e);
break;
}
}
}
});
let smd: SoftwareMetaDatas<DuRsConf> = soft_meta_datas.clone(); let smd: SoftwareMetaDatas<DuRsConf> = soft_meta_datas.clone();
let router_sender_clone = router_sender.clone(); let router_sender_clone = router_sender.clone();
thread::spawn(move || { let _webserver_thread = thread::spawn(move || {
if let Err(e) = webserver::start_web_server(&smd, host, conf.port) { if let Err(e) = webserver::start_web_server(&smd, host, conf.port) {
error!("GVA http web server error : {} ", e); error!("GVA http web server error : {} ", e);
} else { } else {
...@@ -309,20 +249,11 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { ...@@ -309,20 +249,11 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
loop { loop {
// Get messages // Get messages
match gva_receiver.recv_timeout(Duration::from_millis(250)) { match gva_receiver.recv_timeout(Duration::from_millis(250)) {
Ok(ref message) => match *message { Ok(durs_message) => match durs_message {
GvaMsg::DursMsg(ref durs_message) => {
match durs_message.deref() {
DursMsg::Stop => { DursMsg::Stop => {
// Relay stop signal to all child threads
let _result_stop_propagation: Result<(), mpsc::SendError<GvaMsg>> =
datas
.child_threads
.iter()
.map(|t| t.send(GvaMsg::DursMsg(Box::new(DursMsg::Stop))))
.collect();
// Relay stop signal to router // Relay stop signal to router
let _result = router_sender let _result =
.send(RouterThreadMessage::ModuleMessage(DursMsg::Stop)); router_sender.send(RouterThreadMessage::ModuleMessage(DursMsg::Stop));
// Break main loop // Break main loop
break; break;
} }
...@@ -337,7 +268,7 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { ...@@ -337,7 +268,7 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
BlockchainEvent::RevertBlocks(ref _blocks) => { BlockchainEvent::RevertBlocks(ref _blocks) => {
// Do something when the node has destacked blocks from its local blockchain (roll back) // Do something when the node has destacked blocks from its local blockchain (roll back)
} }
_ => {} // Do nothing for events that don't concern your module. _ => {} // Do nothing for events that don't concern this module.
} }
} }
DursEvent::NetworkEvent(ref network_event_box) => { DursEvent::NetworkEvent(ref network_event_box) => {
...@@ -348,30 +279,23 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule { ...@@ -348,30 +279,23 @@ impl DursModule<DuRsConf, DursMsg> for GvaModule {
NetworkEvent::ReceiveDocuments(ref _bc_documents) => { NetworkEvent::ReceiveDocuments(ref _bc_documents) => {
// Do something when the node receive blockchain documents from network // Do something when the node receive blockchain documents from network
} }
_ => {} // Do nothing for events that don't concern your module. _ => {} // Do nothing for events that don't concern this module.
} }
} }
_ => {} // Do nothing for DursEvent variants that don't concern your module. _ => {} // Do nothing for DursEvent variants that don't concern this module.
}, },
_ => {} // Do nothing for DursMsgContent variants that don't concern your module. _ => {} // Do nothing for DursMsgContent variants that don't concern this module.
}
}
GvaMsg::GvaThreadMsg(ref _child_thread_msg) => {
// Do something when receive a message from child thread.
}
}, },
Err(e) => match e { Err(e) => match e {
mpsc::RecvTimeoutError::Disconnected => { mpsc::RecvTimeoutError::Disconnected => {
fatal_error!("Disconnected gva module !"); fatal_error!("Disconnected gva module !");
} }
mpsc::RecvTimeoutError::Timeout => { mpsc::RecvTimeoutError::Timeout => {
// If you arrive here it's because your main thread did not receive anything at the end of the timeout. // If you arrive here it's because this main thread did not receive anything at the end of the timeout.
// This is quite normal and happens regularly when there is little activity, there is nothing particular to do. // This is quite normal and happens regularly when there is little activity, there is nothing particular to do.
} }
}, },
} }
// If you want your module's main thread to do things even when it doesn't receive any messages, this is the place where it can do them.
// ...
} }
// If we reach this point it means that the module has stopped correctly, so we return OK. // If we reach this point it means that the module has stopped correctly, so we return OK.
Ok(()) Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment