From 7e49d0dac847cc2a502038eb512255377ac6238a Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 14 Oct 2021 11:58:09 +0200 Subject: Make a public function to parse peer addresses --- src/util.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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 { }); watch_cancel } + +/// Parse a peer's address including public key, written in the format: +/// `@:` +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::().ok()?; + Some((pubkey, ip)) +} -- cgit v1.2.3