fix fox nodes length issue

This commit is contained in:
Christien Rioux 2023-07-22 15:37:15 -04:00
parent fe8e963af7
commit cff955782b
4 changed files with 20 additions and 8 deletions

View File

@ -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::<O>::with_capacity(cnt);
nodes.truncate(node_count);
let mut out = Vec::<O>::with_capacity(nodes.len());
for node in nodes {
let val = transform(self, node);
out.push(val);

View File

@ -81,7 +81,9 @@ pub struct RPCOperationFindNodeA {
impl RPCOperationFindNodeA {
pub fn new(peers: Vec<PeerInfo>) -> Result<Self, RPCError> {
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::<PeerInfo>::with_capacity(

View File

@ -89,7 +89,9 @@ impl RPCOperationGetValueA {
descriptor: Option<SignedValueDescriptor>,
) -> Result<Self, RPCError> {
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::<PeerInfo>::with_capacity(
peers_reader

View File

@ -123,7 +123,9 @@ impl RPCOperationSetValueA {
peers: Vec<PeerInfo>,
) -> Result<Self, RPCError> {
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::<PeerInfo>::with_capacity(
peers_reader