refactor checkpoint
This commit is contained in:
@@ -12,7 +12,7 @@ mod stats_accounting;
|
||||
mod tasks;
|
||||
mod types;
|
||||
|
||||
use crate::*;
|
||||
use super::*;
|
||||
|
||||
use crate::crypto::*;
|
||||
use crate::network_manager::*;
|
||||
|
@@ -25,13 +25,7 @@ impl RouteNode {
|
||||
pub fn validate(&self, crypto: Crypto) -> Result<(), VeilidAPIError> {
|
||||
match self {
|
||||
RouteNode::NodeId(_) => Ok(()),
|
||||
RouteNode::PeerInfo(pi) => {
|
||||
let validated_node_ids = pi.validate(crypto)?;
|
||||
if validated_node_ids.is_empty() {
|
||||
apibail_generic!("no validated node ids for route node");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
RouteNode::PeerInfo(pi) => pi.validate(crypto),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -117,7 +117,7 @@ impl RoutingDomainDetailCommon {
|
||||
.and_then(|rn| {
|
||||
let opt_relay_pi = rn.locked(rti).make_peer_info(self.routing_domain);
|
||||
if let Some(relay_pi) = opt_relay_pi {
|
||||
let (relay_ids, relay_sni) = relay_pi.into_fields();
|
||||
let (relay_ids, relay_sni) = relay_pi.destructure();
|
||||
match relay_sni {
|
||||
SignedNodeInfo::Direct(d) => Some((relay_ids, d)),
|
||||
SignedNodeInfo::Relayed(_) => {
|
||||
|
@@ -835,8 +835,9 @@ impl RoutingTableInner {
|
||||
}
|
||||
}
|
||||
|
||||
self.create_node_ref(outer_self, peer_info.node_ids(), |_rti, e| {
|
||||
e.update_signed_node_info(routing_domain, peer_info.into_signed_node_info());
|
||||
let (node_ids, signed_node_info) = peer_info.destructure();
|
||||
self.create_node_ref(outer_self, &node_ids, |_rti, e| {
|
||||
e.update_signed_node_info(routing_domain, signed_node_info);
|
||||
})
|
||||
.map(|mut nr| {
|
||||
nr.set_filter(Some(
|
||||
|
@@ -16,8 +16,13 @@ impl PeerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate(&self, crypto: Crypto) -> Result<TypedKeySet, VeilidAPIError> {
|
||||
self.signed_node_info.validate(&self.node_ids, crypto)
|
||||
pub fn validate(&self, crypto: Crypto) -> Result<(), VeilidAPIError> {
|
||||
let validated_node_ids = self.signed_node_info.validate(&self.node_ids, crypto)?;
|
||||
if validated_node_ids.is_empty() {
|
||||
// Shouldn't get here because signed node info validation also checks this
|
||||
apibail_generic!("no validated node ids");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn node_ids(&self) -> &TypedKeySet {
|
||||
@@ -26,10 +31,19 @@ impl PeerInfo {
|
||||
pub fn signed_node_info(&self) -> &SignedNodeInfo {
|
||||
&self.signed_node_info
|
||||
}
|
||||
pub fn into_signed_node_info(self) -> SignedNodeInfo {
|
||||
self.signed_node_info
|
||||
}
|
||||
pub fn into_fields(self) -> (TypedKeySet, SignedNodeInfo) {
|
||||
pub fn destructure(self) -> (TypedKeySet, SignedNodeInfo) {
|
||||
(self.node_ids, self.signed_node_info)
|
||||
}
|
||||
|
||||
pub fn validate_vec(peer_info_vec: &mut Vec<PeerInfo>, crypto: Crypto) {
|
||||
let mut n = 0usize;
|
||||
while n < peer_info_vec.len() {
|
||||
let pi = peer_info_vec.get(n).unwrap();
|
||||
if pi.validate(crypto.clone()).is_err() {
|
||||
peer_info_vec.remove(n);
|
||||
} else {
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user