diff --git a/hyperactor/src/channel.rs b/hyperactor/src/channel.rs index 2f62bb0b5..378b01df0 100644 --- a/hyperactor/src/channel.rs +++ b/hyperactor/src/channel.rs @@ -276,20 +276,20 @@ pub type Port = u16; /// The type of a channel address, used to multiplex different underlying /// channel implementations. ChannelAddrs also have a concrete syntax: -/// the address type ("tcp" or "local"), followed by "!", and an address -/// parseable to that type. Addresses without a specified type default to -/// "tcp". For example: +/// the address type (e.g., "tcp" or "local"), followed by ":", and an address +/// parseable to that type. For example: /// -/// - `tcp!127.0.0.1:1234` - localhost port 1234 over TCP -/// - `tcp!192.168.0.1:1111` - 192.168.0.1 port 1111 over TCP -/// - `local!123` - the (in-process) local port 123 +/// - `tcp:127.0.0.1:1234` - localhost port 1234 over TCP +/// - `tcp:192.168.0.1:1111` - 192.168.0.1 port 1111 over TCP +/// - `local:123` - the (in-process) local port 123 +/// - `unix:/some/path` - the Unix socket at `/some/path` /// /// Both local and TCP ports 0 are reserved to indicate "any available /// port" when serving. /// /// ``` /// # use hyperactor::channel::ChannelAddr; -/// let addr: ChannelAddr = "tcp!127.0.0.1:1234".parse().unwrap(); +/// let addr: ChannelAddr = "tcp:127.0.0.1:1234".parse().unwrap(); /// let ChannelAddr::Tcp(socket_addr) = addr else { /// panic!() /// }; @@ -401,11 +401,11 @@ impl ChannelAddr { impl fmt::Display for ChannelAddr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Tcp(addr) => write!(f, "tcp!{}", addr), - Self::MetaTls(hostname, port) => write!(f, "metatls!{}:{}", hostname, port), - Self::Local(index) => write!(f, "local!{}", index), - Self::Sim(sim_addr) => write!(f, "sim!{}", sim_addr), - Self::Unix(addr) => write!(f, "unix!{}", addr), + Self::Tcp(addr) => write!(f, "tcp:{}", addr), + Self::MetaTls(hostname, port) => write!(f, "metatls:{}:{}", hostname, port), + Self::Local(index) => write!(f, "local:{}", index), + Self::Sim(sim_addr) => write!(f, "sim:{}", sim_addr), + Self::Unix(addr) => write!(f, "unix:{}", addr), } } } @@ -414,7 +414,8 @@ impl FromStr for ChannelAddr { type Err = anyhow::Error; fn from_str(addr: &str) -> Result { - match addr.split_once('!') { + // "!" is the legacy delimiter; ":" is preferred + match addr.split_once('!').or_else(|| addr.split_once(':')) { Some(("local", rest)) => rest .parse::() .map(Self::Local) @@ -604,30 +605,30 @@ mod tests { fn test_channel_addr() { let cases_ok = vec![ ( - "tcp![::1]:1234", + "tcp[::1]:1234", ChannelAddr::Tcp(SocketAddr::new( IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 1234, )), ), ( - "tcp!127.0.0.1:8080", + "tcp127.0.0.1:8080", ChannelAddr::Tcp(SocketAddr::new( IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080, )), ), - ("local!123", ChannelAddr::Local(123)), #[cfg(target_os = "linux")] + ("local123", ChannelAddr::Local(123)), ( - "unix!@yolo", + "unix@yolo", ChannelAddr::Unix( unix::SocketAddr::from_abstract_name("yolo") .expect("can't make socket from abstract name"), ), ), ( - "unix!/cool/socket-path", + "unix/cool/socket-path", ChannelAddr::Unix( unix::SocketAddr::from_pathname("/cool/socket-path") .expect("can't make socket from path"), @@ -635,42 +636,29 @@ mod tests { ), ]; - let src_ok = vec![ - ( - "tcp![::1]:1235", - ChannelAddr::Tcp(SocketAddr::new( - IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), - 1235, - )), - ), - ( - "tcp!127.0.0.1:8081", - ChannelAddr::Tcp(SocketAddr::new( - IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), - 8081, - )), - ), - ("local!124", ChannelAddr::Local(124)), - ]; - for (raw, parsed) in cases_ok.clone() { - assert_eq!(raw.parse::().unwrap(), parsed); + for delim in ["!", ":"] { + let raw = raw.replace("", delim); + assert_eq!(raw.parse::().unwrap(), parsed); + } } - for (raw, parsed) in cases_ok.iter().zip(src_ok.clone()).map(|(a, _)| { - ( - format!("sim!{}", a.0), - ChannelAddr::Sim(SimAddr::new(a.1.clone()).unwrap()), - ) - }) { - assert_eq!(raw.parse::().unwrap(), parsed); + for (raw, parsed) in cases_ok { + for delim in ["!", ":"] { + // We don't allow mixing and matching delims + let raw = format!("sim{}{}", delim, raw.replace("", delim)); + assert_eq!( + raw.parse::().unwrap(), + ChannelAddr::Sim(SimAddr::new(parsed.clone()).unwrap()) + ); + } } let cases_err = vec![ - ("tcp!abcdef..123124", "invalid socket address syntax"), - ("xxx!foo", "no such channel type: xxx"), + ("tcp:abcdef..123124", "invalid socket address syntax"), + ("xxx:foo", "no such channel type: xxx"), ("127.0.0.1", "no channel type specified"), - ("local!abc", "invalid digit found in string"), + ("local:abc", "invalid digit found in string"), ]; for (raw, error) in cases_err { @@ -751,13 +739,13 @@ mod tests { let rng = rand::thread_rng(); vec![ - "tcp![::1]:0".parse().unwrap(), - "local!0".parse().unwrap(), + "tcp:[::1]:0".parse().unwrap(), + "local:0".parse().unwrap(), #[cfg(target_os = "linux")] - "unix!".parse().unwrap(), + "unix:".parse().unwrap(), #[cfg(target_os = "linux")] format!( - "unix!@{}", + "unix:@{}", rng.sample_iter(Uniform::new_inclusive('a', 'z')) .take(10) .collect::() diff --git a/hyperactor/src/channel/sim.rs b/hyperactor/src/channel/sim.rs index acd509617..41a41487e 100644 --- a/hyperactor/src/channel/sim.rs +++ b/hyperactor/src/channel/sim.rs @@ -419,8 +419,8 @@ mod tests { #[tokio::test] async fn test_sim_basic() { - let dst_ok = vec!["tcp![::1]:1234", "tcp!127.0.0.1:8080", "local!123"]; - let srcs_ok = vec!["tcp![::2]:1234", "tcp!127.0.0.2:8080", "local!124"]; + let dst_ok = vec!["tcp:[::1]:1234", "tcp:127.0.0.1:8080", "local:123"]; + let srcs_ok = vec!["tcp:[::2]:1234", "tcp:127.0.0.2:8080", "local:124"]; start(); @@ -460,23 +460,23 @@ mod tests { #[tokio::test] async fn test_parse_sim_addr() { - let sim_addr = "sim!unix!@dst"; + let sim_addr = "sim!unix:@dst"; let result = sim_addr.parse(); assert!(result.is_ok()); let ChannelAddr::Sim(sim_addr) = result.unwrap() else { panic!("Expected a sim address"); }; assert!(sim_addr.src().is_none()); - assert_eq!(sim_addr.addr().to_string(), "unix!@dst"); + assert_eq!(sim_addr.addr().to_string(), "unix:@dst"); - let sim_addr = "sim!unix!@src,unix!@dst"; + let sim_addr = "sim!unix:@src,unix:@dst"; let result = sim_addr.parse(); assert!(result.is_ok()); let ChannelAddr::Sim(sim_addr) = result.unwrap() else { panic!("Expected a sim address"); }; assert!(sim_addr.src().is_some()); - assert_eq!(sim_addr.addr().to_string(), "unix!@dst"); + assert_eq!(sim_addr.addr().to_string(), "unix:@dst"); } #[tokio::test] @@ -484,18 +484,18 @@ mod tests { start(); tokio::time::pause(); - let sim_addr = SimAddr::new("unix!@dst".parse::().unwrap()).unwrap(); + let sim_addr = SimAddr::new("unix:@dst".parse::().unwrap()).unwrap(); let sim_addr_with_src = SimAddr::new_with_src( - "unix!@src".parse::().unwrap(), - "unix!@dst".parse::().unwrap(), + "unix:@src".parse::().unwrap(), + "unix:@dst".parse::().unwrap(), ) .unwrap(); let (_, mut rx) = sim::serve::<()>(sim_addr.clone()).unwrap(); let tx = sim::dial::<()>(sim_addr_with_src).unwrap(); let simnet_config_yaml = r#" edges: - - src: unix!@src - dst: unix!@dst + - src: unix:@src + dst: unix:@dst metadata: latency: 100 "#; @@ -526,15 +526,15 @@ mod tests { tokio::time::pause(); start(); let controller_to_dst = SimAddr::new_with_src( - "unix!@controller".parse::().unwrap(), - "unix!@dst".parse::().unwrap(), + "unix:@controller".parse::().unwrap(), + "unix:@dst".parse::().unwrap(), ) .unwrap(); let controller_tx = sim::dial::<()>(controller_to_dst.clone()).unwrap(); let client_to_dst = SimAddr::new_with_client_src( - "unix!@client".parse::().unwrap(), - "unix!@dst".parse::().unwrap(), + "unix:@client".parse::().unwrap(), + "unix:@dst".parse::().unwrap(), ) .unwrap(); let client_tx = sim::dial::<()>(client_to_dst).unwrap(); @@ -542,8 +542,8 @@ mod tests { // 1 second of latency let simnet_config_yaml = r#" edges: - - src: unix!@controller - dst: unix!@dst + - src: unix:@controller + dst: unix:@dst metadata: latency: 1 "#; diff --git a/hyperactor/src/mailbox.rs b/hyperactor/src/mailbox.rs index 3c2650ad4..d64566575 100644 --- a/hyperactor/src/mailbox.rs +++ b/hyperactor/src/mailbox.rs @@ -2709,10 +2709,10 @@ mod tests { #[tokio::test] async fn test_sim_client_server() { simnet::start(); - let dst_addr = SimAddr::new("local!1".parse::().unwrap()).unwrap(); + let dst_addr = SimAddr::new("local:1".parse::().unwrap()).unwrap(); let src_to_dst = ChannelAddr::Sim( SimAddr::new_with_src( - "local!0".parse::().unwrap(), + "local:0".parse::().unwrap(), dst_addr.addr().clone(), ) .unwrap(), diff --git a/hyperactor/src/simnet.rs b/hyperactor/src/simnet.rs index 28b1d1c28..def1fc9f5 100644 --- a/hyperactor/src/simnet.rs +++ b/hyperactor/src/simnet.rs @@ -917,8 +917,8 @@ mod tests { // Tests that we can create a simnet, config latency between two node and deliver // the message with configured latency. start(); - let alice = "local!1".parse::().unwrap(); - let bob = "local!2".parse::().unwrap(); + let alice = "local:1".parse::().unwrap(); + let bob = "local:2".parse::().unwrap(); let latency = Duration::from_millis(1000); let config = NetworkConfig { edges: vec![EdgeConfig { @@ -949,7 +949,7 @@ mod tests { .unwrap(); let records = simnet_handle().unwrap().close().await; let expected_record = SimulatorEventRecord { - summary: "Sending message from local!1 to local!2".to_string(), + summary: "Sending message from local:1 to local:2".to_string(), start_at: 0, end_at: latency.as_millis() as u64, }; @@ -960,8 +960,8 @@ mod tests { #[tokio::test] async fn test_simnet_debounce() { start(); - let alice = "local!1".parse::().unwrap(); - let bob = "local!2".parse::().unwrap(); + let alice = "local:1".parse::().unwrap(); + let bob = "local:2".parse::().unwrap(); let latency = Duration::from_millis(10000); simnet_handle() @@ -1020,7 +1020,7 @@ mod tests { // // Create a simple network of 4 nodes. for i in 0..4 { addresses.push( - format!("local!{}", i) + format!("local:{}", i) .parse::() .unwrap(), ); @@ -1083,16 +1083,16 @@ mod tests { async fn test_read_config_from_yaml() { let yaml = r#" edges: - - src: local!0 - dst: local!1 + - src: local:0 + dst: local:1 metadata: latency: 1 - - src: local!0 - dst: local!2 + - src: local:0 + dst: local:2 metadata: latency: 2 - - src: local!1 - dst: local!2 + - src: local:1 + dst: local:2 metadata: latency: 3 "#; @@ -1100,29 +1100,29 @@ mod tests { assert_eq!(config.edges.len(), 3); assert_eq!( config.edges[0].src, - "local!0".parse::().unwrap() + "local:0".parse::().unwrap() ); assert_eq!( config.edges[0].dst, - "local!1".parse::().unwrap() + "local:1".parse::().unwrap() ); assert_eq!(config.edges[0].metadata.latency, Duration::from_secs(1)); assert_eq!( config.edges[1].src, - "local!0".parse::().unwrap() + "local:0".parse::().unwrap() ); assert_eq!( config.edges[1].dst, - "local!2".parse::().unwrap() + "local:2".parse::().unwrap() ); assert_eq!(config.edges[1].metadata.latency, Duration::from_secs(2)); assert_eq!( config.edges[2].src, - "local!1".parse::().unwrap() + "local:1".parse::().unwrap() ); assert_eq!( config.edges[2].dst, - "local!2".parse::().unwrap() + "local:2".parse::().unwrap() ); assert_eq!(config.edges[2].metadata.latency, Duration::from_secs(3)); } diff --git a/hyperactor_multiprocess/src/ping_pong.rs b/hyperactor_multiprocess/src/ping_pong.rs index 848721a04..dd610dddf 100644 --- a/hyperactor_multiprocess/src/ping_pong.rs +++ b/hyperactor_multiprocess/src/ping_pong.rs @@ -33,7 +33,7 @@ mod tests { #[tracing_test::traced_test] #[tokio::test] async fn test_sim_ping_pong() { - let system_addr = "local!1".parse::().unwrap(); + let system_addr = "local:1".parse::().unwrap(); simnet::start(); diff --git a/hyperactor_multiprocess/src/system_actor.rs b/hyperactor_multiprocess/src/system_actor.rs index ce75926f6..584cddc9b 100644 --- a/hyperactor_multiprocess/src/system_actor.rs +++ b/hyperactor_multiprocess/src/system_actor.rs @@ -2947,7 +2947,7 @@ mod tests { panic!("Expected sim address"); }; - assert_eq!(addr.src().clone().unwrap().to_string(), "unix!@src"); - assert_eq!(addr.addr().to_string(), "unix!@dst"); + assert_eq!(addr.src().clone().unwrap().to_string(), "unix:@src"); + assert_eq!(addr.addr().to_string(), "unix:@dst"); } }