mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-20 07:01:40 +03:00
state: do not hash process_ids for keys
This commit is contained in:
parent
ee4aa1d282
commit
fe1e4c7d1a
18
src/state.rs
18
src/state.rs
@ -32,8 +32,8 @@ pub async fn load_state(
|
|||||||
let db = DB::open_default(state_path).unwrap();
|
let db = DB::open_default(state_path).unwrap();
|
||||||
let mut process_map: ProcessMap = HashMap::new();
|
let mut process_map: ProcessMap = HashMap::new();
|
||||||
|
|
||||||
let kernel_id = KERNEL_PROCESS_ID.to_hash();
|
let kernel_id = process_to_vec(KERNEL_PROCESS_ID.clone());
|
||||||
match db.get(kernel_id) {
|
match db.get(&kernel_id) {
|
||||||
Ok(Some(value)) => {
|
Ok(Some(value)) => {
|
||||||
process_map = bincode::deserialize::<ProcessMap>(&value).unwrap();
|
process_map = bincode::deserialize::<ProcessMap>(&value).unwrap();
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ pub async fn load_state(
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
db.put(kernel_id, bincode::serialize(&process_map).unwrap())
|
db.put(&kernel_id, bincode::serialize(&process_map).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -145,8 +145,8 @@ async fn handle_request(
|
|||||||
|
|
||||||
let (ipc, bytes) = match action {
|
let (ipc, bytes) = match action {
|
||||||
StateAction::SetState(process_id) => {
|
StateAction::SetState(process_id) => {
|
||||||
let key = process_id.to_hash();
|
let key = process_to_vec(process_id);
|
||||||
// TODO consistency with to_stirngs
|
|
||||||
let Some(ref payload) = payload else {
|
let Some(ref payload) = payload else {
|
||||||
return Err(StateError::BadBytes {
|
return Err(StateError::BadBytes {
|
||||||
action: "SetState".into(),
|
action: "SetState".into(),
|
||||||
@ -157,7 +157,7 @@ async fn handle_request(
|
|||||||
(serde_json::to_vec(&StateResponse::SetState).unwrap(), None)
|
(serde_json::to_vec(&StateResponse::SetState).unwrap(), None)
|
||||||
}
|
}
|
||||||
StateAction::GetState(process_id) => {
|
StateAction::GetState(process_id) => {
|
||||||
let key = process_id.to_hash();
|
let key = process_to_vec(process_id.clone());
|
||||||
match db.get(key) {
|
match db.get(key) {
|
||||||
Ok(Some(value)) => (
|
Ok(Some(value)) => (
|
||||||
serde_json::to_vec(&StateResponse::GetState).unwrap(),
|
serde_json::to_vec(&StateResponse::GetState).unwrap(),
|
||||||
@ -178,7 +178,7 @@ async fn handle_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
StateAction::DeleteState(process_id) => {
|
StateAction::DeleteState(process_id) => {
|
||||||
let key = process_id.to_hash();
|
let key = process_to_vec(process_id);
|
||||||
match db.delete(key) {
|
match db.delete(key) {
|
||||||
Ok(_) => (
|
Ok(_) => (
|
||||||
serde_json::to_vec(&StateResponse::DeleteState).unwrap(),
|
serde_json::to_vec(&StateResponse::DeleteState).unwrap(),
|
||||||
@ -623,6 +623,10 @@ fn make_error_message(our_name: String, km: &KernelMessage, error: StateError) -
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn process_to_vec(process: ProcessId) -> Vec<u8> {
|
||||||
|
process.to_string().as_bytes().to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
impl From<std::io::Error> for VfsError {
|
impl From<std::io::Error> for VfsError {
|
||||||
fn from(err: std::io::Error) -> Self {
|
fn from(err: std::io::Error) -> Self {
|
||||||
VfsError::IOError {
|
VfsError::IOError {
|
||||||
|
@ -153,13 +153,6 @@ impl ProcessId {
|
|||||||
pub fn publisher(&self) -> &str {
|
pub fn publisher(&self) -> &str {
|
||||||
&self.publisher_node
|
&self.publisher_node
|
||||||
}
|
}
|
||||||
pub fn to_hash(&self) -> [u8; 32] {
|
|
||||||
let mut hasher = blake3::Hasher::new();
|
|
||||||
hasher.update(self.process_name.as_bytes());
|
|
||||||
hasher.update(self.package_name.as_bytes());
|
|
||||||
hasher.update(self.publisher_node.as_bytes());
|
|
||||||
hasher.finalize().into()
|
|
||||||
}
|
|
||||||
pub fn en_wit(&self) -> wit::ProcessId {
|
pub fn en_wit(&self) -> wit::ProcessId {
|
||||||
wit::ProcessId {
|
wit::ProcessId {
|
||||||
process_name: self.process_name.clone(),
|
process_name: self.process_name.clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user