From 94d1598ce112bfb0262125bfae2a27467be1fa89 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 12 Nov 2022 21:29:43 -0500 Subject: [PATCH] remove node_dial_info --- veilid-core/proto/veilid.capnp | 5 -- veilid-core/src/crypto/key.rs | 6 +-- veilid-core/src/network_manager/tasks.rs | 18 ++++--- .../routing_table/routing_domain_editor.rs | 9 ++-- veilid-core/src/rpc_processor/coders/mod.rs | 2 - .../rpc_processor/coders/node_dial_info.rs | 29 ----------- veilid-core/src/veilid_api/mod.rs | 49 ------------------- veilid-server/src/settings.rs | 25 +++++++--- 8 files changed, 35 insertions(+), 108 deletions(-) delete mode 100644 veilid-core/src/rpc_processor/coders/node_dial_info.rs diff --git a/veilid-core/proto/veilid.capnp b/veilid-core/proto/veilid.capnp index c3f00bcf..3525da9f 100644 --- a/veilid-core/proto/veilid.capnp +++ b/veilid-core/proto/veilid.capnp @@ -102,11 +102,6 @@ struct DialInfo { } } -struct NodeDialInfo { - nodeId @0 :NodeID; # node id - dialInfo @1 :DialInfo; # how to get to the node -} - # Signals ############################## diff --git a/veilid-core/src/crypto/key.rs b/veilid-core/src/crypto/key.rs index d2e5f568..90f57297 100644 --- a/veilid-core/src/crypto/key.rs +++ b/veilid-core/src/crypto/key.rs @@ -150,10 +150,10 @@ macro_rules! byte_array_type { BASE64URL_NOPAD.encode(&self.bytes) } - pub fn try_decode(input: &str) -> Result { + pub fn try_decode>(input: S) -> Result { let mut bytes = [0u8; $size]; - let res = BASE64URL_NOPAD.decode_len(input.len()); + let res = BASE64URL_NOPAD.decode_len(input.as_ref().len()); match res { Ok(v) => { if v != $size { @@ -165,7 +165,7 @@ macro_rules! byte_array_type { } } - let res = BASE64URL_NOPAD.decode_mut(input.as_bytes(), &mut bytes); + let res = BASE64URL_NOPAD.decode_mut(input.as_ref().as_bytes(), &mut bytes); match res { Ok(_) => Ok(Self::new(bytes)), Err(_) => apibail_generic!("Failed to decode"), diff --git a/veilid-core/src/network_manager/tasks.rs b/veilid-core/src/network_manager/tasks.rs index 6ec80996..c9834645 100644 --- a/veilid-core/src/network_manager/tasks.rs +++ b/veilid-core/src/network_manager/tasks.rs @@ -256,14 +256,18 @@ impl NetworkManager { let mut bsmap = BootstrapRecordMap::new(); let mut bootstrap_node_dial_infos = Vec::new(); for b in bootstrap_nodes { - let ndis = NodeDialInfo::from_str(b.as_str()) - .wrap_err("Invalid node dial info in bootstrap entry")?; - bootstrap_node_dial_infos.push(ndis); + let (id_str, di_str) = b + .split_once('@') + .ok_or_else(|| eyre!("Invalid node dial info in bootstrap entry"))?; + let node_id = + NodeId::from_str(id_str).wrap_err("Invalid node id in bootstrap entry")?; + let dial_info = + DialInfo::from_str(di_str).wrap_err("Invalid dial info in bootstrap entry")?; + bootstrap_node_dial_infos.push((node_id, dial_info)); } - for ndi in bootstrap_node_dial_infos { - let node_id = ndi.node_id.key; + for (node_id, dial_info) in bootstrap_node_dial_infos { bsmap - .entry(node_id) + .entry(node_id.key) .or_insert_with(|| BootstrapRecord { min_version: MIN_CRYPTO_VERSION, max_version: MAX_CRYPTO_VERSION, @@ -271,7 +275,7 @@ impl NetworkManager { }) .dial_info_details .push(DialInfoDetail { - dial_info: ndi.dial_info, + dial_info, class: DialInfoClass::Direct, // Bootstraps are always directly reachable }); } diff --git a/veilid-core/src/routing_table/routing_domain_editor.rs b/veilid-core/src/routing_table/routing_domain_editor.rs index 60e76509..b9150196 100644 --- a/veilid-core/src/routing_table/routing_domain_editor.rs +++ b/veilid-core/src/routing_table/routing_domain_editor.rs @@ -139,13 +139,10 @@ impl RoutingDomainEditor { .add_dial_info_detail(dial_info_detail.clone()); info!( - "{:?} Dial Info: {}", + "{:?} Dial Info: {}@{}", self.routing_domain, - NodeDialInfo { - node_id: NodeId::new(node_id), - dial_info: dial_info_detail.dial_info - } - .to_string(), + NodeId::new(node_id), + dial_info_detail.dial_info ); changed = true; } diff --git a/veilid-core/src/rpc_processor/coders/mod.rs b/veilid-core/src/rpc_processor/coders/mod.rs index 3211b338..ccc6dc17 100644 --- a/veilid-core/src/rpc_processor/coders/mod.rs +++ b/veilid-core/src/rpc_processor/coders/mod.rs @@ -5,7 +5,6 @@ mod dial_info; mod dial_info_class; mod dial_info_detail; mod network_class; -mod node_dial_info; mod node_info; mod node_status; mod nonce; @@ -32,7 +31,6 @@ pub use dial_info::*; pub use dial_info_class::*; pub use dial_info_detail::*; pub use network_class::*; -pub use node_dial_info::*; pub use node_info::*; pub use node_status::*; pub use nonce::*; diff --git a/veilid-core/src/rpc_processor/coders/node_dial_info.rs b/veilid-core/src/rpc_processor/coders/node_dial_info.rs deleted file mode 100644 index 47ae96ad..00000000 --- a/veilid-core/src/rpc_processor/coders/node_dial_info.rs +++ /dev/null @@ -1,29 +0,0 @@ -use crate::*; -use rpc_processor::*; - -pub fn encode_node_dial_info( - ndis: &NodeDialInfo, - builder: &mut veilid_capnp::node_dial_info::Builder, -) -> Result<(), RPCError> { - let mut ni_builder = builder.reborrow().init_node_id(); - encode_public_key(&ndis.node_id.key, &mut ni_builder)?; - let mut di_builder = builder.reborrow().init_dial_info(); - encode_dial_info(&ndis.dial_info, &mut di_builder)?; - Ok(()) -} - -pub fn decode_node_dial_info( - reader: &veilid_capnp::node_dial_info::Reader, -) -> Result { - let node_id = decode_public_key(&reader.get_node_id().map_err(RPCError::map_protocol( - "invalid public key in node_dial_info", - ))?); - let dial_info = decode_dial_info(&reader.get_dial_info().map_err(RPCError::map_protocol( - "invalid dial_info in node_dial_info", - ))?)?; - - Ok(NodeDialInfo { - node_id: NodeId::new(node_id), - dial_info, - }) -} diff --git a/veilid-core/src/veilid_api/mod.rs b/veilid-core/src/veilid_api/mod.rs index bf2ac7b6..69348803 100644 --- a/veilid-core/src/veilid_api/mod.rs +++ b/veilid-core/src/veilid_api/mod.rs @@ -2350,55 +2350,6 @@ impl MatchesDialInfoFilter for ConnectionDescriptor { ////////////////////////////////////////////////////////////////////////// -#[derive( - Clone, - Debug, - Default, - Eq, - PartialEq, - PartialOrd, - Ord, - Serialize, - Deserialize, - RkyvArchive, - RkyvSerialize, - RkyvDeserialize, -)] -#[archive_attr(repr(C), derive(CheckBytes))] -pub struct NodeDialInfo { - pub node_id: NodeId, - pub dial_info: DialInfo, -} - -impl fmt::Display for NodeDialInfo { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { - write!(f, "{}@{}", self.node_id, self.dial_info) - } -} - -impl FromStr for NodeDialInfo { - type Err = VeilidAPIError; - fn from_str(s: &str) -> Result { - // split out node id from the dial info - let (node_id_str, rest) = s.split_once('@').ok_or_else(|| { - VeilidAPIError::parse_error("NodeDialInfo::from_str missing @ node id separator", s) - })?; - - // parse out node id - let node_id = NodeId::new(DHTKey::try_decode(node_id_str).map_err(|e| { - VeilidAPIError::parse_error( - format!("NodeDialInfo::from_str couldn't parse node id: {}", e), - s, - ) - })?); - // parse out dial info - let dial_info = DialInfo::from_str(rest)?; - - // return completed NodeDialInfo - Ok(NodeDialInfo { node_id, dial_info }) - } -} - #[derive( Clone, Debug, diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index d02d7d77..4c6b4135 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -307,16 +307,16 @@ impl serde::Serialize for ParsedUrl { #[derive(Debug, Clone, PartialEq)] pub struct ParsedNodeDialInfo { pub node_dial_info_string: String, - pub node_dial_info: veilid_core::NodeDialInfo, + pub node_id: NodeId, + pub dial_info: DialInfo, } // impl ParsedNodeDialInfo { // pub fn offset_port(&mut self, offset: u16) -> Result<(), ()> { // // Bump port on dial_info -// self.node_dial_info -// .dial_info -// .set_port(self.node_dial_info.dial_info.port() + 1); -// self.node_dial_info_string = self.node_dial_info.to_string(); +// self.dial_info +// .set_port(self.dial_info.port() + 1); +// self.node_dial_info_string = format!("{}@{}",self.node_id, self.dial_info); // Ok(()) // } // } @@ -326,10 +326,21 @@ impl FromStr for ParsedNodeDialInfo { fn from_str( node_dial_info_string: &str, ) -> Result { - let node_dial_info = veilid_core::NodeDialInfo::from_str(node_dial_info_string)?; + let (id_str, di_str) = node_dial_info_string.split_once('@').ok_or_else(|| { + VeilidAPIError::invalid_argument( + "Invalid node dial info in bootstrap entry", + "node_dial_info_string", + node_dial_info_string, + ) + })?; + let node_id = NodeId::from_str(id_str) + .map_err(|e| VeilidAPIError::invalid_argument(e, "node_id", id_str))?; + let dial_info = DialInfo::from_str(di_str) + .map_err(|e| VeilidAPIError::invalid_argument(e, "dial_info", id_str))?; Ok(Self { node_dial_info_string: node_dial_info_string.to_owned(), - node_dial_info, + node_id, + dial_info, }) } }