fix crash
This commit is contained in:
@@ -13,6 +13,9 @@ impl RoutingTable {
|
||||
"Not finding closest peers because our network class is still invalid",
|
||||
);
|
||||
}
|
||||
if Crypto::validate_crypto_kind(key.kind).is_err() {
|
||||
return NetworkResult::invalid_message("invalid crypto kind");
|
||||
}
|
||||
|
||||
// find N nodes closest to the target node in our routing table
|
||||
let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet);
|
||||
@@ -46,7 +49,7 @@ impl RoutingTable {
|
||||
};
|
||||
|
||||
let own_peer_info = self.get_own_peer_info(RoutingDomain::PublicInternet);
|
||||
let closest_nodes = self.find_closest_nodes(
|
||||
let closest_nodes = match self.find_closest_nodes(
|
||||
node_count,
|
||||
key,
|
||||
filters,
|
||||
@@ -54,7 +57,13 @@ impl RoutingTable {
|
||||
|rti, entry| {
|
||||
rti.transform_to_peer_info(RoutingDomain::PublicInternet, &own_peer_info, entry)
|
||||
},
|
||||
);
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("failed to find closest nodes for key {}: {}", key, e);
|
||||
return NetworkResult::invalid_message("failed to find closest nodes for key");
|
||||
}
|
||||
};
|
||||
|
||||
NetworkResult::value(closest_nodes)
|
||||
}
|
||||
@@ -117,7 +126,7 @@ impl RoutingTable {
|
||||
};
|
||||
|
||||
//
|
||||
let closest_nodes = self.find_closest_nodes(
|
||||
let closest_nodes = match self.find_closest_nodes(
|
||||
node_count,
|
||||
key,
|
||||
filters,
|
||||
@@ -127,7 +136,13 @@ impl RoutingTable {
|
||||
e.make_peer_info(RoutingDomain::PublicInternet).unwrap()
|
||||
})
|
||||
},
|
||||
);
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(e) => {
|
||||
error!("failed to find closest nodes for key {}: {}", key, e);
|
||||
return NetworkResult::invalid_message("failed to find closest nodes for key");
|
||||
}
|
||||
};
|
||||
|
||||
// Validate peers returned are, in fact, closer to the key than the node we sent this to
|
||||
// This same test is used on the other side so we vet things here
|
||||
|
@@ -1012,7 +1012,7 @@ impl RoutingTable {
|
||||
node_id: TypedKey,
|
||||
filters: VecDeque<RoutingTableEntryFilter>,
|
||||
transform: T,
|
||||
) -> Vec<O>
|
||||
) -> VeilidAPIResult<Vec<O>>
|
||||
where
|
||||
T: for<'r> FnMut(&'r RoutingTableInner, Option<Arc<BucketEntry>>) -> O + Send,
|
||||
{
|
||||
|
@@ -1162,7 +1162,7 @@ impl RoutingTableInner {
|
||||
node_id: TypedKey,
|
||||
mut filters: VecDeque<RoutingTableEntryFilter>,
|
||||
transform: T,
|
||||
) -> Vec<O>
|
||||
) -> VeilidAPIResult<Vec<O>>
|
||||
where
|
||||
T: for<'r> FnMut(&'r RoutingTableInner, Option<Arc<BucketEntry>>) -> O,
|
||||
{
|
||||
@@ -1170,7 +1170,9 @@ impl RoutingTableInner {
|
||||
|
||||
// Get the crypto kind
|
||||
let crypto_kind = node_id.kind;
|
||||
let vcrypto = self.unlocked_inner.crypto().get(crypto_kind).unwrap();
|
||||
let Some(vcrypto) = self.unlocked_inner.crypto().get(crypto_kind) else {
|
||||
apibail_generic!("invalid crypto kind");
|
||||
};
|
||||
|
||||
// Filter to ensure entries support the crypto kind in use
|
||||
let filter = Box::new(
|
||||
@@ -1236,7 +1238,7 @@ impl RoutingTableInner {
|
||||
let out =
|
||||
self.find_peers_with_sort_and_filter(node_count, cur_ts, filters, sort, transform);
|
||||
log_rtab!(">> find_closest_nodes: node count = {}", out.len());
|
||||
out
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub fn sort_and_clean_closest_noderefs(
|
||||
|
Reference in New Issue
Block a user