Skip to content
Snippets Groups Projects
Commit 52d5bd0f authored by Jonas SPRENGER's avatar Jonas SPRENGER
Browse files

[feat] network-documents: replace panic! by fatal_error!

parent b98845f1
No related branches found
No related tags found
1 merge request!141Jonas/127 replace all panics by fatal error
......@@ -457,7 +457,9 @@ dependencies = [
"bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-documents 0.12.0",
"dup-crypto 0.6.0",
"durs-common-tools 0.1.0",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
......
......@@ -12,6 +12,8 @@ edition = "2018"
path = "src/lib.rs"
[dependencies]
log = "0.4.*"
durs-common-tools = { path = "../common-tools" }
base58 = "0.1.*"
dup-crypto = { path = "../crypto" }
dubp-documents= { path = "../documents" }
......
......@@ -30,6 +30,8 @@ extern crate pest_derive;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
#[macro_use]
extern crate log;
pub mod network_endpoint;
pub mod network_head;
......@@ -44,6 +46,7 @@ use crate::network_peer::PeerCardV11;
use dubp_documents::{TextDocumentParseError, TextDocumentParser};
use dup_crypto::hashs::*;
use dup_crypto::keys::*;
use durs_common_tools::fatal_error;
use pest::iterators::Pair;
use pest::Parser;
use serde::{Deserialize, Serialize};
......@@ -82,7 +85,7 @@ impl TextDocumentParser<Rule> for NetworkDocument {
Rule::head_v3 => NetworkDocument::Head(NetworkHead::V3(Box::new(
NetworkHeadV3::from_pest_pair(pair),
))),
_ => panic!("unexpected rule: {:?}", pair.as_rule()), // Grammar ensures that we never reach this line
_ => fatal_error!("unexpected rule: {:?}", pair.as_rule()), // Grammar ensures that we never reach this line
}
}
}
......
......@@ -147,7 +147,7 @@ impl EndpointV1 {
Rule::host => host_str = ep_pair.as_str(),
Rule::port => port = ep_pair.as_str().parse().unwrap(),
Rule::path_inner => path = Some(String::from(ep_pair.as_str())),
_ => panic!("unexpected rule: {:?}", ep_pair.as_rule()), // Grammar ensures that we never reach this line
_ => fatal_error!("unexpected rule: {:?}", ep_pair.as_rule()), // Grammar ensures that we never reach this line
}
}
EndpointV1 {
......@@ -388,7 +388,7 @@ impl EndpointV2 {
Rule::ip4_inner => ip_v4 = Some(Ipv4Addr::from_str(field.as_str()).unwrap()),
Rule::ip6_inner => ip_v6 = Some(Ipv6Addr::from_str(field.as_str()).unwrap()),
Rule::path_inner => path = Some(String::from(field.as_str())),
_ => panic!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
_ => fatal_error!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
}
}
if network_features.is_empty() {
......@@ -468,7 +468,7 @@ impl EndpointEnum {
pub fn raw(&self) -> String {
match *self {
EndpointEnum::V1(ref ep) => ep.raw_endpoint.clone(),
_ => panic!("Endpoint version is not supported !"),
_ => fatal_error!("Endpoint version is not supported !"),
}
}
/// Accessors providing endpoint accessibility status
......
......@@ -21,6 +21,7 @@ use crate::{NodeFullId, NodeId};
use dubp_documents::blockstamp::*;
use dup_crypto::bases::BaseConvertionError;
use dup_crypto::keys::*;
use durs_common_tools::fatal_error;
use serde::{Deserialize, Serialize};
use serde_json;
use std::collections::HashMap;
......@@ -41,7 +42,7 @@ impl ToString for NetworkHead {
fn to_string(&self) -> String {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.deref().to_string(),
_ => panic!("NetworkHead version not supported !"),
_ => fatal_error!("NetworkHead version not supported !"),
}
}
}
......@@ -96,14 +97,14 @@ impl NetworkHead {
pub fn version(&self) -> u32 {
match *self {
NetworkHead::V2(_) => 2,
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Get HEAD blockstamp
pub fn blockstamp(&self) -> Blockstamp {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.message_v2.blockstamp(),
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Get pubkey of head issuer
......@@ -111,30 +112,30 @@ impl NetworkHead {
match *self {
NetworkHead::V2(ref head_v2) => match head_v2.message_v2 {
NetworkHeadMessage::V2(ref head_message_v2) => head_message_v2.pubkey,
_ => panic!("This HEAD message version is not supported !"),
_ => fatal_error!("This HEAD message version is not supported !"),
},
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Get uid of head issuer
pub fn uid(&self) -> Option<String> {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.uid(),
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Change uid of head issuer
pub fn set_uid(&mut self, uid: &str) {
match *self {
NetworkHead::V2(ref mut head_v2) => head_v2.uid = Some(String::from(uid)),
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// return the HEAD Step
pub fn step(&self) -> u32 {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.step,
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Checks the validity of all head signatures
......@@ -147,14 +148,14 @@ impl NetworkHead {
.pubkey()
.verify(head_v2.message_v2.to_string().as_bytes(), &head_v2.sig_v2)
}
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Returns issuer node id
pub fn node_uuid(&self) -> NodeId {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.message_v2.node_uuid(),
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Returns issuer node full identifier
......@@ -249,7 +250,7 @@ impl NetworkHead {
pub fn to_human_string(&self, max_len: usize) -> String {
match *self {
NetworkHead::V2(ref head_v2) => head_v2.deref().to_human_string(max_len),
_ => panic!("NetworkHead version not supported !"),
_ => fatal_error!("NetworkHead version not supported !"),
}
}
}
......@@ -19,6 +19,7 @@ use crate::NodeId;
use dubp_documents::blockstamp::*;
use dup_crypto::bases::BaseConvertionError;
use dup_crypto::keys::*;
use durs_common_tools::fatal_error;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::num::ParseIntError;
......@@ -202,28 +203,28 @@ impl NetworkHeadMessage {
pub fn to_human_string(&self, max_len: usize, uid: Option<String>) -> String {
match *self {
NetworkHeadMessage::V2(ref mess_v2) => mess_v2.deref().to_human_string(max_len, uid),
_ => panic!("NetworkHead version not supported !"),
_ => fatal_error!("NetworkHead version not supported !"),
}
}
/// Get head blockcstamp
pub fn blockstamp(&self) -> Blockstamp {
match *self {
NetworkHeadMessage::V2(ref head_message_v2) => head_message_v2.blockstamp,
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Get head node id
pub fn node_uuid(&self) -> NodeId {
match *self {
NetworkHeadMessage::V2(ref head_message_v2) => head_message_v2.node_uuid,
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
/// Get head issuer public key
fn _pubkey(&self) -> PubKey {
match *self {
NetworkHeadMessage::V2(ref head_message_v2) => head_message_v2.pubkey,
_ => panic!("This HEAD version is not supported !"),
_ => fatal_error!("This HEAD version is not supported !"),
}
}
}
......@@ -253,7 +254,7 @@ impl ToString for NetworkHeadMessageV2 {
self.free_member_room.unwrap(),
self.free_mirror_room.unwrap()
),
_ => panic!("NetworkHeadMessage is wrongly parsed !"),
_ => fatal_error!("NetworkHeadMessage is wrongly parsed !"),
}
}
}
......@@ -262,7 +263,7 @@ impl ToString for NetworkHeadMessage {
fn to_string(&self) -> String {
match *self {
NetworkHeadMessage::V2(ref head_message) => head_message.to_string(),
_ => panic!("This HEADMessage version is not supported !"),
_ => fatal_error!("This HEADMessage version is not supported !"),
}
}
}
......
......@@ -162,7 +162,7 @@ impl TextDocumentParser<Rule> for NetworkHeadV3 {
))
}
Rule::step => step = field.as_str().parse().unwrap(),
_ => panic!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
_ => fatal_error!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
}
}
NetworkHeadV3 {
......
......@@ -172,7 +172,7 @@ impl TextDocumentParser<Rule> for PeerCardV11 {
ed25519::Signature::from_base64(field.as_str()).unwrap(),
))
}
_ => panic!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
_ => fatal_error!("unexpected rule: {:?}", field.as_rule()), // Grammar ensures that we never reach this line
}
}
let endpoints_len = endpoints.len();
......@@ -252,7 +252,6 @@ impl PeerCard {
match *self {
PeerCard::V10(ref peer_v10) => peer_v10.blockstamp,
PeerCard::V11(ref peer_v11) => peer_v11.blockstamp,
//_ => panic!("Peer version is not supported !"),
}
}
/// Get peer card issuer
......@@ -260,7 +259,6 @@ impl PeerCard {
match *self {
PeerCard::V10(ref peer_v10) => peer_v10.issuer,
PeerCard::V11(ref peer_v11) => peer_v11.issuer,
//_ => panic!("Peer version is not supported !"),
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment