checkpoint

This commit is contained in:
John Smith
2023-02-26 18:11:10 -05:00
parent 66db856c50
commit c330faa4fa
12 changed files with 158 additions and 114 deletions
+18 -23
View File
@@ -19,10 +19,10 @@ pub enum Destination {
/// Require safety route or not
safety_selection: SafetySelection,
},
/// Send to private route (privateroute)
/// Send to private route
PrivateRoute {
/// A private route set id to send to
private_route_id: RouteId,
/// A private route to send to
private_route: PrivateRoute,
/// Require safety route or not
safety_selection: SafetySelection,
},
@@ -44,9 +44,9 @@ impl Destination {
safety_selection: SafetySelection::Unsafe(sequencing),
}
}
pub fn private_route(private_route_id: RouteId, safety_selection: SafetySelection) -> Self {
pub fn private_route(private_route: PrivateRoute, safety_selection: SafetySelection) -> Self {
Self::PrivateRoute {
private_route_id,
private_route,
safety_selection,
}
}
@@ -70,10 +70,10 @@ impl Destination {
safety_selection,
},
Destination::PrivateRoute {
private_route_id,
private_route,
safety_selection: _,
} => Self::PrivateRoute {
private_route_id,
private_route,
safety_selection,
},
}
@@ -91,7 +91,7 @@ impl Destination {
safety_selection,
} => safety_selection,
Destination::PrivateRoute {
private_route_id: _,
private_route: _,
safety_selection,
} => safety_selection,
}
@@ -127,7 +127,7 @@ impl fmt::Display for Destination {
write!(f, "{}@{}{}", target, relay, sr)
}
Destination::PrivateRoute {
private_route_id,
private_route,
safety_selection,
} => {
let sr = if matches!(safety_selection, SafetySelection::Safe(_)) {
@@ -136,7 +136,7 @@ impl fmt::Display for Destination {
""
};
write!(f, "{}{}", private_route_id, sr)
write!(f, "{}{}", private_route.public_key, sr)
}
}
}
@@ -162,9 +162,6 @@ impl RPCProcessor {
}
SafetySelection::Safe(safety_spec) => {
// Sent directly but with a safety route, respond to private route
xxx continue here. ensure crypto kind makes sense with get_private_route_for_safety_spec and then make it work.
let ck = target.best_node_id().kind;
let Some(pr_key) = rss
.get_private_route_for_safety_spec(ck, safety_spec, &target.node_ids())
@@ -210,9 +207,10 @@ xxx continue here. ensure crypto kind makes sense with get_private_route_for_saf
}
},
Destination::PrivateRoute {
private_route_id,
private_route,
safety_selection,
} => {
let Some(avoid_node_id) = private_route.first_hop_node_id() else {
return Err(RPCError::internal("destination private route must have first hop"));
};
@@ -224,22 +222,19 @@ xxx continue here. ensure crypto kind makes sense with get_private_route_for_saf
// Sent to a private route with no safety route, use a stub safety route for the response
// Determine if we can use optimized nodeinfo
let route_node = match rss
.has_remote_private_route_seen_our_node_info(&private_route_id)
let route_node = if rss
.has_remote_private_route_seen_our_node_info(&private_route.public_key.key)
{
true => {
if !routing_table.has_valid_own_node_info(RoutingDomain::PublicInternet) {
return Ok(NetworkResult::no_connection_other("Own node info must be valid to use private route"));
}
RouteNode::NodeId(routing_table.node_id(crypto_kind).key)
}
false => {
} else {
let Some(own_peer_info) =
routing_table.get_own_peer_info(RoutingDomain::PublicInternet) else {
return Ok(NetworkResult::no_connection_other("Own peer info must be valid to use private route"));
};
RouteNode::PeerInfo(own_peer_info)
},
};
Ok(NetworkResult::value(RespondTo::PrivateRoute(
@@ -248,12 +243,12 @@ xxx continue here. ensure crypto kind makes sense with get_private_route_for_saf
}
SafetySelection::Safe(safety_spec) => {
// Sent to a private route via a safety route, respond to private route
// Check for loopback test
let pr_key = if safety_spec.preferred_route == Some(private_route_id)
let opt_private_route_id = rss.get_route_id_for_key(&private_route.public_key.key);
let pr_key = if safety_spec.preferred_route == opt_private_route_id
{
// Private route is also safety route during loopback test
xxx build loopback routine? get_private_route_for_loopback_test?
private_route.public_key.key
} else {
// Get the private route to respond to that matches the safety route spec we sent the request with