refactor checkpoint

This commit is contained in:
John Smith
2022-09-03 13:57:25 -04:00
parent 9966d25672
commit e0a5b1bd69
30 changed files with 1274 additions and 838 deletions

View File

@@ -45,6 +45,16 @@ fn get_address_type(text: &str) -> Option<AddressType> {
None
}
}
fn get_routing_domain(text: &str) -> Option<RoutingDomain> {
let lctext = text.to_ascii_lowercase();
if "publicinternet".starts_with(&lctext) {
Some(RoutingDomain::PublicInternet)
} else if "localnetwork".starts_with(&lctext) {
Some(RoutingDomain::LocalNetwork)
} else {
None
}
}
fn get_debug_argument<T, G: FnOnce(&str) -> Option<T>>(
value: &str,
@@ -331,27 +341,40 @@ impl VeilidAPI {
None => return Ok("Node id not found in routing table".to_owned()),
};
if args.len() >= 2 {
let pt =
get_debug_argument_at(&args, 1, "debug_ping", "protocol_type", get_protocol_type)?;
nr.merge_filter(DialInfoFilter::all().with_protocol_type(pt));
if args.len() >= 3 {
let at = get_debug_argument_at(
&args,
2,
"debug_ping",
"address_type",
get_address_type,
)?;
let mut ai = 1;
let mut routing_domain = None;
while ai < args.len() {
if let Ok(pt) =
get_debug_argument_at(&args, ai, "debug_ping", "protocol_type", get_protocol_type)
{
nr.merge_filter(DialInfoFilter::all().with_protocol_type(pt));
} else if let Ok(at) =
get_debug_argument_at(&args, ai, "debug_ping", "address_type", get_address_type)
{
nr.merge_filter(DialInfoFilter::all().with_address_type(at));
} else if let Ok(rd) = get_debug_argument_at(
&args,
ai,
"debug_ping",
"routing_domain",
get_routing_domain,
) {
if routing_domain.is_none() {
routing_domain = Some(rd);
} else {
return Ok("Multiple routing domains specified".to_owned());
}
} else {
return Ok(format!("Invalid argument specified: {}", args[ai]));
}
ai += 1;
}
let rpc = self.network_manager()?.rpc_processor();
// Dump routing table entry
let out = match rpc
.rpc_call_status(nr)
.rpc_call_status(routing_domain, nr)
.await
.map_err(VeilidAPIError::internal)?
{
@@ -383,7 +406,7 @@ impl VeilidAPI {
attach
detach
restart network
ping <node_id> [protocol_type [address_type]]
ping <node_id> [protocol_type][address_type][routing_domain]
contact <node_id> [protocol_type [address_type]]
"#
.to_owned())

View File

@@ -460,9 +460,31 @@ pub struct NodeInfo {
}
impl NodeInfo {
pub fn is_valid(&self) -> bool {
!matches!(self.network_class, NetworkClass::Invalid)
pub fn is_valid_in_routing_domain(
&self,
routing_table: RoutingTable,
routing_domain: RoutingDomain,
) -> bool {
// Should not be passing around nodeinfo with an invalid network class
if matches!(self.network_class, NetworkClass::Invalid) {
return false;
}
// Ensure all of the dial info works in this routing domain
for did in self.dial_info_detail_list {
if !routing_table.ensure_dial_info_is_valid(routing_domain, &did.dial_info) {
return false;
}
}
// Ensure the relay is also valid in this routing domain if it is provided
if let Some(relay_peer_info) = self.relay_peer_info {
let relay_ni = &relay_peer_info.signed_node_info.node_info;
if !relay_ni.is_valid_in_routing_domain(routing_table, routing_domain) {
return false;
}
}
true
}
pub fn first_filtered_dial_info_detail<F>(&self, filter: F) -> Option<DialInfoDetail>
where
F: Fn(&DialInfoDetail) -> bool,
@@ -783,7 +805,7 @@ impl FromStr for SocketAddress {
//////////////////////////////////////////////////////////////////
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct DialInfoFilter {
pub protocol_type_set: ProtocolTypeSet,
pub address_type_set: AddressTypeSet,
@@ -1096,6 +1118,14 @@ impl DialInfo {
pub fn address_type(&self) -> AddressType {
self.socket_address().address_type()
}
pub fn address(&self) -> Address {
match self {
Self::UDP(di) => di.socket_address.address,
Self::TCP(di) => di.socket_address.address,
Self::WS(di) => di.socket_address.address,
Self::WSS(di) => di.socket_address.address,
}
}
pub fn socket_address(&self) -> SocketAddress {
match self {
Self::UDP(di) => di.socket_address,