From 071b40637fffbda26ef116c304acfb201186f964 Mon Sep 17 00:00:00 2001 From: tripledoublev Date: Wed, 18 Sep 2024 14:49:35 +0200 Subject: [PATCH] Hardcode the subkey in a const and set it to 2 --- src/common.rs | 8 ++++---- src/constants.rs | 3 ++- src/lib.rs | 9 +++------ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/common.rs b/src/common.rs index 27797e8..ec92d9e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,7 @@ #![allow(async_fn_in_trait)] #![allow(clippy::async_yields_async)] +use crate::constants::ROUTE_ID_DHT_KEY; use serde::{Serialize, Deserialize}; use eyre::{Result, anyhow}; use std::sync::Arc; @@ -100,16 +101,15 @@ pub trait DHTEntity { Ok(()) } - async fn store_route_id_in_dht( + async fn store_route_id_in_dht( &self, - subkey: u32, route_id_blob: Vec, ) -> Result<()> { let routing_context = &self.get_routing_context(); let dht_record = self.get_dht_record(); routing_context.set_dht_value( dht_record.key().clone(), - subkey, + ROUTE_ID_DHT_KEY, route_id_blob, None, ) @@ -127,7 +127,7 @@ pub trait DHTEntity { // Get the stored route ID blob at subkey let stored_blob = routing_context - .get_dht_value(dht_record.key().clone(), subkey, false) + .get_dht_value(dht_record.key().clone(), ROUTE_ID_DHT_KEY, false) .await? .ok_or_else(|| anyhow!("Route ID blob not found in DHT"))?; diff --git a/src/constants.rs b/src/constants.rs index 1354be5..bafb8f1 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -5,4 +5,5 @@ pub const TEST_GROUP_NAME: &str = "Test Group"; pub const UNABLE_TO_STORE_KEYPAIR: &str = "Unable to store keypair"; pub const FAILED_TO_LOAD_KEYPAIR: &str = "Failed to load keypair"; pub const KEYPAIR_NOT_FOUND: &str = "Keypair not found"; -pub const FAILED_TO_DESERIALIZE_KEYPAIR: &str = "Failed to deserialize keypair"; \ No newline at end of file +pub const FAILED_TO_DESERIALIZE_KEYPAIR: &str = "Failed to deserialize keypair"; +pub const ROUTE_ID_DHT_KEY: u32 = 2; diff --git a/src/lib.rs b/src/lib.rs index 1a35c47..4aa509b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ pub mod backend; pub mod common; pub mod constants; -use crate::constants::{GROUP_NOT_FOUND, UNABLE_TO_SET_GROUP_NAME, UNABLE_TO_GET_GROUP_NAME, TEST_GROUP_NAME, UNABLE_TO_STORE_KEYPAIR, FAILED_TO_LOAD_KEYPAIR, KEYPAIR_NOT_FOUND, FAILED_TO_DESERIALIZE_KEYPAIR}; +use crate::constants::{GROUP_NOT_FOUND, UNABLE_TO_SET_GROUP_NAME, UNABLE_TO_GET_GROUP_NAME, TEST_GROUP_NAME, UNABLE_TO_STORE_KEYPAIR, FAILED_TO_LOAD_KEYPAIR, KEYPAIR_NOT_FOUND, FAILED_TO_DESERIALIZE_KEYPAIR, ROUTE_ID_DHT_KEY}; use crate::backend::Backend; use crate::common::{CommonKeypair, DHTEntity}; @@ -108,9 +108,6 @@ mod tests { // Get VeilidAPI instance from backend let veilid_api = backend.get_veilid_api().expect("Failed to get VeilidAPI instance"); - // Define the subkey - let subkey = 2u32; - // Create a new private route let (route_id, route_id_blob) = veilid_api .new_custom_private_route( @@ -123,7 +120,7 @@ mod tests { // Store the route_id_blob in DHT loaded_repo - .store_route_id_in_dht(subkey, route_id_blob.clone()) + .store_route_id_in_dht(route_id_blob.clone()) .await .expect("Failed to store route ID blob in DHT"); @@ -132,7 +129,7 @@ mod tests { // Send the message loaded_repo - .send_message_to_owner(veilid_api, message.clone(), subkey) + .send_message_to_owner(veilid_api, message.clone(), ROUTE_ID_DHT_KEY) .await .expect("Failed to send message to repo owner");