diff --git a/util/src/network/mod.rs b/util/src/network/mod.rs index ff52212af..50645f2be 100644 --- a/util/src/network/mod.rs +++ b/util/src/network/mod.rs @@ -89,6 +89,7 @@ pub use network::host::NetworkConfiguration; pub use network::stats::NetworkStats; use io::TimerToken; +pub use network::node_table::is_valid_node_url; const PROTOCOL_VERSION: u32 = 4; diff --git a/util/src/network/node_table.rs b/util/src/network/node_table.rs index 065990a63..f528f7134 100644 --- a/util/src/network/node_table.rs +++ b/util/src/network/node_table.rs @@ -332,6 +332,11 @@ impl Drop for NodeTable { } } +pub fn is_valid_node_url(url: &str) -> bool { + use std::str::FromStr; + Node::from_str(url).is_ok() +} + #[cfg(test)] mod tests { use super::*; @@ -353,6 +358,7 @@ mod tests { #[test] fn node_parse() { + assert!(is_valid_node_url("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770")); let node = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@22.99.55.44:7770"); assert!(node.is_ok()); let node = node.unwrap();