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();
|
||||
|
||||
|
Reference in New Issue
Block a user