Merge branch 'veilidchat-work' into 'main'
fix nodes length issue See merge request veilid/veilid!99
This commit is contained in:
commit
8841473184
@ -1054,8 +1054,8 @@ impl RoutingTableInner {
|
|||||||
nodes.sort_by(|a, b| compare(self, a, b));
|
nodes.sort_by(|a, b| compare(self, a, b));
|
||||||
|
|
||||||
// return transformed vector for filtered+sorted nodes
|
// return transformed vector for filtered+sorted nodes
|
||||||
let cnt = usize::min(node_count, nodes.len());
|
nodes.truncate(node_count);
|
||||||
let mut out = Vec::<O>::with_capacity(cnt);
|
let mut out = Vec::<O>::with_capacity(nodes.len());
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
let val = transform(self, node);
|
let val = transform(self, node);
|
||||||
out.push(val);
|
out.push(val);
|
||||||
|
@ -81,7 +81,9 @@ pub struct RPCOperationFindNodeA {
|
|||||||
impl RPCOperationFindNodeA {
|
impl RPCOperationFindNodeA {
|
||||||
pub fn new(peers: Vec<PeerInfo>) -> Result<Self, RPCError> {
|
pub fn new(peers: Vec<PeerInfo>) -> Result<Self, RPCError> {
|
||||||
if peers.len() > MAX_FIND_NODE_A_PEERS_LEN {
|
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 })
|
Ok(Self { peers })
|
||||||
@ -106,7 +108,9 @@ impl RPCOperationFindNodeA {
|
|||||||
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
||||||
|
|
||||||
if peers_reader.len() as usize > MAX_FIND_NODE_A_PEERS_LEN {
|
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(
|
let mut peers = Vec::<PeerInfo>::with_capacity(
|
||||||
|
@ -89,7 +89,9 @@ impl RPCOperationGetValueA {
|
|||||||
descriptor: Option<SignedValueDescriptor>,
|
descriptor: Option<SignedValueDescriptor>,
|
||||||
) -> Result<Self, RPCError> {
|
) -> Result<Self, RPCError> {
|
||||||
if peers.len() > MAX_GET_VALUE_A_PEERS_LEN {
|
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 {
|
Ok(Self {
|
||||||
value,
|
value,
|
||||||
@ -175,7 +177,9 @@ impl RPCOperationGetValueA {
|
|||||||
|
|
||||||
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
||||||
if peers_reader.len() as usize > MAX_GET_VALUE_A_PEERS_LEN {
|
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(
|
let mut peers = Vec::<PeerInfo>::with_capacity(
|
||||||
peers_reader
|
peers_reader
|
||||||
|
@ -123,7 +123,9 @@ impl RPCOperationSetValueA {
|
|||||||
peers: Vec<PeerInfo>,
|
peers: Vec<PeerInfo>,
|
||||||
) -> Result<Self, RPCError> {
|
) -> Result<Self, RPCError> {
|
||||||
if peers.len() as usize > MAX_SET_VALUE_A_PEERS_LEN {
|
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 })
|
Ok(Self { set, value, peers })
|
||||||
}
|
}
|
||||||
@ -182,7 +184,9 @@ impl RPCOperationSetValueA {
|
|||||||
};
|
};
|
||||||
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
let peers_reader = reader.get_peers().map_err(RPCError::protocol)?;
|
||||||
if peers_reader.len() as usize > MAX_SET_VALUE_A_PEERS_LEN {
|
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(
|
let mut peers = Vec::<PeerInfo>::with_capacity(
|
||||||
peers_reader
|
peers_reader
|
||||||
|
Loading…
Reference in New Issue
Block a user