refactor
This commit is contained in:
@@ -127,7 +127,7 @@ impl RoutingTableUnlockedInner {
|
||||
pub fn node_id_typed_key_pairs(&self) -> Vec<TypedKeyPair> {
|
||||
let mut tkps = Vec::new();
|
||||
for (ck, v) in &self.node_id_keypairs {
|
||||
tkps.push(TypedKeyPair::new(*ck, v.key, v.secret));
|
||||
tkps.push(TypedKeyPair::new(*ck, *v));
|
||||
}
|
||||
tkps
|
||||
}
|
||||
@@ -139,7 +139,7 @@ impl RoutingTableUnlockedInner {
|
||||
pub fn matches_own_node_id(&self, node_ids: &[TypedKey]) -> bool {
|
||||
for ni in node_ids {
|
||||
if let Some(v) = self.node_id_keypairs.get(&ni.kind) {
|
||||
if v.key == ni.key {
|
||||
if v.key == ni.value {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ impl RoutingTableUnlockedInner {
|
||||
(
|
||||
node_id.kind,
|
||||
vcrypto
|
||||
.distance(&node_id.key, &self_node_id)
|
||||
.distance(&node_id.value, &self_node_id)
|
||||
.first_nonzero_bit()
|
||||
.unwrap(),
|
||||
)
|
||||
|
||||
@@ -68,7 +68,7 @@ impl RouteSetSpecDetail {
|
||||
tks
|
||||
}
|
||||
pub fn get_best_route_set_key(&self) -> Option<PublicKey> {
|
||||
self.get_route_set_keys().best().map(|k| k.key)
|
||||
self.get_route_set_keys().best().map(|k| k.value)
|
||||
}
|
||||
pub fn set_hop_node_refs(&mut self, node_refs: Vec<NodeRef>) {
|
||||
self.hop_node_refs = node_refs;
|
||||
@@ -128,7 +128,7 @@ impl RouteSetSpecDetail {
|
||||
let hops = &self.hop_node_refs;
|
||||
let mut cache: Vec<u8> = Vec::with_capacity(hops.len() * PUBLIC_KEY_LENGTH);
|
||||
for hop in hops {
|
||||
cache.extend_from_slice(&hop.best_node_id().key.bytes);
|
||||
cache.extend_from_slice(&hop.best_node_id().value.bytes);
|
||||
}
|
||||
cache
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ impl RouteSpecStore {
|
||||
fn route_permutation_to_hop_cache(rti: &RoutingTableInner, nodes: &[NodeRef], perm: &[usize]) -> Vec<u8> {
|
||||
let mut cache: Vec<u8> = Vec::with_capacity(perm.len() * PUBLIC_KEY_LENGTH);
|
||||
for n in perm {
|
||||
cache.extend_from_slice(&nodes[*n].locked(rti).best_node_id().key.bytes)
|
||||
cache.extend_from_slice(&nodes[*n].locked(rti).best_node_id().value.bytes)
|
||||
}
|
||||
cache
|
||||
}
|
||||
@@ -491,7 +491,7 @@ impl RouteSpecStore {
|
||||
for crypto_kind in crypto_kinds.iter().copied() {
|
||||
let vcrypto = self.unlocked_inner.routing_table.crypto().get(crypto_kind).unwrap();
|
||||
let (public_key, secret_key) = vcrypto.generate_keypair();
|
||||
let hops: Vec<PublicKey> = route_nodes.iter().map(|v| nodes[*v].node_ids().get(crypto_kind).unwrap().key).collect();
|
||||
let hops: Vec<PublicKey> = route_nodes.iter().map(|v| nodes[*v].node_ids().get(crypto_kind).unwrap().value).collect();
|
||||
|
||||
route_set.insert(public_key, RouteSpecDetail {
|
||||
crypto_kind,
|
||||
@@ -543,16 +543,16 @@ impl RouteSpecStore {
|
||||
return None;
|
||||
};
|
||||
|
||||
let Some(rsid) = inner.content.get_id_by_key(&public_key.key) else {
|
||||
log_rpc!(debug "route id does not exist: {:?}", public_key.key);
|
||||
let Some(rsid) = inner.content.get_id_by_key(&public_key.value) else {
|
||||
log_rpc!(debug "route id does not exist: {:?}", public_key.value);
|
||||
return None;
|
||||
};
|
||||
let Some(rssd) = inner.content.get_detail(&rsid) else {
|
||||
log_rpc!(debug "route detail does not exist: {:?}", rsid);
|
||||
return None;
|
||||
};
|
||||
let Some(rsd) = rssd.get_route_by_key(&public_key.key) else {
|
||||
log_rpc!(debug "route set {:?} does not have key: {:?}", rsid, public_key.key);
|
||||
let Some(rsd) = rssd.get_route_by_key(&public_key.value) else {
|
||||
log_rpc!(debug "route set {:?} does not have key: {:?}", rsid, public_key.value);
|
||||
return None;
|
||||
};
|
||||
|
||||
@@ -694,7 +694,7 @@ impl RouteSpecStore {
|
||||
}
|
||||
|
||||
/// Check if a route id is remote or not
|
||||
fn is_route_id_remote(&self, id: &RouteId) -> bool {
|
||||
pub fn is_route_id_remote(&self, id: &RouteId) -> bool {
|
||||
let inner = &mut *self.inner.lock();
|
||||
let cur_ts = get_aligned_timestamp();
|
||||
inner.cache.peek_remote_private_route_mut(cur_ts, &id).is_some()
|
||||
@@ -847,7 +847,7 @@ impl RouteSpecStore {
|
||||
let Some(vcrypto) = crypto.get(crypto_kind) else {
|
||||
bail!("crypto not supported for route");
|
||||
};
|
||||
let pr_pubkey = private_route.public_key.key;
|
||||
let pr_pubkey = private_route.public_key.value;
|
||||
let pr_hopcount = private_route.hop_count as usize;
|
||||
let max_route_hop_count = self.unlocked_inner.max_route_hop_count;
|
||||
|
||||
@@ -1092,7 +1092,7 @@ impl RouteSpecStore {
|
||||
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
|
||||
if !preferred_rssd.contains_nodes(avoid_nodes) {
|
||||
return Ok(Some(preferred_key.key));
|
||||
return Ok(Some(preferred_key.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1131,7 +1131,7 @@ impl RouteSpecStore {
|
||||
sr_route_id
|
||||
};
|
||||
|
||||
let sr_pubkey = inner.content.get_detail(&sr_route_id).unwrap().get_route_set_keys().get(crypto_kind).unwrap().key;
|
||||
let sr_pubkey = inner.content.get_detail(&sr_route_id).unwrap().get_route_set_keys().get(crypto_kind).unwrap().value;
|
||||
|
||||
Ok(Some(sr_pubkey))
|
||||
}
|
||||
@@ -1178,7 +1178,7 @@ impl RouteSpecStore {
|
||||
let Some(node_id) = routing_table.node_ids().get(rsd.crypto_kind) else {
|
||||
bail!("missing node id for crypto kind");
|
||||
};
|
||||
RouteNode::NodeId(node_id.key)
|
||||
RouteNode::NodeId(node_id.value)
|
||||
} else {
|
||||
let Some(pi) = rti.get_own_peer_info(RoutingDomain::PublicInternet) else {
|
||||
bail!("can't make private routes until our node info is valid");
|
||||
@@ -1319,7 +1319,7 @@ impl RouteSpecStore {
|
||||
}
|
||||
|
||||
// ensure this isn't also an allocated route
|
||||
if inner.content.get_id_by_key(&private_route.public_key.key).is_some() {
|
||||
if inner.content.get_id_by_key(&private_route.public_key.value).is_some() {
|
||||
bail!("should not import allocated route");
|
||||
}
|
||||
}
|
||||
@@ -1570,7 +1570,7 @@ impl RouteSpecStore {
|
||||
if best_kind.is_none() || compare_crypto_kind(&tk.kind, best_kind.as_ref().unwrap()) == cmp::Ordering::Less {
|
||||
best_kind = Some(tk.kind);
|
||||
}
|
||||
idbytes.extend_from_slice(&tk.key.bytes);
|
||||
idbytes.extend_from_slice(&tk.value.bytes);
|
||||
}
|
||||
let Some(best_kind) = best_kind else {
|
||||
bail!("no compatible crypto kinds in route");
|
||||
@@ -1591,7 +1591,7 @@ impl RouteSpecStore {
|
||||
if best_kind.is_none() || compare_crypto_kind(&private_route.public_key.kind, best_kind.as_ref().unwrap()) == cmp::Ordering::Less {
|
||||
best_kind = Some(private_route.public_key.kind);
|
||||
}
|
||||
idbytes.extend_from_slice(&private_route.public_key.key.bytes);
|
||||
idbytes.extend_from_slice(&private_route.public_key.value.bytes);
|
||||
}
|
||||
let Some(best_kind) = best_kind else {
|
||||
bail!("no compatible crypto kinds in route");
|
||||
|
||||
@@ -114,14 +114,18 @@ impl RouteSpecStoreCache {
|
||||
/// calculate how many times a node with a particular node id set has been used anywhere in the path of our allocated routes
|
||||
pub fn get_used_node_count(&self, node_ids: &TypedKeySet) -> usize {
|
||||
node_ids.iter().fold(0usize, |acc, k| {
|
||||
acc + self.used_nodes.get(&k.key).cloned().unwrap_or_default()
|
||||
acc + self.used_nodes.get(&k.value).cloned().unwrap_or_default()
|
||||
})
|
||||
}
|
||||
|
||||
/// calculate how many times a node with a particular node id set has been used at the end of the path of our allocated routes
|
||||
pub fn get_used_end_node_count(&self, node_ids: &TypedKeySet) -> usize {
|
||||
node_ids.iter().fold(0usize, |acc, k| {
|
||||
acc + self.used_end_nodes.get(&k.key).cloned().unwrap_or_default()
|
||||
acc + self
|
||||
.used_end_nodes
|
||||
.get(&k.value)
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -135,7 +139,7 @@ impl RouteSpecStoreCache {
|
||||
// also store in id by key table
|
||||
for private_route in rprinfo.get_private_routes() {
|
||||
self.remote_private_routes_by_key
|
||||
.insert(private_route.public_key.key, id.clone());
|
||||
.insert(private_route.public_key.value, id.clone());
|
||||
}
|
||||
|
||||
let mut dead = None;
|
||||
@@ -149,9 +153,9 @@ impl RouteSpecStoreCache {
|
||||
// Follow the same logic as 'remove_remote_private_route' here
|
||||
for dead_private_route in dead_rpri.get_private_routes() {
|
||||
self.remote_private_routes_by_key
|
||||
.remove(&dead_private_route.public_key.key)
|
||||
.remove(&dead_private_route.public_key.value)
|
||||
.unwrap();
|
||||
self.invalidate_compiled_route_cache(&dead_private_route.public_key.key);
|
||||
self.invalidate_compiled_route_cache(&dead_private_route.public_key.value);
|
||||
}
|
||||
self.dead_remote_routes.push(dead_id);
|
||||
}
|
||||
@@ -261,9 +265,9 @@ impl RouteSpecStoreCache {
|
||||
};
|
||||
for private_route in rprinfo.get_private_routes() {
|
||||
self.remote_private_routes_by_key
|
||||
.remove(&private_route.public_key.key)
|
||||
.remove(&private_route.public_key.value)
|
||||
.unwrap();
|
||||
self.invalidate_compiled_route_cache(&private_route.public_key.key);
|
||||
self.invalidate_compiled_route_cache(&private_route.public_key.value);
|
||||
}
|
||||
self.dead_remote_routes.push(id);
|
||||
true
|
||||
@@ -272,7 +276,7 @@ impl RouteSpecStoreCache {
|
||||
/// Stores a compiled 'safety + private' route so we don't have to compile it again later
|
||||
pub fn add_to_compiled_route_cache(&mut self, pr_pubkey: PublicKey, safety_route: SafetyRoute) {
|
||||
let key = CompiledRouteCacheKey {
|
||||
sr_pubkey: safety_route.public_key.key,
|
||||
sr_pubkey: safety_route.public_key.value,
|
||||
pr_pubkey,
|
||||
};
|
||||
|
||||
|
||||
@@ -605,14 +605,14 @@ impl RoutingTableInner {
|
||||
// Remove any old node id for this crypto kind
|
||||
let bucket_index = self.unlocked_inner.calculate_bucket_index(&old_node_id);
|
||||
let bucket = self.get_bucket_mut(bucket_index);
|
||||
bucket.remove_entry(&old_node_id.key);
|
||||
bucket.remove_entry(&old_node_id.value);
|
||||
self.unlocked_inner.kick_queue.lock().insert(bucket_index);
|
||||
}
|
||||
|
||||
// Bucket the entry appropriately
|
||||
let bucket_index = self.unlocked_inner.calculate_bucket_index(node_id);
|
||||
let bucket = self.get_bucket_mut(bucket_index);
|
||||
bucket.add_existing_entry(node_id.key, entry.clone());
|
||||
bucket.add_existing_entry(node_id.value, entry.clone());
|
||||
|
||||
// Kick bucket
|
||||
self.unlocked_inner.kick_queue.lock().insert(bucket_index);
|
||||
@@ -649,7 +649,7 @@ impl RoutingTableInner {
|
||||
}
|
||||
let bucket_index = self.unlocked_inner.calculate_bucket_index(node_id);
|
||||
let bucket = self.get_bucket(bucket_index);
|
||||
if let Some(entry) = bucket.entry(&node_id.key) {
|
||||
if let Some(entry) = bucket.entry(&node_id.value) {
|
||||
// Best entry is the first one in sorted order that exists from the node id list
|
||||
// Everything else that matches will be overwritten in the bucket and the
|
||||
// existing noderefs will eventually unref and drop the old unindexed bucketentry
|
||||
@@ -680,7 +680,7 @@ impl RoutingTableInner {
|
||||
let first_node_id = node_ids[0];
|
||||
let bucket_entry = self.unlocked_inner.calculate_bucket_index(&first_node_id);
|
||||
let bucket = self.get_bucket_mut(bucket_entry);
|
||||
let new_entry = bucket.add_new_entry(first_node_id.key);
|
||||
let new_entry = bucket.add_new_entry(first_node_id.value);
|
||||
self.unlocked_inner.kick_queue.lock().insert(bucket_entry);
|
||||
|
||||
// Update the other bucket entries with the remaining node ids
|
||||
@@ -723,7 +723,7 @@ impl RoutingTableInner {
|
||||
let bucket_index = self.unlocked_inner.calculate_bucket_index(&node_id);
|
||||
let bucket = self.get_bucket(bucket_index);
|
||||
bucket
|
||||
.entry(&node_id.key)
|
||||
.entry(&node_id.value)
|
||||
.map(|e| NodeRef::new(outer_self, e, None))
|
||||
}
|
||||
|
||||
@@ -760,7 +760,7 @@ impl RoutingTableInner {
|
||||
}
|
||||
let bucket_entry = self.unlocked_inner.calculate_bucket_index(&node_id);
|
||||
let bucket = self.get_bucket(bucket_entry);
|
||||
bucket.entry(&node_id.key).map(f)
|
||||
bucket.entry(&node_id.value).map(f)
|
||||
}
|
||||
|
||||
/// Shortcut function to add a node to our routing table if it doesn't exist
|
||||
@@ -1174,8 +1174,8 @@ impl RoutingTableInner {
|
||||
// since multiple cryptosystems are in use, the distance for a key is the shortest
|
||||
// distance to that key over all supported cryptosystems
|
||||
|
||||
let da = vcrypto.distance(&a_key.key, &node_id.key);
|
||||
let db = vcrypto.distance(&b_key.key, &node_id.key);
|
||||
let da = vcrypto.distance(&a_key.value, &node_id.value);
|
||||
let db = vcrypto.distance(&b_key.value, &node_id.value);
|
||||
da.cmp(&db)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user