Skip to content

Commit

Permalink
Merge pull request #68 from Cosmian/fix/make_compact_callback_async
Browse files Browse the repository at this point in the history
Fix/make compact callback async
  • Loading branch information
tbrezot committed Aug 1, 2023
2 parents 24425b3 + 367439b commit bdff0bb
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 687 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rust-analyzer.cargo.features": ["in_memory"]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [5.0.0] - 2023-07-21

### Bug Fixes

- add missing `async` keyword for compact callbacks
- fix `list_removed_locations` doc

## [4.0.3] - 2023-07-11

### Features
Expand Down
26 changes: 16 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[package]
name = "cosmian_findex"
version = "4.0.3"
version = "5.0.0"
authors = [
"Chloé Hébant <[email protected]>",
"Bruno Grieder <[email protected]>",
"Célia Corsin <[email protected]>",
"Emmanuel Coste <[email protected]>",
"Théophile Brézot <[email protected]>",
"Chloé Hébant <[email protected]>",
"Bruno Grieder <[email protected]>",
"Célia Corsin <[email protected]>",
"Emmanuel Coste <[email protected]>",
"Théophile Brézot <[email protected]>",
]
categories = ["cosmian::crypto"]
edition = "2021"
keywords = ["SSE"]
license = "MIT/Apache-2.0"
license-file = "LICENSE.md"
repository = "https://github.com/Cosmian/findex/"
description = "Symmetric Searchable Encryption"

Expand All @@ -22,18 +22,24 @@ path = "src/lib.rs"

[features]
in_memory = []
live_compact = []

[dependencies]
base64 = "0.21.2"
cosmian_crypto_core = { version = "9.0.0", features = ["aes", "sha3", "ser"], default-features = false }
cosmian_crypto_core = { version = "9.0.0", features = [
"aes",
"sha3",
"ser",
], default-features = false }
rand = "0.8"
tiny-keccak = { version = "2.0.2", features = ["kmac", "sha3"] }
zeroize = "1.5"

[dev-dependencies]
actix-rt = "2.8"
criterion = { version = "0.4", features = ["html_reports", "async_futures"], default_features = false }
criterion = { version = "0.4", features = [
"html_reports",
"async_futures",
], default_features = false }
futures = "0.3"
serde_json = "1.0"

Expand Down
2 changes: 1 addition & 1 deletion benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn bench_search(c: &mut Criterion) {
//
// Prepare indexes to be search
//
let mut findex = FindexInMemory::default();
let findex = FindexInMemory::default();
block_on(findex.add(&master_key, &label, locations_and_words)).expect("msg");

println!("Entry Table length: {}", findex.entry_table_len());
Expand Down
2 changes: 1 addition & 1 deletion examples/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
//
// Prepare indexes to be search
//
let mut findex = FindexInMemory::default();
let findex = FindexInMemory::default();
block_on(findex.add(&master_key, &label, locations_and_words)).expect("msg");

//
Expand Down
2 changes: 1 addition & 1 deletion examples/upsert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() {
hashset_keywords(&["rob"]),
);

let mut findex = FindexInMemory::default();
let findex = FindexInMemory::default();

for _ in 0..100_000 {
block_on(findex.add(&master_key, &label, indexed_value_to_keywords.clone())).unwrap();
Expand Down
14 changes: 7 additions & 7 deletions src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait FindexCallbacks<Error: std::error::Error + CallbackError, const UID_LE
///
/// - `items` : entries to be upserted
async fn upsert_entry_table(
&mut self,
&self,
items: UpsertData<UID_LENGTH>,
) -> Result<EncryptedTable<UID_LENGTH>, Error>;

Expand All @@ -93,7 +93,7 @@ pub trait FindexCallbacks<Error: std::error::Error + CallbackError, const UID_LE
/// # Parameters
///
/// - `items` : items to be inserted
async fn insert_chain_table(&mut self, items: EncryptedTable<UID_LENGTH>) -> Result<(), Error>;
async fn insert_chain_table(&self, items: EncryptedTable<UID_LENGTH>) -> Result<(), Error>;

/// Updates the indexes with the given data.
///
Expand Down Expand Up @@ -143,14 +143,14 @@ pub trait FindexCallbacks<Error: std::error::Error + CallbackError, const UID_LE
/// - `chain_table_uids_to_remove` : UIDs to remove from the Chain Table
/// - `new_entry_table_items` : new Entry Table
/// - `new_chain_table_items` : items to insert into the Chain Table
fn update_lines(
&mut self,
async fn update_lines(
&self,
chain_table_uids_to_remove: Uids<UID_LENGTH>,
new_entry_table_items: EncryptedTable<UID_LENGTH>,
new_chain_table_items: EncryptedTable<UID_LENGTH>,
) -> Result<(), Error>;

/// Returns all locations that point to existing data.
/// Returns all locations that do not point to existing data.
///
/// **NOTE**: this callback does not call the index database since indexed
/// locations can be anything in Findex (DB UID, path, other ID...). It may
Expand All @@ -159,14 +159,14 @@ pub trait FindexCallbacks<Error: std::error::Error + CallbackError, const UID_LE
/// # Parameters
///
/// - `locations` : locations queried
fn list_removed_locations(
async fn list_removed_locations(
&self,
locations: HashSet<Location>,
) -> Result<HashSet<Location>, Error>;

#[cfg(feature = "live_compact")]
/// Returns all locations that point to existing data.
fn filter_removed_locations(
async fn filter_removed_locations(
&self,
locations: HashSet<Location>,
) -> Result<HashSet<Location>, Error>;
Expand Down
21 changes: 12 additions & 9 deletions src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub trait FindexCompact<
/// **WARNING**: the compact operation *cannot* be done concurrently with
/// upsert operations. This could result in corrupted indexes.
async fn compact(
&mut self,
&self,
master_key: &KeyingMaterial<MASTER_KEY_LENGTH>,
new_master_key: &KeyingMaterial<MASTER_KEY_LENGTH>,
label: &Label,
Expand Down Expand Up @@ -155,13 +155,15 @@ pub trait FindexCompact<
// calling for one location batch for one word to add noise and prevent
// the database the size of the chains for each keywords.
//
let removed_locations = self.list_removed_locations(
reindexed_chain_values
.values()
.flat_map(|chain| chain.iter().filter_map(IndexedValue::get_location))
.cloned()
.collect(),
)?;
let removed_locations = self
.list_removed_locations(
reindexed_chain_values
.values()
.flat_map(|chain| chain.iter().filter_map(IndexedValue::get_location))
.cloned()
.collect(),
)
.await?;

for entry_table_uid in entry_table_items_to_reindex {
let entry_table_value = entry_table.get(&entry_table_uid).ok_or_else(|| {
Expand Down Expand Up @@ -243,7 +245,8 @@ pub trait FindexCompact<
chain_table_uids_to_remove,
entry_table.encrypt(&mut rng, &new_k_value)?,
chain_table_adds,
)?;
)
.await?;

Ok(())
}
Expand Down
Loading

0 comments on commit bdff0bb

Please sign in to comment.