diff --git a/veilid-core/src/routing_table/routing_table_inner.rs b/veilid-core/src/routing_table/routing_table_inner.rs index d3b88cae..e82f9f9d 100644 --- a/veilid-core/src/routing_table/routing_table_inner.rs +++ b/veilid-core/src/routing_table/routing_table_inner.rs @@ -1054,8 +1054,8 @@ impl RoutingTableInner { nodes.sort_by(|a, b| compare(self, a, b)); // return transformed vector for filtered+sorted nodes - let cnt = usize::min(node_count, nodes.len()); - let mut out = Vec::::with_capacity(cnt); + nodes.truncate(node_count); + let mut out = Vec::::with_capacity(nodes.len()); for node in nodes { let val = transform(self, node); out.push(val); diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_find_node.rs b/veilid-core/src/rpc_processor/coders/operations/operation_find_node.rs index 10848648..5292d4fc 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_find_node.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_find_node.rs @@ -81,7 +81,9 @@ pub struct RPCOperationFindNodeA { impl RPCOperationFindNodeA { pub fn new(peers: Vec) -> Result { if peers.len() > MAX_FIND_NODE_A_PEERS_LEN { - return Err(RPCError::protocol("find node peers length too long")); + return Err(RPCError::protocol( + "encoded find node peers length too long", + )); } Ok(Self { peers }) @@ -106,7 +108,9 @@ impl RPCOperationFindNodeA { let peers_reader = reader.get_peers().map_err(RPCError::protocol)?; if peers_reader.len() as usize > MAX_FIND_NODE_A_PEERS_LEN { - return Err(RPCError::protocol("find node peers length too long")); + return Err(RPCError::protocol( + "decoded find node peers length too long", + )); } let mut peers = Vec::::with_capacity( diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs b/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs index 72224952..bc255bd3 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs @@ -89,7 +89,9 @@ impl RPCOperationGetValueA { descriptor: Option, ) -> Result { if peers.len() > MAX_GET_VALUE_A_PEERS_LEN { - return Err(RPCError::protocol("GetValueA peers length too long")); + return Err(RPCError::protocol( + "encoded GetValueA peers length too long", + )); } Ok(Self { value, @@ -175,7 +177,9 @@ impl RPCOperationGetValueA { let peers_reader = reader.get_peers().map_err(RPCError::protocol)?; if peers_reader.len() as usize > MAX_GET_VALUE_A_PEERS_LEN { - return Err(RPCError::protocol("GetValueA peers length too long")); + return Err(RPCError::protocol( + "decoded GetValueA peers length too long", + )); } let mut peers = Vec::::with_capacity( peers_reader diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_set_value.rs b/veilid-core/src/rpc_processor/coders/operations/operation_set_value.rs index c7fa4cf2..3ff5c71f 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_set_value.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_set_value.rs @@ -123,7 +123,9 @@ impl RPCOperationSetValueA { peers: Vec, ) -> Result { if peers.len() as usize > MAX_SET_VALUE_A_PEERS_LEN { - return Err(RPCError::protocol("SetValueA peers length too long")); + return Err(RPCError::protocol( + "encoded SetValueA peers length too long", + )); } Ok(Self { set, value, peers }) } @@ -182,7 +184,9 @@ impl RPCOperationSetValueA { }; let peers_reader = reader.get_peers().map_err(RPCError::protocol)?; if peers_reader.len() as usize > MAX_SET_VALUE_A_PEERS_LEN { - return Err(RPCError::protocol("SetValueA peers length too long")); + return Err(RPCError::protocol( + "decoded SetValueA peers length too long", + )); } let mut peers = Vec::::with_capacity( peers_reader