more dialinfodetail refactor
This commit is contained in:
@@ -6,7 +6,7 @@ pub fn encode_dial_info_detail(
|
||||
builder: &mut veilid_capnp::dial_info_detail::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
let mut di_builder = builder.reborrow().init_dial_info();
|
||||
encode_dial_info(&node_info.dial_info, &mut di_builder)?;
|
||||
encode_dial_info(&dial_info_detail.dial_info, &mut di_builder)?;
|
||||
|
||||
builder.set_class(encode_dial_info_class(dial_info_detail.class));
|
||||
Ok(())
|
||||
@@ -22,7 +22,7 @@ pub fn decode_dial_info_detail(
|
||||
.map_err(map_error_capnp_error!())?,
|
||||
)?;
|
||||
|
||||
let dial_info_class = decode_dial_info_class(
|
||||
let class = decode_dial_info_class(
|
||||
reader
|
||||
.reborrow()
|
||||
.get_class()
|
||||
|
@@ -2,26 +2,17 @@ use crate::*;
|
||||
|
||||
pub fn encode_network_class(network_class: NetworkClass) -> veilid_capnp::NetworkClass {
|
||||
match network_class {
|
||||
NetworkClass::Server => veilid_capnp::NetworkClass::Server,
|
||||
NetworkClass::Mapped => veilid_capnp::NetworkClass::Mapped,
|
||||
NetworkClass::FullConeNAT => veilid_capnp::NetworkClass::FullConeNAT,
|
||||
NetworkClass::AddressRestrictedNAT => veilid_capnp::NetworkClass::AddressRestrictedNAT,
|
||||
NetworkClass::PortRestrictedNAT => veilid_capnp::NetworkClass::PortRestrictedNAT,
|
||||
NetworkClass::InboundCapable => veilid_capnp::NetworkClass::InboundCapable,
|
||||
NetworkClass::OutboundOnly => veilid_capnp::NetworkClass::OutboundOnly,
|
||||
NetworkClass::WebApp => veilid_capnp::NetworkClass::WebApp,
|
||||
NetworkClass::Invalid => veilid_capnp::NetworkClass::Invalid,
|
||||
NetworkClass::Invalid => panic!("invalid network class should not be encoded"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_network_class(network_class: veilid_capnp::NetworkClass) -> NetworkClass {
|
||||
match network_class {
|
||||
veilid_capnp::NetworkClass::Server => NetworkClass::Server,
|
||||
veilid_capnp::NetworkClass::Mapped => NetworkClass::Mapped,
|
||||
veilid_capnp::NetworkClass::FullConeNAT => NetworkClass::FullConeNAT,
|
||||
veilid_capnp::NetworkClass::AddressRestrictedNAT => NetworkClass::AddressRestrictedNAT,
|
||||
veilid_capnp::NetworkClass::PortRestrictedNAT => NetworkClass::PortRestrictedNAT,
|
||||
veilid_capnp::NetworkClass::InboundCapable => NetworkClass::InboundCapable,
|
||||
veilid_capnp::NetworkClass::OutboundOnly => NetworkClass::OutboundOnly,
|
||||
veilid_capnp::NetworkClass::WebApp => NetworkClass::WebApp,
|
||||
veilid_capnp::NetworkClass::Invalid => NetworkClass::Invalid,
|
||||
}
|
||||
}
|
||||
|
@@ -55,14 +55,14 @@ pub fn decode_node_info(
|
||||
.reborrow()
|
||||
.get_dial_info_detail_list()
|
||||
.map_err(map_error_capnp_error!())?;
|
||||
let mut dial_info_detail_list = Vec::<DialInfo>::with_capacity(
|
||||
let mut dial_info_detail_list = Vec::<DialInfoDetail>::with_capacity(
|
||||
didl_reader
|
||||
.len()
|
||||
.try_into()
|
||||
.map_err(map_error_protocol!("too many dial info details"))?,
|
||||
);
|
||||
for di in dil_reader.iter() {
|
||||
dial_info_detail_list.push(decode_dial_info_detail(&di)?)
|
||||
for did in didl_reader.iter() {
|
||||
dial_info_detail_list.push(decode_dial_info_detail(&did)?)
|
||||
}
|
||||
|
||||
let relay_peer_info = if allow_relay_peer_info {
|
||||
|
@@ -204,26 +204,8 @@ impl RPCProcessor {
|
||||
return format!("(invalid node id: {})", e);
|
||||
}
|
||||
};
|
||||
|
||||
let sni_reader = match fnqr.reborrow().get_sender_node_info() {
|
||||
Ok(snir) => snir,
|
||||
Err(e) => {
|
||||
return format!("(invalid sender node info: {})", e);
|
||||
}
|
||||
};
|
||||
let sender_node_info = match decode_node_info(&sni_reader, true) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
return format!("(unable to decode node info: {})", e);
|
||||
}
|
||||
};
|
||||
|
||||
let node_id = decode_public_key(&nidr);
|
||||
format!(
|
||||
"FindNodeQ: node_id={} sender_node_info={:#?}",
|
||||
node_id.encode(),
|
||||
sender_node_info
|
||||
)
|
||||
format!("FindNodeQ: node_id={}", node_id.encode(),)
|
||||
}
|
||||
veilid_capnp::operation::detail::FindNodeA(d) => {
|
||||
let fnar = match d {
|
||||
@@ -236,7 +218,7 @@ impl RPCProcessor {
|
||||
let p_reader = match fnar.reborrow().get_peers() {
|
||||
Ok(pr) => pr,
|
||||
Err(e) => {
|
||||
return format!("(invalid sender node info: {})", e);
|
||||
return format!("(invalid peers: {})", e);
|
||||
}
|
||||
};
|
||||
let mut peers = Vec::<PeerInfo>::with_capacity(match p_reader.len().try_into() {
|
||||
|
@@ -213,22 +213,22 @@ impl RPCProcessor {
|
||||
get_random_u64()
|
||||
}
|
||||
|
||||
fn filter_peer_scope(&self, peer_info: &PeerInfo) -> bool {
|
||||
fn filter_peer_scope(&self, node_info: &NodeInfo) -> bool {
|
||||
// if local peer scope is enabled, then don't reject any peer info
|
||||
if self.enable_local_peer_scope {
|
||||
return true;
|
||||
}
|
||||
|
||||
// reject attempts to include non-public addresses in results
|
||||
for di in &peer_info.node_info.dial_info_list {
|
||||
if !di.is_global() {
|
||||
for did in &node_info.dial_info_detail_list {
|
||||
if !did.dial_info.is_global() {
|
||||
// non-public address causes rejection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(rpi) = &peer_info.node_info.relay_peer_info {
|
||||
for di in &rpi.node_info.dial_info_list {
|
||||
if !di.is_global() {
|
||||
if let Some(rpi) = &node_info.relay_peer_info {
|
||||
for did in &rpi.node_info.dial_info_detail_list {
|
||||
if !did.dial_info.is_global() {
|
||||
// non-public address causes rejection
|
||||
return false;
|
||||
}
|
||||
@@ -964,26 +964,8 @@ impl RPCProcessor {
|
||||
.map_err(logthru_rpc!())?,
|
||||
);
|
||||
|
||||
// get the sender NodeInfo of the requesting node
|
||||
let sni_reader = fnq_reader
|
||||
.reborrow()
|
||||
.get_sender_node_info()
|
||||
.map_err(map_error_capnp_error!())?;
|
||||
let peer_info = PeerInfo {
|
||||
node_id: NodeId::new(rpcreader.header.envelope.get_sender_id()),
|
||||
node_info: decode_node_info(&sni_reader, true)?,
|
||||
};
|
||||
|
||||
// filter out attempts to pass non-public addresses in for peers
|
||||
if !self.filter_peer_scope(&peer_info) {
|
||||
return Err(RPCError::InvalidFormat);
|
||||
}
|
||||
|
||||
// add node information for the requesting node to our routing table
|
||||
let routing_table = self.routing_table();
|
||||
let _requesting_node_ref = routing_table
|
||||
.register_node_with_node_info(peer_info.node_id.key, peer_info.node_info)
|
||||
.map_err(map_error_string!())?;
|
||||
|
||||
// find N nodes closest to the target node in our routing table
|
||||
let own_peer_info = routing_table.get_own_peer_info();
|
||||
@@ -1192,6 +1174,9 @@ impl RPCProcessor {
|
||||
opt_sender_nr =
|
||||
if let Some(sender_ni) = self.get_respond_to_sender_node_info(&operation)? {
|
||||
// Sender NodeInfo was specified, update our routing table with it
|
||||
if !self.filter_peer_scope(&sender_ni) {
|
||||
return Err(RPCError::InvalidFormat);
|
||||
}
|
||||
let nr = self
|
||||
.routing_table()
|
||||
.register_node_with_node_info(
|
||||
@@ -1544,11 +1529,6 @@ impl RPCProcessor {
|
||||
let mut node_id_builder = fnq.reborrow().init_node_id();
|
||||
encode_public_key(&key, &mut node_id_builder)?;
|
||||
|
||||
let own_peer_info = self.routing_table().get_own_peer_info();
|
||||
|
||||
let mut ni_builder = fnq.reborrow().init_sender_node_info();
|
||||
encode_node_info(&own_peer_info.node_info, &mut ni_builder)?;
|
||||
|
||||
find_node_q_msg.into_reader()
|
||||
};
|
||||
|
||||
@@ -1590,7 +1570,7 @@ impl RPCProcessor {
|
||||
for p in peers_reader.iter() {
|
||||
let peer_info = decode_peer_info(&p, true)?;
|
||||
|
||||
if !self.filter_peer_scope(&peer_info) {
|
||||
if !self.filter_peer_scope(&peer_info.node_info) {
|
||||
return Err(RPCError::InvalidFormat);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user