Skip to content

Commit

Permalink
fix(eid): calling node_id() on an IPN eid now returns correct URL ins…
Browse files Browse the repository at this point in the history
…tead of an dtn scheme formatted IPN address
  • Loading branch information
gh0st42 committed Nov 24, 2023
1 parent 203cfef commit 04bbb3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/eid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down Expand Up @@ -344,15 +346,16 @@ impl EndpointID {
pub fn node_id(&self) -> Option<String> {
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())),
}
}

pub fn is_node_id(&self) -> bool {
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<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ pub fn vec_dump<T: serde::ser::Serialize>(input: &T, cbor: Vec<u8>, 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();
Expand Down

0 comments on commit 04bbb3a

Please sign in to comment.