Skip to content

Commit

Permalink
Hardcode the subkey in a const and set it to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tripledoublev committed Sep 18, 2024
1 parent 1630b9c commit 071b406
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<u8>,
) -> 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,
)
Expand All @@ -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"))?;

Expand Down
3 changes: 2 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
pub const FAILED_TO_DESERIALIZE_KEYPAIR: &str = "Failed to deserialize keypair";
pub const ROUTE_ID_DHT_KEY: u32 = 2;
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(
Expand All @@ -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");

Expand All @@ -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");

Expand Down

0 comments on commit 071b406

Please sign in to comment.