Added is_valid_node_url

This commit is contained in:
arkpar 2016-02-19 14:13:20 +01:00
parent 85c842b7fd
commit beab90c707
2 changed files with 7 additions and 0 deletions

View File

@ -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;

View File

@ -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();