more refactor
This commit is contained in:
parent
b3c55f4a6d
commit
bb4dbb7c4a
@ -80,9 +80,15 @@ impl RouteSetSpecDetail {
|
|||||||
pub fn hop_count(&self) -> usize {
|
pub fn hop_count(&self) -> usize {
|
||||||
self.hop_node_refs.len()
|
self.hop_node_refs.len()
|
||||||
}
|
}
|
||||||
|
pub fn hop_node_ref(&self, idx: usize) -> Option<NodeRef> {
|
||||||
|
self.hop_node_refs.get(idx).cloned()
|
||||||
|
}
|
||||||
pub fn get_stability(&self) -> Stability {
|
pub fn get_stability(&self) -> Stability {
|
||||||
self.stability
|
self.stability
|
||||||
}
|
}
|
||||||
|
pub fn get_directions(&self) -> DirectionSet {
|
||||||
|
self.directions
|
||||||
|
}
|
||||||
pub fn is_sequencing_match(&self, sequencing: Sequencing) -> bool {
|
pub fn is_sequencing_match(&self, sequencing: Sequencing) -> bool {
|
||||||
match sequencing {
|
match sequencing {
|
||||||
Sequencing::NoPreference => true,
|
Sequencing::NoPreference => true,
|
||||||
|
@ -730,52 +730,46 @@ impl RouteSpecStore {
|
|||||||
/// Don't pick any routes that have failed and haven't been tested yet
|
/// Don't pick any routes that have failed and haven't been tested yet
|
||||||
fn first_available_route_inner<'a>(
|
fn first_available_route_inner<'a>(
|
||||||
inner: &'a RouteSpecStoreInner,
|
inner: &'a RouteSpecStoreInner,
|
||||||
|
crypto_kind: CryptoKind,
|
||||||
min_hop_count: usize,
|
min_hop_count: usize,
|
||||||
max_hop_count: usize,
|
max_hop_count: usize,
|
||||||
stability: Stability,
|
stability: Stability,
|
||||||
sequencing: Sequencing,
|
sequencing: Sequencing,
|
||||||
directions: DirectionSet,
|
directions: DirectionSet,
|
||||||
avoid_nodes: &[TypedKey],
|
avoid_nodes: &[TypedKey],
|
||||||
) -> Option<PublicKey> {
|
) -> Option<RouteId> {
|
||||||
let cur_ts = get_aligned_timestamp();
|
let cur_ts = get_aligned_timestamp();
|
||||||
|
|
||||||
let mut routes = Vec::new();
|
let mut routes = Vec::new();
|
||||||
|
|
||||||
// Get all valid routes, allow routes that need testing
|
// Get all valid routes, allow routes that need testing
|
||||||
// but definitely prefer routes that have been recently tested
|
// but definitely prefer routes that have been recently tested
|
||||||
for detail in &inner.content.details {
|
for (id, rssd) in inner.content.iter_details() {
|
||||||
if detail.1.stability >= stability
|
if rssd.get_stability() >= stability
|
||||||
&& detail.1.is_sequencing_match(sequencing)
|
&& rssd.is_sequencing_match(sequencing)
|
||||||
&& detail.1.hops.len() >= min_hop_count
|
&& rssd.hop_count() >= min_hop_count
|
||||||
&& detail.1.hops.len() <= max_hop_count
|
&& rssd.hop_count() <= max_hop_count
|
||||||
&& detail.1.directions.is_superset(directions)
|
&& rssd.get_directions().is_superset(directions)
|
||||||
&& !detail.1.published
|
&& rssd.get_route_set_keys().kinds().contains(&crypto_kind)
|
||||||
|
&& !rssd.is_published()
|
||||||
|
&& !rssd.contains_nodes(avoid_nodes)
|
||||||
{
|
{
|
||||||
let mut avoid = false;
|
routes.push((id, rssd));
|
||||||
for h in &detail.1.hops {
|
|
||||||
if avoid_nodes.contains(h) {
|
|
||||||
avoid = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !avoid {
|
|
||||||
routes.push(detail);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the routes by preference
|
// Sort the routes by preference
|
||||||
routes.sort_by(|a, b| {
|
routes.sort_by(|a, b| {
|
||||||
let a_needs_testing = a.1.stats.needs_testing(cur_ts);
|
let a_needs_testing = a.1.get_stats().needs_testing(cur_ts);
|
||||||
let b_needs_testing = b.1.stats.needs_testing(cur_ts);
|
let b_needs_testing = b.1.get_stats().needs_testing(cur_ts);
|
||||||
if !a_needs_testing && b_needs_testing {
|
if !a_needs_testing && b_needs_testing {
|
||||||
return cmp::Ordering::Less;
|
return cmp::Ordering::Less;
|
||||||
}
|
}
|
||||||
if !b_needs_testing && a_needs_testing {
|
if !b_needs_testing && a_needs_testing {
|
||||||
return cmp::Ordering::Greater;
|
return cmp::Ordering::Greater;
|
||||||
}
|
}
|
||||||
let a_latency = a.1.stats.latency_stats().average;
|
let a_latency = a.1.get_stats().latency_stats().average;
|
||||||
let b_latency = b.1.stats.latency_stats().average;
|
let b_latency = b.1.get_stats().latency_stats().average;
|
||||||
|
|
||||||
a_latency.cmp(&b_latency)
|
a_latency.cmp(&b_latency)
|
||||||
});
|
});
|
||||||
@ -847,14 +841,20 @@ impl RouteSpecStore {
|
|||||||
mut private_route: PrivateRoute,
|
mut private_route: PrivateRoute,
|
||||||
) -> EyreResult<Option<CompiledRoute>> {
|
) -> EyreResult<Option<CompiledRoute>> {
|
||||||
// let profile_start_ts = get_timestamp();
|
// let profile_start_ts = get_timestamp();
|
||||||
|
|
||||||
let inner = &mut *self.inner.lock();
|
let inner = &mut *self.inner.lock();
|
||||||
let routing_table = self.unlocked_inner.routing_table.clone();
|
let routing_table = self.unlocked_inner.routing_table.clone();
|
||||||
let rti = &mut *routing_table.inner.write();
|
let rti = &mut *routing_table.inner.write();
|
||||||
|
|
||||||
let pr_pubkey = private_route.public_key;
|
// Get useful private route properties
|
||||||
|
let crypto_kind = private_route.crypto_kind();
|
||||||
|
let crypto = routing_table.crypto();
|
||||||
|
let Some(vcrypto) = crypto.get(crypto_kind) else {
|
||||||
|
bail!("crypto not supported for route");
|
||||||
|
};
|
||||||
|
let pr_pubkey = private_route.public_key.key;
|
||||||
let pr_hopcount = private_route.hop_count as usize;
|
let pr_hopcount = private_route.hop_count as usize;
|
||||||
let max_route_hop_count = self.unlocked_inner.max_route_hop_count;
|
let max_route_hop_count = self.unlocked_inner.max_route_hop_count;
|
||||||
|
|
||||||
// Check private route hop count isn't larger than the max route hop count plus one for the 'first hop' header
|
// Check private route hop count isn't larger than the max route hop count plus one for the 'first hop' header
|
||||||
if pr_hopcount > (max_route_hop_count + 1) {
|
if pr_hopcount > (max_route_hop_count + 1) {
|
||||||
bail!("private route hop count too long");
|
bail!("private route hop count too long");
|
||||||
@ -870,12 +870,11 @@ impl RouteSpecStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let opt_first_hop = match pr_first_hop_node {
|
let opt_first_hop = match pr_first_hop_node {
|
||||||
RouteNode::NodeId(id) => rti.lookup_node_ref(routing_table.clone(), id.key),
|
RouteNode::NodeId(id) => rti.lookup_any_node_ref(routing_table.clone(), id),
|
||||||
RouteNode::PeerInfo(pi) => rti.register_node_with_peer_info(
|
RouteNode::PeerInfo(pi) => rti.register_node_with_peer_info(
|
||||||
routing_table.clone(),
|
routing_table.clone(),
|
||||||
RoutingDomain::PublicInternet,
|
RoutingDomain::PublicInternet,
|
||||||
pi.node_id.key,
|
pi,
|
||||||
pi.signed_node_info.clone(),
|
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
@ -892,22 +891,23 @@ impl RouteSpecStore {
|
|||||||
// Return the compiled safety route
|
// Return the compiled safety route
|
||||||
//println!("compile_safety_route profile (stub): {} us", (get_timestamp() - profile_start_ts));
|
//println!("compile_safety_route profile (stub): {} us", (get_timestamp() - profile_start_ts));
|
||||||
return Ok(Some(CompiledRoute {
|
return Ok(Some(CompiledRoute {
|
||||||
safety_route: SafetyRoute::new_stub(routing_table.node_id(), private_route),
|
safety_route: SafetyRoute::new_stub(routing_table.node_id(crypto_kind), private_route),
|
||||||
secret: routing_table.node_id_secret(),
|
secret: routing_table.node_id_secret(crypto_kind),
|
||||||
first_hop,
|
first_hop,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the safety route requested is also the private route, this is a loopback test, just accept it
|
// If the safety route requested is also the private route, this is a loopback test, just accept it
|
||||||
let sr_pubkey = if safety_spec.preferred_route == Some(private_route.public_key) {
|
let opt_private_route_id = inner.content.get_id_by_key(&pr_pubkey);
|
||||||
|
let sr_pubkey = if opt_private_route_id.is_some() && safety_spec.preferred_route == opt_private_route_id {
|
||||||
// Private route is also safety route during loopback test
|
// Private route is also safety route during loopback test
|
||||||
private_route.public_key
|
pr_pubkey
|
||||||
} else {
|
} else {
|
||||||
let Some(avoid_node_id) = private_route.first_hop_node_id() else {
|
let Some(avoid_node_id) = private_route.first_hop_node_id() else {
|
||||||
bail!("compiled private route should have first hop");
|
bail!("compiled private route should have first hop");
|
||||||
};
|
};
|
||||||
let Some(sr_pubkey) = self.get_route_for_safety_spec_inner(inner, rti, &safety_spec, Direction::Outbound.into(), &[avoid_node_id])? else {
|
let Some(sr_pubkey) = self.get_route_for_safety_spec_inner(inner, rti, crypto_kind, &safety_spec, Direction::Outbound.into(), &[avoid_node_id])? else {
|
||||||
// No safety route could be found for this spec
|
// No safety route could be found for this spec
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
@ -915,28 +915,33 @@ impl RouteSpecStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Look up a few things from the safety route detail we want for the compiled route and don't borrow inner
|
// Look up a few things from the safety route detail we want for the compiled route and don't borrow inner
|
||||||
let (optimize, first_hop, secret) = {
|
let Some(safety_route_id) = inner.content.get_id_by_key(&sr_pubkey) else {
|
||||||
let safety_rsd = Self::detail(inner, &sr_pubkey).ok_or_else(|| eyre!("route missing"))?;
|
bail!("route id missing");
|
||||||
|
};
|
||||||
|
let Some(safety_rssd) = inner.content.get_detail(&safety_route_id) else {
|
||||||
|
bail!("route set detail missing");
|
||||||
|
};
|
||||||
|
let Some(safety_rsd) = safety_rssd.get_route_by_key(&sr_pubkey) else {
|
||||||
|
bail!("route detail missing");
|
||||||
|
};
|
||||||
|
|
||||||
// We can optimize the peer info in this safety route if it has been successfully
|
// We can optimize the peer info in this safety route if it has been successfully
|
||||||
// communicated over either via an outbound test, or used as a private route inbound
|
// communicated over either via an outbound test, or used as a private route inbound
|
||||||
// and we are replying over the same route as our safety route outbound
|
// and we are replying over the same route as our safety route outbound
|
||||||
let optimize = safety_rsd.stats.last_tested_ts.is_some() || safety_rsd.stats.last_received_ts.is_some();
|
let optimize = safety_rssd.get_stats().last_tested_ts.is_some() || safety_rssd.get_stats().last_received_ts.is_some();
|
||||||
|
|
||||||
// Get the first hop noderef of the safety route
|
// Get the first hop noderef of the safety route
|
||||||
let mut first_hop = safety_rsd.hop_node_refs.first().unwrap().clone();
|
let mut first_hop = safety_rssd.hop_node_ref(0).unwrap();
|
||||||
|
|
||||||
// Ensure sequencing requirement is set on first hop
|
// Ensure sequencing requirement is set on first hop
|
||||||
first_hop.set_sequencing(safety_spec.sequencing);
|
first_hop.set_sequencing(safety_spec.sequencing);
|
||||||
|
|
||||||
// Get the safety route secret key
|
// Get the safety route secret key
|
||||||
let secret = safety_rsd.secret_key;
|
let secret = safety_rsd.secret_key;
|
||||||
|
|
||||||
(optimize, first_hop, secret)
|
|
||||||
};
|
|
||||||
|
|
||||||
// See if we have a cached route we can use
|
// See if we have a cached route we can use
|
||||||
if optimize {
|
if optimize {
|
||||||
if let Some(safety_route) = self.lookup_compiled_route_cache(inner, sr_pubkey, pr_pubkey) {
|
if let Some(safety_route) = inner.cache.lookup_compiled_route_cache(sr_pubkey, pr_pubkey) {
|
||||||
// Build compiled route
|
// Build compiled route
|
||||||
let compiled_route = CompiledRoute {
|
let compiled_route = CompiledRoute {
|
||||||
safety_route,
|
safety_route,
|
||||||
@ -951,8 +956,6 @@ impl RouteSpecStore {
|
|||||||
|
|
||||||
// Create hops
|
// Create hops
|
||||||
let hops = {
|
let hops = {
|
||||||
let safety_rsd = Self::detail(inner, &sr_pubkey).ok_or_else(|| eyre!("route missing"))?;
|
|
||||||
|
|
||||||
// start last blob-to-encrypt data off as private route
|
// start last blob-to-encrypt data off as private route
|
||||||
let mut blob_data = {
|
let mut blob_data = {
|
||||||
let mut pr_message = ::capnp::message::Builder::new_default();
|
let mut pr_message = ::capnp::message::Builder::new_default();
|
||||||
@ -970,18 +973,17 @@ impl RouteSpecStore {
|
|||||||
// safety route and does not include the dialInfo
|
// safety route and does not include the dialInfo
|
||||||
// (outer hop is a RouteHopData, not a RouteHop).
|
// (outer hop is a RouteHopData, not a RouteHop).
|
||||||
// Each loop mutates 'nonce', and 'blob_data'
|
// Each loop mutates 'nonce', and 'blob_data'
|
||||||
let mut nonce = Crypto::get_random_nonce();
|
let mut nonce = vcrypto.random_nonce();
|
||||||
let crypto = routing_table.crypto();
|
|
||||||
// Forward order (safety route), but inside-out
|
// Forward order (safety route), but inside-out
|
||||||
for h in (1..safety_rsd.hops.len()).rev() {
|
for h in (1..safety_rsd.hops.len()).rev() {
|
||||||
// Get blob to encrypt for next hop
|
// Get blob to encrypt for next hop
|
||||||
blob_data = {
|
blob_data = {
|
||||||
// Encrypt the previous blob ENC(nonce, DH(PKhop,SKsr))
|
// Encrypt the previous blob ENC(nonce, DH(PKhop,SKsr))
|
||||||
let dh_secret = crypto
|
let dh_secret = vcrypto
|
||||||
.cached_dh(&safety_rsd.hops[h], &safety_rsd.secret_key)
|
.cached_dh(&safety_rsd.hops[h], &safety_rsd.secret_key)
|
||||||
.wrap_err("dh failed")?;
|
.wrap_err("dh failed")?;
|
||||||
let enc_msg_data =
|
let enc_msg_data =
|
||||||
Crypto::encrypt_aead(blob_data.as_slice(), &nonce, &dh_secret, None)
|
vcrypto.encrypt_aead(blob_data.as_slice(), &nonce, &dh_secret, None)
|
||||||
.wrap_err("encryption failed")?;
|
.wrap_err("encryption failed")?;
|
||||||
|
|
||||||
// Make route hop data
|
// Make route hop data
|
||||||
@ -994,14 +996,14 @@ impl RouteSpecStore {
|
|||||||
let route_hop = RouteHop {
|
let route_hop = RouteHop {
|
||||||
node: if optimize {
|
node: if optimize {
|
||||||
// Optimized, no peer info, just the dht key
|
// Optimized, no peer info, just the dht key
|
||||||
RouteNode::NodeId(NodeId::new(safety_rsd.hops[h]))
|
RouteNode::NodeId(safety_rsd.hops[h])
|
||||||
} else {
|
} else {
|
||||||
// Full peer info, required until we are sure the route has been fully established
|
// Full peer info, required until we are sure the route has been fully established
|
||||||
let node_id = safety_rsd.hops[h];
|
let node_id = TypedKey::new(safety_rsd.crypto_kind, safety_rsd.hops[h]);
|
||||||
let pi = rti
|
let pi = rti
|
||||||
.with_node_entry(node_id, |entry| {
|
.with_node_entry(node_id, |entry| {
|
||||||
entry.with(rti, |_rti, e| {
|
entry.with(rti, |_rti, e| {
|
||||||
e.make_peer_info(node_id, RoutingDomain::PublicInternet)
|
e.make_peer_info(RoutingDomain::PublicInternet)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
@ -1025,14 +1027,14 @@ impl RouteSpecStore {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Make another nonce for the next hop
|
// Make another nonce for the next hop
|
||||||
nonce = Crypto::get_random_nonce();
|
nonce = vcrypto.random_nonce();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode first RouteHopData
|
// Encode first RouteHopData
|
||||||
let dh_secret = crypto
|
let dh_secret = vcrypto
|
||||||
.cached_dh(&safety_rsd.hops[0], &safety_rsd.secret_key)
|
.cached_dh(&safety_rsd.hops[0], &safety_rsd.secret_key)
|
||||||
.map_err(RPCError::map_internal("dh failed"))?;
|
.map_err(RPCError::map_internal("dh failed"))?;
|
||||||
let enc_msg_data = Crypto::encrypt_aead(blob_data.as_slice(), &nonce, &dh_secret, None)
|
let enc_msg_data = vcrypto.encrypt_aead(blob_data.as_slice(), &nonce, &dh_secret, None)
|
||||||
.map_err(RPCError::map_internal("encryption failed"))?;
|
.map_err(RPCError::map_internal("encryption failed"))?;
|
||||||
|
|
||||||
let route_hop_data = RouteHopData {
|
let route_hop_data = RouteHopData {
|
||||||
@ -1045,14 +1047,14 @@ impl RouteSpecStore {
|
|||||||
|
|
||||||
// Build safety route
|
// Build safety route
|
||||||
let safety_route = SafetyRoute {
|
let safety_route = SafetyRoute {
|
||||||
public_key: sr_pubkey,
|
public_key: TypedKey::new(crypto_kind, sr_pubkey),
|
||||||
hop_count: safety_spec.hop_count as u8,
|
hop_count: safety_spec.hop_count as u8,
|
||||||
hops,
|
hops,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add to cache but only if we have an optimized route
|
// Add to cache but only if we have an optimized route
|
||||||
if optimize {
|
if optimize {
|
||||||
self.add_to_compiled_route_cache(inner, pr_pubkey, safety_route.clone());
|
inner.cache.add_to_compiled_route_cache( pr_pubkey, safety_route.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build compiled route
|
// Build compiled route
|
||||||
@ -1090,7 +1092,7 @@ impl RouteSpecStore {
|
|||||||
// See if the preferred route is here
|
// See if the preferred route is here
|
||||||
if let Some(preferred_route) = safety_spec.preferred_route {
|
if let Some(preferred_route) = safety_spec.preferred_route {
|
||||||
if let Some(preferred_rssd) = inner.content.get_detail(&preferred_route) {
|
if let Some(preferred_rssd) = inner.content.get_detail(&preferred_route) {
|
||||||
// Only use the preferred route if it has the desire crypto kind
|
// Only use the preferred route if it has the desired crypto kind
|
||||||
if let Some(preferred_key) = preferred_rssd.get_route_set_keys().get(crypto_kind) {
|
if let Some(preferred_key) = preferred_rssd.get_route_set_keys().get(crypto_kind) {
|
||||||
// Only use the preferred route if it doesn't contain the avoid nodes
|
// Only use the preferred route if it doesn't contain the avoid nodes
|
||||||
if !preferred_rssd.contains_nodes(avoid_nodes) {
|
if !preferred_rssd.contains_nodes(avoid_nodes) {
|
||||||
@ -1101,8 +1103,9 @@ impl RouteSpecStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select a safety route from the pool or make one if we don't have one that matches
|
// Select a safety route from the pool or make one if we don't have one that matches
|
||||||
let sr_pubkey = if let Some(sr_pubkey) = Self::first_available_route_inner(
|
let sr_route_id = if let Some(sr_route_id) = Self::first_available_route_inner(
|
||||||
inner,
|
inner,
|
||||||
|
crypto_kind,
|
||||||
safety_spec.hop_count,
|
safety_spec.hop_count,
|
||||||
safety_spec.hop_count,
|
safety_spec.hop_count,
|
||||||
safety_spec.stability,
|
safety_spec.stability,
|
||||||
@ -1111,14 +1114,14 @@ impl RouteSpecStore {
|
|||||||
avoid_nodes,
|
avoid_nodes,
|
||||||
) {
|
) {
|
||||||
// Found a route to use
|
// Found a route to use
|
||||||
sr_pubkey
|
sr_route_id
|
||||||
} else {
|
} else {
|
||||||
// No route found, gotta allocate one
|
// No route found, gotta allocate one
|
||||||
let sr_pubkey = match self
|
let Some(sr_route_id) = self
|
||||||
.allocate_route_inner(
|
.allocate_route_inner(
|
||||||
inner,
|
inner,
|
||||||
rti,
|
rti,
|
||||||
crypto_kind, ???
|
&[crypto_kind],
|
||||||
safety_spec.stability,
|
safety_spec.stability,
|
||||||
safety_spec.sequencing,
|
safety_spec.sequencing,
|
||||||
safety_spec.hop_count,
|
safety_spec.hop_count,
|
||||||
@ -1126,12 +1129,14 @@ impl RouteSpecStore {
|
|||||||
avoid_nodes,
|
avoid_nodes,
|
||||||
)
|
)
|
||||||
.map_err(RPCError::internal)?
|
.map_err(RPCError::internal)?
|
||||||
{
|
else {
|
||||||
Some(pk) => pk,
|
return Ok(None);
|
||||||
None => return Ok(None),
|
|
||||||
};
|
};
|
||||||
sr_pubkey
|
sr_route_id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let sr_pubkey = inner.content.get_detail(&sr_route_id).unwrap().get_route_set_keys().get(crypto_kind).unwrap().key;
|
||||||
|
|
||||||
Ok(Some(sr_pubkey))
|
Ok(Some(sr_pubkey))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1366,7 +1371,6 @@ impl RouteSpecStore {
|
|||||||
pub fn get_route_id_for_key(&self, key: &PublicKey) -> Option<RouteId>
|
pub fn get_route_id_for_key(&self, key: &PublicKey) -> Option<RouteId>
|
||||||
{
|
{
|
||||||
let inner = &mut *self.inner.lock();
|
let inner = &mut *self.inner.lock();
|
||||||
|
|
||||||
// Check for local route
|
// Check for local route
|
||||||
if let Some(id) = inner.content.get_id_by_key(key) {
|
if let Some(id) = inner.content.get_id_by_key(key) {
|
||||||
return Some(id);
|
return Some(id);
|
||||||
|
@ -162,9 +162,9 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
SafetySelection::Safe(safety_spec) => {
|
SafetySelection::Safe(safety_spec) => {
|
||||||
// Sent directly but with a safety route, respond to private route
|
// Sent directly but with a safety route, respond to private route
|
||||||
let ck = target.best_node_id().kind;
|
let crypto_kind = target.best_node_id().kind;
|
||||||
let Some(pr_key) = rss
|
let Some(pr_key) = rss
|
||||||
.get_private_route_for_safety_spec(ck, safety_spec, &target.node_ids())
|
.get_private_route_for_safety_spec(crypto_kind, safety_spec, &target.node_ids())
|
||||||
.map_err(RPCError::internal)? else {
|
.map_err(RPCError::internal)? else {
|
||||||
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
||||||
};
|
};
|
||||||
@ -188,12 +188,12 @@ impl RPCProcessor {
|
|||||||
}
|
}
|
||||||
SafetySelection::Safe(safety_spec) => {
|
SafetySelection::Safe(safety_spec) => {
|
||||||
// Sent via a relay but with a safety route, respond to private route
|
// Sent via a relay but with a safety route, respond to private route
|
||||||
let ck = target.best_node_id().kind;
|
let crypto_kind = target.best_node_id().kind;
|
||||||
|
|
||||||
let mut avoid_nodes = relay.node_ids();
|
let mut avoid_nodes = relay.node_ids();
|
||||||
avoid_nodes.add_all(&target.node_ids());
|
avoid_nodes.add_all(&target.node_ids());
|
||||||
let Some(pr_key) = rss
|
let Some(pr_key) = rss
|
||||||
.get_private_route_for_safety_spec(ck, safety_spec, &avoid_nodes)
|
.get_private_route_for_safety_spec(crypto_kind, safety_spec, &avoid_nodes)
|
||||||
.map_err(RPCError::internal)? else {
|
.map_err(RPCError::internal)? else {
|
||||||
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
return Ok(NetworkResult::no_connection_other("no private route for response at this time"));
|
||||||
};
|
};
|
||||||
@ -246,7 +246,7 @@ impl RPCProcessor {
|
|||||||
|
|
||||||
// Check for loopback test
|
// Check for loopback test
|
||||||
let opt_private_route_id = rss.get_route_id_for_key(&private_route.public_key.key);
|
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
|
let pr_key = if opt_private_route_id.is_some() && safety_spec.preferred_route == opt_private_route_id
|
||||||
{
|
{
|
||||||
// Private route is also safety route during loopback test
|
// Private route is also safety route during loopback test
|
||||||
private_route.public_key.key
|
private_route.public_key.key
|
||||||
|
@ -192,13 +192,13 @@ impl RPCProcessor {
|
|||||||
&routed_operation.signatures,
|
&routed_operation.signatures,
|
||||||
&routed_operation.data,
|
&routed_operation.data,
|
||||||
sender_id,
|
sender_id,
|
||||||
|rsd| {
|
|rssd, rsd| {
|
||||||
(
|
(
|
||||||
rsd.secret_key,
|
rsd.secret_key,
|
||||||
SafetySpec {
|
SafetySpec {
|
||||||
preferred_route: Some(pr_pubkey),
|
preferred_route: rss.get_route_id_for_key(&pr_pubkey),
|
||||||
hop_count: rsd.hop_count(),
|
hop_count: rssd.hop_count(),
|
||||||
stability: rsd.get_stability(),
|
stability: rssd.get_stability(),
|
||||||
sequencing: routed_operation.sequencing,
|
sequencing: routed_operation.sequencing,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user