checkpoint

This commit is contained in:
John Smith
2023-02-22 21:47:00 -05:00
parent 4085af7fc4
commit 8fc38febca
11 changed files with 216 additions and 110 deletions

View File

@@ -145,6 +145,15 @@ impl RoutingTableUnlockedInner {
false
}
pub fn matches_own_node_id_key(&self, node_id_key: &PublicKey) -> bool {
for (ck, v) in &self.node_id_keypairs {
if v.key == *node_id_key {
return true;
}
}
false
}
pub fn calculate_bucket_index(&self, node_id: &TypedKey) -> (CryptoKind, usize) {
let crypto = self.crypto();
let self_node_id = self.node_id_keypairs.get(&node_id.kind).unwrap().key;
@@ -587,6 +596,13 @@ impl RoutingTable {
}
}
/// Resolve an existing routing table entry using any crypto kind and return a reference to it
pub fn lookup_any_node_ref(&self, node_id_key: PublicKey) -> Option<NodeRef> {
self.inner
.read()
.lookup_any_node_ref(self.clone(), node_id_key)
}
/// Resolve an existing routing table entry and return a reference to it
pub fn lookup_node_ref(&self, node_id: TypedKey) -> Option<NodeRef> {
self.inner.read().lookup_node_ref(self.clone(), node_id)

View File

@@ -1780,7 +1780,7 @@ impl RouteSpecStore {
/// Import a remote private route for compilation
#[instrument(level = "trace", skip(self, blob), ret, err)]
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> EyreResult<TypedKeySet> {
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> EyreResult<TypedKeySet> { xxx continue here, maybe formalize 'private route set' as having its own non-key identifier for both remote and local routes... just a uuid map to typedkeyset?
// decode the pr blob
let private_routes = RouteSpecStore::blob_to_private_routes(blob)?;
@@ -2006,7 +2006,7 @@ impl RouteSpecStore {
let inner = &mut *self.inner.lock();
// Check for stub route
if *key == self.unlocked_inner.routing_table.node_id() {
if self.unlocked_inner.routing_table.matches_own_node_id_key(key) {
return None;
}
// Check for local route
@@ -2096,7 +2096,7 @@ impl RouteSpecStore {
}
/// Convert binary blob to private route
pub fn blob_to_private_routes(blob: Vec<u8>) -> EyreResult<Vec<PrivateRoute>> {
pub fn blob_to_private_routes(crypto: Crypto, blob: Vec<u8>) -> EyreResult<Vec<PrivateRoute>> {
// Deserialize count
if blob.is_empty() {
@@ -2123,7 +2123,7 @@ impl RouteSpecStore {
.get_root::<veilid_capnp::private_route::Reader>()
.map_err(RPCError::internal)
.wrap_err("failed to make reader for private_route")?;
let private_route = decode_private_route(&pr_reader).wrap_err("failed to decode private route")?;
let private_route = decode_private_route(&pr_reader, crypto).wrap_err("failed to decode private route")?;
out.push(private_route);
}
Ok(out)

View File

@@ -678,6 +678,17 @@ impl RoutingTableInner {
Some(nr)
}
/// Resolve an existing routing table entry using any crypto kind and return a reference to it
pub fn lookup_any_node_ref(
&self,
outer_self: RoutingTable,
node_id_key: PublicKey,
) -> Option<NodeRef> {
VALID_CRYPTO_KINDS
.iter()
.find_map(|ck| self.lookup_node_ref(outer_self, TypedKey::new(*ck, node_id_key)))
}
/// Resolve an existing routing table entry and return a reference to it
pub fn lookup_node_ref(&self, outer_self: RoutingTable, node_id: TypedKey) -> Option<NodeRef> {
if self.unlocked_inner.matches_own_node_id(&[node_id]) {