Commit 96cad9f3 authored by Éloïs's avatar Éloïs

Merge branch 'logs_panic' into 'dev'

Logs panic

See merge request nodes/rust/duniter-rs!72
parents 61512545 0e8e4723
......@@ -220,6 +220,7 @@ dependencies = [
"duniter-network 0.1.0-a0.1",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -512,6 +513,14 @@ dependencies = [
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log-panics"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "matches"
version = "0.1.6"
......@@ -1145,6 +1154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "87f737ad6cc6fd6eefe3d9dc5412f1573865bded441300904d2f42269e140f16"
"checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e"
"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
"checksum log-panics 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae0136257df209261daa18d6c16394757c63e032e27aafd8b07788b051082bef"
"checksum matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "100aabe6b8ff4e4a7e32c1c13523379802df0772b82466207ac25b013f193376"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
......
......@@ -807,14 +807,7 @@ impl BlockchainModule {
current_blockstamp
);
}
// Apply wot events
/*BlockchainModule::apply_wot_events(
&wot_events,
&wot_path,
&current_blockstamp,
&mut wot,
&mut wotb_index,
);*/ }
}
}
}
......
......@@ -337,28 +337,6 @@ pub fn load_conf_at_path(profile: &str, profile_path: &PathBuf) -> (DuRsConf, Du
let mut contents = String::new();
if f.read_to_string(&mut contents).is_ok() {
conf = serde_json::from_str(&contents).expect("Conf: Fail to parse conf file !");
/*let json_conf: serde_json::Value =
serde_json::from_str(&contents).expect("Conf: Fail to parse conf file !");
if let Some(currency) = json_conf.get("currency") {
conf.currency = Currency::Str(
currency
.as_str()
.expect("Conf: fail to parse currency field !")
.to_string(),
);
};
if let Some(node_id) = json_conf.get("node_id") {
conf.my_node_id =
u32::from_str_radix(
node_id
.as_str()
.expect("Conf : fail to parse node_id field !"),
16,
).expect("Fail to load conf: node_id must be an hexadecimal number !");
};
if let Some(modules_conf) = json_conf.get("modules") {
conf.modules = modules_conf.clone();
};*/
}
} else {
panic!("Fail to open conf file !");
......@@ -400,22 +378,6 @@ pub fn write_conf_file<DC: DuniterConf>(profile: &str, conf: &DC) -> Result<(),
.as_bytes(),
)?;
f.sync_all()?;
/*match *conf {
DuRsConf::V1(ref conf_v1) => {
let mut f = try!(File::create(conf_path.as_path()));
try!(
f.write_all(
serde_json::to_string_pretty(conf_v1)
.expect("Fatal error : fail to write default conf file !")
.as_bytes()
)
);
try!(f.sync_all());
}
_ => {
panic!("Fatal error : Conf version is not supported !");
}
}*/
Ok(())
}
......
......@@ -18,6 +18,7 @@ duniter-module = { path = "../module" }
duniter-network = { path = "../network" }
lazy_static = "1.0.*"
log = "0.4.*"
log-panics = "2.0.*"
rand = "0.4.*"
regex = "1.0.*"
rust-crypto = "0.2.*"
......
......@@ -34,6 +34,7 @@ extern crate duniter_crypto;
extern crate duniter_message;
extern crate duniter_module;
extern crate duniter_network;
extern crate log_panics;
extern crate serde_json;
extern crate simplelog;
extern crate sqlite;
......@@ -121,6 +122,9 @@ impl DuniterCore<DuRsConf> {
// Init logger
init_logger(profile.as_str(), soft_name, &cli_args);
// Print panic! in logs
log_panics::init();
// Load global conf
let (conf, keypairs) = duniter_conf::load_conf(profile.as_str());
info!("Success to load global conf.");
......
......@@ -194,82 +194,6 @@ impl Default for Blockstamp {
}
}
/*impl Serialize for Blockstamp {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}-{}", self.id, self.hash))
}
}*/
/*impl<'de> Deserialize<'de> for Blockstamp {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
#[derive(Deserialize)]
#[serde(field_identifier, rename_all = "lowercase")]
enum Field {
Id,
Hash,
}
struct BlockstampVisitor;
impl<'de> Visitor<'de> for BlockstampVisitor {
type Value = Blockstamp;
fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str("struct Blockstamp")
}
fn visit_seq<V>(self, mut seq: V) -> Result<Blockstamp, V::Error>
where
V: SeqAccess<'de>,
{
let id = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
let hash = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(1, &self))?;
Ok(Blockstamp { id, hash })
}
fn visit_map<V>(self, mut map: V) -> Result<Blockstamp, V::Error>
where
V: MapAccess<'de>,
{
let mut id = None;
let mut hash = None;
while let Some(key) = map.next_key()? {
match key {
Field::Id => {
if id.is_some() {
return Err(de::Error::duplicate_field("id"));
}
id = Some(map.next_value()?);
}
Field::Hash => {
if hash.is_some() {
return Err(de::Error::duplicate_field("hash"));
}
hash = Some(map.next_value()?);
}
}
}
let id = id.ok_or_else(|| de::Error::missing_field("id"))?;
let hash = hash.ok_or_else(|| de::Error::missing_field("hash"))?;
Ok(Blockstamp { id, hash })
}
}
const FIELDS: &'static [&'static str] = &["id", "hash"];
deserializer.deserialize_struct("Blockstamp", FIELDS, BlockstampVisitor)
}
}*/
impl PartialOrd for Blockstamp {
fn partial_cmp(&self, other: &Blockstamp) -> Option<Ordering> {
Some(self.cmp(other))
......
......@@ -64,19 +64,6 @@ impl ToString for ModuleId {
}
}
/*impl Serialize for ModuleId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let module_id_string = match *self {
ModuleId::Str(module_id_str) => String::from(module_id_str),
ModuleId::Bin(_) => panic!("ModuleId binary format is not implemented !"),
};
serializer.serialize_str(module_id_string.as_str())
}
}*/
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
/// Identifier of an inter-module request
pub struct ModuleReqId(pub u32);
......@@ -101,15 +88,6 @@ impl ToString for ModuleReqFullId {
}
}
/*impl Serialize for ModuleReqFullId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&format!("{}-{}", self.0.to_string(), (self.1).0))
}
}*/
/// Duniter configuration
pub trait DuniterConf: Clone + Debug + Default + PartialEq + Serialize + DeserializeOwned {
/// Get conf version profile
......
......@@ -322,9 +322,6 @@ impl TuiModuleDatas {
"{:02}:{:02}:{:02}",
runtime_hours, runtime_mins, runtime_secs
);
/*DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(runtime_in_secs, 0), Utc)
.format("%H:%M:%S")
.to_string();*/
write!(
stdout,
"{}{}{}runtime : {}",
......
......@@ -58,68 +58,6 @@ impl WS2PModuleDatas {
}
Ok(conn)
}
/*pub fn parse_ws2p_conf(
duniter_conf: &DuRsConf,
ws2p_json_conf: &serde_json::Value,
) -> WS2PConf {
let mut sync_endpoints = Vec::new();
match ws2p_json_conf.get("sync_peers") {
Some(peers) => {
let array_peers = peers.as_array().expect("Conf: Fail to parse conf file !");
for peer in array_peers {
let pubkey = match peer.get("pubkey") {
Some(pubkey) => PubKey::Ed25519(
ed25519::PublicKey::from_base58(
pubkey
.as_str()
.expect("WS2PConf Error : fail to parse sync endpoint pubkey"),
).expect("WS2PConf Error : fail to parse sync endpoint pubkey"),
),
None => panic!(
"Fail to load ws2p conf : \
WrongFormat : not found pubkey field !"
),
};
match peer.get("ws2p_endpoints") {
Some(endpoints) => {
let array_endpoints = endpoints
.as_array()
.expect("Conf: Fail to parse conf file !");
for endpoint in array_endpoints {
sync_endpoints.push(
NetworkEndpoint::parse_from_raw(
endpoint.as_str().expect("WS2P: Fail to get ep.as_str() !"),
pubkey,
0,
0,
).unwrap_or_else(|| {
panic!(
"WS2PConf Error : fail to parse sync Endpoint = {:?}",
endpoint
.as_str()
.expect("WS2P: Fail to get ep.as_str() !")
)
}),
);
}
}
None => panic!(
"Fail to load conf : \
WrongFormat : not found ws2p_endpoints field !"
),
};
}
}
None => panic!(
"Configuration Error : \
You must declare at least one node on which to synchronize !"
),
};
WS2PConf {
outcoming_quota: *WS2P_DEFAULT_OUTCOMING_QUOTA,
sync_endpoints,
}
}*/
pub fn send_dal_request(&self, req: &DALRequest) {
for follower in &self.followers {
if follower
......@@ -275,15 +213,10 @@ impl WS2PModuleDatas {
.1 = WS2PConnectionState::Close
}
}
let _result = self
.websockets
.get(&ws2p_full_id)
.expect("Try to close an unexistant websocket !")
.0
.close(ws::CloseCode::Normal);
self.websockets
.remove(ws2p_full_id)
.unwrap_or_else(|| panic!("Fatal error : no websocket for {} !", ws2p_full_id));
if let Some(websocket) = self.websockets.get(&ws2p_full_id) {
let _result = websocket.0.close(ws::CloseCode::Normal);
}
let _result = self.websockets.remove(ws2p_full_id);
}
pub fn ws2p_conn_message_pretreatment(&mut self, message: WS2PConnectionMessage) -> WS2PSignal {
let ws2p_full_id = message.0;
......
......@@ -201,17 +201,6 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
fn ask_required_keys() -> RequiredKeys {
RequiredKeys::NetworkKeyPair()
}
/*fn default_conf() -> serde_json::Value {
json!({
"sync_peers": [{
"pubkey": "D9D2zaJoWYWveii1JRYLVK3J4Z7ZH3QczoKrnQeiM6mx",
"ws2p_endpoints": ["WS2P c1c39a0a i3.ifee.fr 80 /ws2p"]
},{
"pubkey": "7v2J4badvfWQ6qwRdCwhhJfAsmKwoxRUNpJHiJHj7zef",
"ws2p_endpoints": ["WS2P b48824f0 g1.monnaielibreoccitanie.org 80 /ws2p"]
}]
})
}*/
fn start(
soft_meta_datas: &SoftwareMetaDatas<DuRsConf>,
keys: RequiredKeysContent,
......@@ -219,7 +208,10 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
rooter_sender: mpsc::Sender<RooterThreadMessage<DuniterMessage>>,
load_conf_only: bool,
) -> Result<(), ModuleInitError> {
// Get start time
let start_time = SystemTime::now();
// Define WS2PModuleDatas
let mut ws2p_module = WS2PModuleDatas {
followers: Vec::new(),
key_pair: None,
......@@ -739,65 +731,11 @@ impl DuniterModule<DuRsConf, DuniterMessage> for WS2PModule {
{
last_ws2p_connections_print = SystemTime::now();
let mut connected_nodes = Vec::new();
let mut denial_nodes = Vec::new();
let mut disconnected_nodes = Vec::new();
let mut unreachable_nodes = Vec::new();
let mut ws_error_nodes = Vec::new();
for (k, (_ep, state)) in ws2p_module.ws2p_endpoints.clone() {
match state {
WS2PConnectionState::NeverTry => {
//writeln!("Never try : {}", k);
}
WS2PConnectionState::TryToOpenWS => {}//writeln!("TryToOpenWS : {}", k),
WS2PConnectionState::WSError => {
ws_error_nodes.push(k);
}
WS2PConnectionState::TryToSendConnectMess => {
//writeln!("TryToSendConnectMess : {}", k)
}
WS2PConnectionState::Unreachable => {
unreachable_nodes.push(k);
}
WS2PConnectionState::WaitingConnectMess => {
//writeln!("WaitingConnectMess : {}", k)
}
WS2PConnectionState::NoResponse => {}//writeln!("NoResponse : {}", k),
WS2PConnectionState::AckMessOk
| WS2PConnectionState::ConnectMessOk
| WS2PConnectionState::OkMessOkWaitingAckMess => {
//writeln!("Ongoing negotiations : {}", k)
}
WS2PConnectionState::Denial => {
denial_nodes.push(k);
}
WS2PConnectionState::Established => {
connected_nodes.push(k);
}
WS2PConnectionState::Close => {
disconnected_nodes.push(k);
}
if let WS2PConnectionState::Established = state {
connected_nodes.push(k);
}
}
/*writeln!(
"Connected with {} nodes. (Denial : {}, Disconnected : {}, Unreachable: {}, WSError : {})",
connected_nodes.len(),
denial_nodes.len(),
disconnected_nodes.len(),
unreachable_nodes.len(),
ws_error_nodes.len()
);*/
for _node in connected_nodes.clone() {
//writeln!("Connection established : {}", node);
}
for _node in denial_nodes {
//writeln!("Denial : {}", node);
}
for _node in disconnected_nodes {
//writeln!("Disconnected : {}", node);
}
for _node in unreachable_nodes {
//writeln!("Unreachable : {}", node);
}
// Print network consensus
match ws2p_module.get_network_consensus() {
Ok(consensus_blockstamp) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment