Skip to content

Commit

Permalink
ZMQ socket addresses support native ZMQ representation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 13, 2021
1 parent f23a16a commit 8e35d5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "internet2"
version = "0.5.4"
version = "0.5.5"
license = "Apache-2.0"
authors = ["Dr. Maxim Orlovsky <orlovsky@pandoracore.com>"]
description = "Rust implementation for the stack of Internet2 protocols"
Expand Down
26 changes: 14 additions & 12 deletions src/transport/zmqsocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DisplayFromStr>"))]
SocketAddr,
Expand All @@ -193,17 +193,17 @@ 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://",
}
}

fn to_url_string(&self) -> String { format!("{:}", self) }
}

impl ZmqSocketAddr {
pub fn zmq_socket_string(&self) -> String { format!("{:#}", self) }
pub fn zmq_socket_string(&self) -> String { format!("{:}", self) }
}

#[derive(Display)]
Expand Down Expand Up @@ -313,15 +313,17 @@ impl TryFrom<Url> 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())),
}
}
Expand Down

0 comments on commit 8e35d5c

Please sign in to comment.