mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
remove node_dial_info
This commit is contained in:
parent
53b52848b5
commit
94d1598ce1
@ -102,11 +102,6 @@ struct DialInfo {
|
||||
}
|
||||
}
|
||||
|
||||
struct NodeDialInfo {
|
||||
nodeId @0 :NodeID; # node id
|
||||
dialInfo @1 :DialInfo; # how to get to the node
|
||||
}
|
||||
|
||||
# Signals
|
||||
##############################
|
||||
|
||||
|
@ -150,10 +150,10 @@ macro_rules! byte_array_type {
|
||||
BASE64URL_NOPAD.encode(&self.bytes)
|
||||
}
|
||||
|
||||
pub fn try_decode(input: &str) -> Result<Self, VeilidAPIError> {
|
||||
pub fn try_decode<S: AsRef<str>>(input: S) -> Result<Self, VeilidAPIError> {
|
||||
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"),
|
||||
|
@ -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
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
@ -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<NodeDialInfo, RPCError> {
|
||||
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,
|
||||
})
|
||||
}
|
@ -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<NodeDialInfo, VeilidAPIError> {
|
||||
// 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,
|
||||
|
@ -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<ParsedNodeDialInfo, veilid_core::VeilidAPIError> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user