From 04bbb3a2e819ee1fa2c6829b112ad0bfe17b3cd3 Mon Sep 17 00:00:00 2001 From: gh0st <1264131+gh0st42@users.noreply.github.com> Date: Fri, 24 Nov 2023 08:17:32 +0100 Subject: [PATCH] fix(eid): calling node_id() on an IPN eid now returns correct URL instead of an dtn scheme formatted IPN address --- src/eid.rs | 9 ++++++--- src/helpers.rs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/eid.rs b/src/eid.rs index e1f0e69..1059baf 100644 --- a/src/eid.rs +++ b/src/eid.rs @@ -267,16 +267,18 @@ impl EndpointID { /// let ipn_addr_2 = EndpointID::with_ipn(23, 7).unwrap(); /// /// assert_eq!(ipn_addr_1, ipn_addr_2.new_endpoint("42").unwrap()); + /// assert_eq!(ipn_addr_1.node_id(), Some("ipn:23.0".to_string())); /// /// let ipn_addr_1 = EndpointID::with_ipn(23, 42).unwrap(); /// - /// assert!(ipn_addr_1.new_endpoint("-42").is_err()); + /// assert!(ipn_addr_1.new_endpoint("-42").is_err()); /// /// // For dtn addresses /// let dtn_addr_1 = EndpointID::with_dtn( "//node1/incoming").unwrap(); /// let dtn_addr_2 = EndpointID::with_dtn( "//node1/inbox").unwrap(); /// /// assert_eq!(dtn_addr_1, dtn_addr_2.new_endpoint("incoming").unwrap()); + /// assert_eq!(dtn_addr_1.node_id(), Some("dtn://node1/".to_string())); /// /// // For non endpoint this is not possible /// @@ -344,7 +346,8 @@ impl EndpointID { pub fn node_id(&self) -> Option { match self { EndpointID::DtnNone(_, _) => None, - _ => Some(format!("{}://{}/", self.scheme(), self.node()?)), + EndpointID::Ipn(_, ssp) => Some(format!("{}:{}.0", self.scheme(), ssp.node_number())), + EndpointID::Dtn(_, ssp) => Some(format!("{}://{}/", self.scheme(), ssp.node_name())), } } @@ -352,7 +355,7 @@ impl EndpointID { match self { EndpointID::DtnNone(_, _) => false, EndpointID::Dtn(_, eid) => eid.service_name().is_none(), - EndpointID::Ipn(_, addr) => addr.1 == 0, + EndpointID::Ipn(_, addr) => addr.service_number() == 0, } } pub fn service_name(&self) -> Option { diff --git a/src/helpers.rs b/src/helpers.rs index 5f88698..fddfcbb 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -82,8 +82,8 @@ pub fn vec_dump(input: &T, cbor: Vec, hr: &str) { } pub fn rnd_bundle(now: dtntime::CreationTimestamp) -> bundle::Bundle { let mut rng = WyRand::new(); - let singletons = vec!["sms", "files", "123456", "incoming", "mavlink"]; - let groups = vec!["~news", "~tele", "~mavlink"]; + let singletons = ["sms", "files", "123456", "incoming", "mavlink"]; + let groups = ["~news", "~tele", "~mavlink"]; //rng.shuffle(&mut singletons); //rng.shuffle(&mut groups); let concatenated = [&singletons[..], &groups[..]].concat();