rebuilding the persisted reverse_cap_index

This commit is contained in:
Drew Tada 2024-02-08 12:19:53 -05:00
parent 0e4cd175e3
commit e69e39f8bb
2 changed files with 19 additions and 7 deletions

View File

@ -2,7 +2,6 @@
use anyhow::Result;
use clap::{arg, value_parser, Command};
use std::collections::HashMap;
use std::env;
use std::sync::Arc;
use tokio::sync::{mpsc, oneshot};
@ -432,7 +431,7 @@ async fn main() {
*/
let networking_keypair_arc = Arc::new(decoded_keyfile.networking_keypair);
let (kernel_process_map, db) = state::load_state(
let (kernel_process_map, db, reverse_cap_index) = state::load_state(
our.name.clone(),
networking_keypair_arc.clone(),
home_directory_path.clone(),
@ -446,7 +445,7 @@ async fn main() {
our.clone(),
networking_keypair_arc.clone(),
kernel_process_map.clone(),
HashMap::new(), // TODO need to persist this
reverse_cap_index,
caps_oracle_sender.clone(),
caps_oracle_receiver,
kernel_message_sender.clone(),

View File

@ -19,7 +19,7 @@ pub async fn load_state(
keypair: Arc<signature::Ed25519KeyPair>,
home_directory_path: String,
runtime_extensions: Vec<(ProcessId, MessageSender, bool)>,
) -> Result<(ProcessMap, DB), StateError> {
) -> Result<(ProcessMap, DB, ReverseCapIndex), StateError> {
let state_path = format!("{}/kernel", &home_directory_path);
if let Err(e) = fs::create_dir_all(&state_path).await {
@ -37,6 +37,7 @@ pub async fn load_state(
// let cf_descriptor = ColumnFamilyDescriptor::new(cf_name, Options::default());
let db = DB::open_default(state_path).unwrap();
let mut process_map: ProcessMap = HashMap::new();
let mut reverse_cap_index: ReverseCapIndex = HashMap::new();
let kernel_id = process_to_vec(KERNEL_PROCESS_ID.clone());
match db.get(&kernel_id) {
@ -73,11 +74,12 @@ pub async fn load_state(
home_directory_path.clone(),
runtime_extensions.clone(),
&mut process_map,
&mut reverse_cap_index,
)
.await
.unwrap();
Ok((process_map, db))
Ok((process_map, db, reverse_cap_index))
}
pub async fn state_sender(
@ -307,6 +309,7 @@ async fn bootstrap(
home_directory_path: String,
runtime_extensions: Vec<(ProcessId, MessageSender, bool)>,
process_map: &mut ProcessMap,
reverse_cap_index: &mut ReverseCapIndex,
) -> Result<()> {
// println!("bootstrapping node...\r");
@ -699,7 +702,12 @@ async fn bootstrap(
};
process
.capabilities
.insert(cap.clone(), sign_cap(cap, keypair.clone()));
.insert(cap.clone(), sign_cap(cap.clone(), keypair.clone()));
reverse_cap_index.entry(cap.clone().issuer.process)
.or_insert_with(HashMap::new)
.entry(our_process_id.parse().unwrap())
.or_insert_with(Vec::new)
.push(cap);
}
}
}
@ -719,7 +727,12 @@ async fn bootstrap(
};
process
.capabilities
.insert(cap.clone(), sign_cap(cap, keypair.clone()));
.insert(cap.clone(), sign_cap(cap.clone(), keypair.clone()));
reverse_cap_index.entry(cap.clone().issuer.process)
.or_insert_with(HashMap::new)
.entry(our_process_id.parse().unwrap())
.or_insert_with(Vec::new)
.push(cap);
}
}
}