more refactor
This commit is contained in:
@@ -79,6 +79,21 @@ pub fn decode_node_info(reader: &veilid_capnp::node_info::Reader) -> Result<Node
|
||||
.map(|s| s.to_vec())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Ensure envelope versions are not duplicated
|
||||
// Unsorted is okay, some nodes may have a different envelope order preference
|
||||
// But nothing should show up more than once
|
||||
let mut eversions = envelope_support.clone();
|
||||
eversions.dedup();
|
||||
if eversions.len() != envelope_support.len() {
|
||||
return Err(RPCError::protocol("duplicate envelope versions"));
|
||||
}
|
||||
if envelope_support.len() > MAX_ENVELOPE_VERSIONS {
|
||||
return Err(RPCError::protocol("too many envelope versions"));
|
||||
}
|
||||
if envelope_support.len() == 0 {
|
||||
return Err(RPCError::protocol("no envelope versions"));
|
||||
}
|
||||
|
||||
let crypto_support: Vec<CryptoKind> = reader
|
||||
.reborrow()
|
||||
.get_crypto_support()
|
||||
@@ -87,6 +102,21 @@ pub fn decode_node_info(reader: &veilid_capnp::node_info::Reader) -> Result<Node
|
||||
.map(|s| s.iter().map(|x| FourCC::from(x.to_be_bytes())).collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
// Ensure crypto kinds are not duplicated
|
||||
// Unsorted is okay, some nodes may have a different crypto order preference
|
||||
// But nothing should show up more than once
|
||||
let mut ckinds = crypto_support.clone();
|
||||
ckinds.dedup();
|
||||
if ckinds.len() != crypto_support.len() {
|
||||
return Err(RPCError::protocol("duplicate crypto kinds"));
|
||||
}
|
||||
if crypto_support.len() > MAX_CRYPTO_KINDS {
|
||||
return Err(RPCError::protocol("too many crypto kinds"));
|
||||
}
|
||||
if crypto_support.len() == 0 {
|
||||
return Err(RPCError::protocol("no crypto kinds"));
|
||||
}
|
||||
|
||||
let didl_reader = reader
|
||||
.reborrow()
|
||||
.get_dial_info_detail_list()
|
||||
|
@@ -43,8 +43,10 @@ pub fn decode_peer_info(
|
||||
for nid_reader in nids_reader.iter() {
|
||||
node_ids.add(decode_typed_key(&nid_reader)?);
|
||||
}
|
||||
let signed_node_info = decode_signed_node_info(&sni_reader, crypto, &node_ids)?;
|
||||
|
||||
let signed_node_info = decode_signed_node_info(&sni_reader, crypto, &mut node_ids)?;
|
||||
if node_ids.len() == 0 {
|
||||
return Err(RPCError::protocol("no verified node ids"));
|
||||
}
|
||||
Ok(PeerInfo {
|
||||
node_ids,
|
||||
signed_node_info,
|
||||
|
@@ -35,7 +35,7 @@ pub fn encode_signed_direct_node_info(
|
||||
pub fn decode_signed_direct_node_info(
|
||||
reader: &veilid_capnp::signed_direct_node_info::Reader,
|
||||
crypto: Crypto,
|
||||
node_ids: &[TypedKey],
|
||||
node_ids: &mut TypedKeySet,
|
||||
) -> Result<SignedDirectNodeInfo, RPCError> {
|
||||
let ni_reader = reader
|
||||
.reborrow()
|
||||
|
@@ -21,7 +21,7 @@ pub fn encode_signed_node_info(
|
||||
pub fn decode_signed_node_info(
|
||||
reader: &veilid_capnp::signed_node_info::Reader,
|
||||
crypto: Crypto,
|
||||
node_ids: &[TypedKey],
|
||||
node_ids: &mut TypedKeySet,
|
||||
) -> Result<SignedNodeInfo, RPCError> {
|
||||
match reader
|
||||
.which()
|
||||
|
@@ -55,7 +55,7 @@ pub fn encode_signed_relayed_node_info(
|
||||
pub fn decode_signed_relayed_node_info(
|
||||
reader: &veilid_capnp::signed_relayed_node_info::Reader,
|
||||
crypto: Crypto,
|
||||
node_ids: &[TypedKey],
|
||||
node_ids: &mut TypedKeySet,
|
||||
) -> Result<SignedRelayedNodeInfo, RPCError> {
|
||||
let ni_reader = reader
|
||||
.reborrow()
|
||||
@@ -81,7 +81,20 @@ pub fn decode_signed_relayed_node_info(
|
||||
.reborrow()
|
||||
.get_relay_info()
|
||||
.map_err(RPCError::protocol)?;
|
||||
let relay_info = decode_signed_direct_node_info(&ri_reader, crypto, &relay_ids)?;
|
||||
let relay_info = decode_signed_direct_node_info(&ri_reader, crypto, &mut relay_ids)?;
|
||||
|
||||
// Ensure the relay info for the node has a superset of the crypto kinds of the node it is relaying
|
||||
if common_crypto_kinds(
|
||||
&node_info.crypto_support,
|
||||
&relay_info.node_info.crypto_support,
|
||||
)
|
||||
.len()
|
||||
!= node_info.crypto_support.len()
|
||||
{
|
||||
return Err(RPCError::protocol(
|
||||
"relay should have superset of node crypto kinds",
|
||||
));
|
||||
}
|
||||
|
||||
let timestamp = reader.reborrow().get_timestamp().into();
|
||||
|
||||
|
@@ -15,7 +15,7 @@ pub enum Destination {
|
||||
/// The relay to send to
|
||||
relay: NodeRef,
|
||||
/// The final destination the relay should send to
|
||||
target: TypedKey,
|
||||
target: NodeRef,
|
||||
/// Require safety route or not
|
||||
safety_selection: SafetySelection,
|
||||
},
|
||||
@@ -36,7 +36,7 @@ impl Destination {
|
||||
safety_selection: SafetySelection::Unsafe(sequencing),
|
||||
}
|
||||
}
|
||||
pub fn relay(relay: NodeRef, target: TypedKey) -> Self {
|
||||
pub fn relay(relay: NodeRef, target: NodeRef) -> Self {
|
||||
let sequencing = relay.sequencing();
|
||||
Self::Relay {
|
||||
relay,
|
||||
@@ -124,7 +124,7 @@ impl fmt::Display for Destination {
|
||||
""
|
||||
};
|
||||
|
||||
write!(f, "{}@{}{}", target.encode(), relay, sr)
|
||||
write!(f, "{}@{}{}", target, relay, sr)
|
||||
}
|
||||
Destination::PrivateRoute {
|
||||
private_route,
|
||||
@@ -163,7 +163,7 @@ impl RPCProcessor {
|
||||
SafetySelection::Safe(safety_spec) => {
|
||||
// Sent directly but with a safety route, respond to private route
|
||||
let Some(pr_key) = rss
|
||||
.get_private_route_for_safety_spec(safety_spec, &[target.node_id()])
|
||||
.get_private_route_for_safety_spec(safety_spec, &target.node_ids())
|
||||
.map_err(RPCError::internal)? else {
|
||||
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
||||
};
|
||||
@@ -187,11 +187,13 @@ impl RPCProcessor {
|
||||
}
|
||||
SafetySelection::Safe(safety_spec) => {
|
||||
// Sent via a relay but with a safety route, respond to private route
|
||||
let mut avoid_nodes = relay.node_ids();
|
||||
avoid_nodes.add_all(&target.node_ids());
|
||||
let Some(pr_key) = rss
|
||||
.get_private_route_for_safety_spec(safety_spec, &[relay.node_id(), *target])
|
||||
.map_err(RPCError::internal)? else {
|
||||
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
||||
};
|
||||
.get_private_route_for_safety_spec(safety_spec, &avoid_nodes)
|
||||
.map_err(RPCError::internal)? else {
|
||||
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
||||
};
|
||||
|
||||
// Get the assembled route for response
|
||||
let private_route = rss
|
||||
@@ -209,6 +211,8 @@ impl RPCProcessor {
|
||||
return Err(RPCError::internal("destination private route must have first hop"));
|
||||
};
|
||||
|
||||
let crypto_kind = private_route.public_key.kind;
|
||||
|
||||
match safety_selection {
|
||||
SafetySelection::Unsafe(_) => {
|
||||
// Sent to a private route with no safety route, use a stub safety route for the response
|
||||
@@ -221,7 +225,7 @@ impl RPCProcessor {
|
||||
if !routing_table.has_valid_own_node_info(RoutingDomain::PublicInternet) {
|
||||
return Ok(NetworkResult::no_connection_other("Own node info must be valid to use private route"));
|
||||
}
|
||||
RouteNode::NodeId(NodeId::new(routing_table.node_id()))
|
||||
RouteNode::NodeId(routing_table.node_id(crypto_kind))
|
||||
}
|
||||
false => {
|
||||
let Some(own_peer_info) =
|
||||
@@ -233,7 +237,7 @@ impl RPCProcessor {
|
||||
};
|
||||
|
||||
Ok(NetworkResult::value(RespondTo::PrivateRoute(
|
||||
PrivateRoute::new_stub(routing_table.node_id(), route_node),
|
||||
PrivateRoute::new_stub(routing_table.node_id(crypto_kind), route_node),
|
||||
)))
|
||||
}
|
||||
SafetySelection::Safe(safety_spec) => {
|
||||
|
Reference in New Issue
Block a user