diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs index bf8f4cb..fa2f37a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,3 +1,5 @@ +use std::net::SocketAddr; + use serde::Serialize; use log::info; @@ -56,3 +58,13 @@ pub fn watch_ctrl_c() -> watch::Receiver<bool> { }); watch_cancel } + +/// Parse a peer's address including public key, written in the format: +/// `<public key hex>@<ip>:<port>` +pub fn parse_peer_addr(peer: &str) -> Option<(NodeID, SocketAddr)> { + let delim = peer.find('@')?; + let (key, ip) = peer.split_at(delim); + let pubkey = NodeID::from_slice(&hex::decode(&key).ok()?)?; + let ip = ip[1..].parse::<SocketAddr>().ok()?; + Some((pubkey, ip)) +} |