Skip to content

Commit

Permalink
Ensure ordered routing context
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauve Signweaver committed Oct 31, 2024
1 parent a843560 commit 094b4ed
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl Backend {

let on_new_route_callback: OnNewRouteCallback = Arc::new(move |_, _| {
let inner = inner_clone.clone();
println!("Re-generating route");
tokio::spawn(async move {
let inner = inner.lock().await;

Expand All @@ -151,7 +152,9 @@ impl Backend {
});

let (route_id, route_id_blob) = make_route(&veilid_api).await?;
let routing_context = veilid_api.routing_context()?;
let routing_context = veilid_api
.routing_context()?
.with_sequencing(veilid_core::Sequencing::EnsureOrdered);

let mut inner = backend.inner.lock().await;

Expand Down Expand Up @@ -195,12 +198,15 @@ impl Backend {
let (route_id, route_id_blob) = make_route(&veilid_api).await?;

// Get veilid_api and routing_context
let routing_context = veilid_api.routing_context()?;
let routing_context = veilid_api
.routing_context()?
.with_sequencing(veilid_core::Sequencing::EnsureOrdered);

let inner_clone = self.inner.clone();

let on_new_route_callback: OnNewRouteCallback = Arc::new(move |_, _| {
let inner = inner_clone.clone();
println!("Re-generating route");
tokio::spawn(async move {
let inner = inner.lock().await;

Expand Down
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub async fn make_route(veilid: &VeilidAPI) -> Result<(RouteId, Vec<u8>)> {
.new_custom_private_route(
&VALID_CRYPTO_KINDS,
Stability::Reliable,
Sequencing::PreferOrdered,
Sequencing::EnsureOrdered,
)
.await;

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ mod tests {

let mut peer_repo = group.create_repo().await?;

sleep(Duration::from_secs(1)).await;

let group2 = backend2.join_from_url(&group.get_url()).await?;

// Upload a test blob to the peer repo
Expand Down Expand Up @@ -963,6 +965,8 @@ mod tests {
"New collection hash after uploading a file should not be empty"
);

sleep(Duration::from_secs(4)).await;

let joined_group = backend2
.join_from_url(&group1.get_url())
.await
Expand Down
3 changes: 1 addition & 2 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,8 @@ impl Repo {
// Method to retrieve a file's hash from the collection
pub async fn get_file_hash(&self, file_name: &str) -> Result<Hash> {
// Ensure the collection exists before reading
self.get_or_create_collection().await?;
let collection_hash = self.get_or_create_collection().await?;

let collection_hash = self.get_collection_hash().await?;
self.iroh_blobs
.get_file_from_collection_hash(&collection_hash, file_name)
.await
Expand Down

0 comments on commit 094b4ed

Please sign in to comment.