From 8e35d5c3aea03f97b8b5e9c58564d6008ccaecba Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Mon, 13 Dec 2021 06:58:15 +0100 Subject: [PATCH] ZMQ socket addresses support native ZMQ representation --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/transport/zmqsocket.rs | 26 ++++++++++++++------------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ce0a97a..a442d66e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Change Log ========== +v0.5.5 +------ +- ZMQ socket addresses support native ZMQ representation (starting with + `tcp://`, `ipc://`, `inproc://`) + v0.5.3 ------ - Complete Tlv implementation diff --git a/Cargo.lock b/Cargo.lock index afe7f4e6..13065581 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -688,7 +688,7 @@ dependencies = [ [[package]] name = "internet2" -version = "0.5.4" +version = "0.5.5" dependencies = [ "amplify", "bitcoin_hashes", diff --git a/Cargo.toml b/Cargo.toml index 0fe1f743..e3784825 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "internet2" -version = "0.5.4" +version = "0.5.5" license = "Apache-2.0" authors = ["Dr. Maxim Orlovsky "] description = "Rust implementation for the stack of Internet2 protocols" diff --git a/src/transport/zmqsocket.rs b/src/transport/zmqsocket.rs index ed8596f4..8c4f9034 100644 --- a/src/transport/zmqsocket.rs +++ b/src/transport/zmqsocket.rs @@ -163,13 +163,13 @@ impl FromStr for ZmqType { StrictDecode )] pub enum ZmqSocketAddr { - #[display("zmq:{0}", alt = "inproc://{0}")] + #[display("inproc://{0}", alt = "zmq:{0}")] Inproc(String), - #[display("lnpz:{0}", alt = "ipc://{0}")] + #[display("ipc://{0}", alt = "lnpz:{0}")] Ipc(String), - #[display("lnpz://{0}", alt = "tcp://{0}")] + #[display("tcp://{0}", alt = "lnpz://{0}")] Tcp( #[cfg_attr(feature = "serde", serde(with = "As::"))] SocketAddr, @@ -193,9 +193,9 @@ impl Ord for ZmqSocketAddr { impl UrlString for ZmqSocketAddr { fn url_scheme(&self) -> &'static str { match self { - ZmqSocketAddr::Inproc(_) => "zmq:", - ZmqSocketAddr::Ipc(_) => "lnpz:", - ZmqSocketAddr::Tcp(_) => "lnpz://", + ZmqSocketAddr::Inproc(_) => "inproc://", + ZmqSocketAddr::Ipc(_) => "ipc://", + ZmqSocketAddr::Tcp(_) => "tcp://", } } @@ -203,7 +203,7 @@ impl UrlString for ZmqSocketAddr { } impl ZmqSocketAddr { - pub fn zmq_socket_string(&self) -> String { format!("{:#}", self) } + pub fn zmq_socket_string(&self) -> String { format!("{:}", self) } } #[derive(Display)] @@ -313,15 +313,17 @@ impl TryFrom for ZmqSocketAddr { Ok(ZmqSocketAddr::Ipc(url.path().to_owned())) } } - "tcp" => Err(AddrError::UnknownUrlScheme(s!( - "'tcp://'; use 'lnpz://' instead" + "tcp" => Ok(ZmqSocketAddr::Tcp(SocketAddr::new( + url.host() + .ok_or(AddrError::HostRequired)? + .to_string() + .parse()?, + url.port().ok_or(AddrError::PortRequired)?, ))), "inproc" => Ok(ZmqSocketAddr::Inproc( url.host_str().ok_or(AddrError::HostRequired)?.to_owned(), )), - "ipc" => Err(AddrError::UnknownUrlScheme(s!( - "'ipc:'; use 'lnpz:' instead" - ))), + "ipc" => Ok(ZmqSocketAddr::Ipc(url.path().to_owned())), unknown => Err(AddrError::UnknownUrlScheme(unknown.to_owned())), } }