Skip to content

Commit

Permalink
UNSTABLE : WIP on redis
Browse files Browse the repository at this point in the history
  • Loading branch information
HatemMn committed Dec 3, 2024
1 parent a4366ae commit 52b6f6f
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ actix-web = { version = "4.9.0", default-features = false }
base64 = "0.21"
clap = { version = "4.5", default-features = false }
# cloudproof_findex = { path = "../cloudproof_rust/crates/findex" }
# todo(Hatem) : DELET THE PACKAGE BELOW, PURGE IT
cloudproof_findex = { git = "https://www.github.com/Cosmian/cloudproof_rust", branch = "feat/add_basic_findex_rest_client" }
# cosmian_config_utils = { path ="../../core/client_server/crate/config_utils" }
# cosmian_http_client = { path ="../../core/client_server/crate/http_client" }
Expand All @@ -66,4 +67,4 @@ url = "2.5"
x509-parser = "0.16"
zeroize = { version = "1.8", default-features = false }
uuid = { version = "1.10", features = ["v4"] }
cosmian_findex = { git = "https://github.com/Cosmian/findex", branch = "feat/prepare_findex_server_v7" }
cosmian_findex = { git = "https://github.com/Cosmian/findex", branch = "feat/update_for_findex_server" }
1 change: 1 addition & 0 deletions crate/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ clap = { workspace = true, features = [
"derive",
"cargo",
] }
# TODO(hatem) : DELET THE PACKAGE BELOW, PURGE IT
cloudproof_findex = { workspace = true, features = ["redis-interface"] }
cosmian_findex = { workspace = true, features = ["redis-mem"] }
cosmian_findex_structs = { path = "../structs" }
Expand Down
8 changes: 4 additions & 4 deletions crate/server/src/config/params/db_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ use std::fmt::{self, Display};
use url::Url;

pub enum DbParams {
Redis(Url),
Redis(Url, usize),
}

impl DbParams {
/// Return the name of the database type
#[must_use]
pub const fn db_name(&self) -> &str {
match &self {
Self::Redis(_) => "Redis",
Self::Redis(_, _) => "Redis",
}
}
}

impl Display for DbParams {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Redis(url) => {
write!(f, "redis: {}", redact_url(url),)
Self::Redis(url, w) => {
write!(f, "redis : {} | Word length = {}", redact_url(url), w)
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions crate/server/src/database/database_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use cosmian_findex::{Address, MemoryADT, ADDRESS_LENGTH};

use super::database_traits::FindexMemoryTrait;

pub(crate) struct FindexDatabase<const WORD_LENGTH: usize> {
pub(crate) memory: usize,
}
52 changes: 15 additions & 37 deletions crate/server/src/database/database_traits.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,27 @@
use async_trait::async_trait;
use cloudproof_findex::{
db_interfaces::{redis::FindexTable, rest::UpsertData},
reexport::cosmian_findex::{
TokenToEncryptedValueMap, TokenWithEncryptedValueList, Tokens, ENTRY_LENGTH, LINK_LENGTH,
},
};

use cosmian_findex::{Address, MemoryADT, ADDRESS_LENGTH};
use cosmian_findex_structs::{EncryptedEntries, Permission, Permissions, Uuids};
use uuid::Uuid;

use crate::error::result::FResult;

#[async_trait]
pub(crate) trait FindexTrait: Sync + Send {
use super::redis::WORD_LENGTH;

pub(crate) trait FindexMemoryTrait:
Send + Sync + Clone + MemoryADT<Address = Address<ADDRESS_LENGTH>, Word = [u8; WORD_LENGTH]>
{
//
// Findex v6
// Findex
//
async fn findex_fetch_entries(
&self,
index_id: &Uuid,
tokens: Tokens,
) -> FResult<TokenWithEncryptedValueList<ENTRY_LENGTH>>;
async fn findex_fetch_chains(
&self,
index_id: &Uuid,
tokens: Tokens,
) -> FResult<TokenWithEncryptedValueList<LINK_LENGTH>>;
async fn findex_upsert_entries(
&self,
index_id: &Uuid,
upsert_data: UpsertData<ENTRY_LENGTH>,
) -> FResult<TokenToEncryptedValueMap<ENTRY_LENGTH>>;
async fn findex_insert_chains(
&self,
index_id: &Uuid,
items: TokenToEncryptedValueMap<LINK_LENGTH>,
) -> FResult<()>;
async fn findex_delete(
&self,
index_id: &Uuid,
findex_table: FindexTable,
tokens: Tokens,
) -> FResult<()>;
async fn findex_dump_tokens(&self, index_id: &Uuid) -> FResult<Tokens>;
}

pub(crate) type Asba = dyn FindexMemoryTrait<
Word = [u8; WORD_LENGTH],
Address = Address<ADDRESS_LENGTH>,
Error = dyn Send + Sync + std::error::Error,
>;

#[async_trait]
pub(crate) trait PermissionsTrait: Sync + Send {
//
Expand Down Expand Up @@ -77,4 +55,4 @@ pub(crate) trait DatasetsTrait: Sync + Send {
}

#[async_trait]
pub(crate) trait DatabaseTraits: FindexTrait + PermissionsTrait + DatasetsTrait {}
pub(crate) trait DatabaseTraits: PermissionsTrait + DatasetsTrait {}
1 change: 1 addition & 0 deletions crate/server/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod database_struct;
mod database_traits;
mod redis;

Expand Down
10 changes: 5 additions & 5 deletions crate/server/src/database/redis/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use redis::pipe;
use tracing::{instrument, trace};
use uuid::Uuid;

use super::Redis;
use super::{ServerRedis, WORD_LENGTH};
use crate::{
database::database_traits::DatasetsTrait,
error::{result::FResult, server::FindexServerError},
Expand All @@ -18,7 +18,7 @@ fn build_dataset_key(index_id: &Uuid, uid: &Uuid) -> Vec<u8> {
}

#[async_trait]
impl DatasetsTrait for Redis {
impl DatasetsTrait for ServerRedis<WORD_LENGTH> {
//
// Dataset management
//
Expand All @@ -34,7 +34,7 @@ impl DatasetsTrait for Redis {
pipe.set(key, data);
}
pipe.atomic()
.query_async(&mut self.mgr.clone())
.query_async(&mut self.memory.manager.clone())
.await
.map_err(FindexServerError::from)
}
Expand All @@ -47,7 +47,7 @@ impl DatasetsTrait for Redis {
pipe.del(key);
}
pipe.atomic()
.query_async(&mut self.mgr.clone())
.query_async(&mut self.memory.manager.clone())
.await
.map_err(FindexServerError::from)
}
Expand All @@ -70,7 +70,7 @@ impl DatasetsTrait for Redis {
}
let values: Vec<Vec<u8>> = pipe
.atomic()
.query_async(&mut self.mgr.clone())
.query_async(&mut self.memory.manager.clone())
.await
.map_err(FindexServerError::from)?;

Expand Down
Loading

0 comments on commit 52b6f6f

Please sign in to comment.