Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions components/controller/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use keri_core::{
actor::prelude::VersionError, database::redb::RedbError,
event_message::cesr_adapter::ParseError, oobi::Scheme, prefix::IdentifierPrefix,
processor::validator::VerificationError,
event_message::cesr_adapter::ParseError, oobi::Scheme, oobi::error::OobiError,
prefix::IdentifierPrefix, processor::validator::VerificationError,
};
use thiserror::Error;

Expand Down Expand Up @@ -58,9 +58,18 @@ pub enum ControllerError {
#[error("Error: {0}")]
OtherError(String),

#[error("Oobi error: {0}")]
OobiError(String),

#[error(transparent)]
Mechanic(#[from] MechanicsError),

#[error("Watcher response error: {0}")]
WatcherResponseError(#[from] WatcherResponseError),
}

impl From<OobiError> for ControllerError {
fn from(e: OobiError) -> Self {
ControllerError::OobiError(e.to_string())
}
}
12 changes: 9 additions & 3 deletions components/controller/src/known_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ use crate::identifier::mechanics::MechanicsError;
pub enum OobiRetrieveError {
#[error("No oobi for {0} identifier")]
MissingOobi(IdentifierPrefix, Option<Scheme>),
#[error(transparent)]
DbError(#[from] RedbError),
#[error("Database error: {0}")]
DbError(String),
}

impl From<keri_core::oobi::error::OobiError> for OobiRetrieveError {
fn from(e: keri_core::oobi::error::OobiError) -> Self {
OobiRetrieveError::DbError(e.to_string())
}
}

pub struct KnownEvents {
Expand All @@ -62,7 +68,7 @@ impl KnownEvents {
Arc::new(RedbDatabase::new(&path)?)
};

let oobi_manager = OobiManager::new(event_database.clone());
let oobi_manager = OobiManager::new(event_database.clone())?;

let (
mut notification_bus,
Expand Down
8 changes: 4 additions & 4 deletions components/watcher/src/watcher/watcher_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{fs::File, sync::Arc};
use futures::future::join_all;
use itertools::Itertools;
use keri_core::actor::possible_response::PossibleResponse;
use keri_core::database::redb::RedbError;
use keri_core::error::Error;
use keri_core::oobi::error::OobiError;
use keri_core::oobi::LocationScheme;
use keri_core::prefix::{BasicPrefix, IdentifierPrefix, SelfSigningPrefix};
use keri_core::processor::escrow::default_escrow_bus;
Expand Down Expand Up @@ -97,7 +97,7 @@ impl WatcherData {
Arc::new(RedbDatabase::new(&path).unwrap())
};

let oobi_manager = OobiManager::new(events_db.clone());
let oobi_manager = OobiManager::new(events_db.clone())?;

let (mut notification_bus, _) = default_escrow_bus(events_db.clone(), escrow_config);
let reply_escrow = Arc::new(ReplyEscrow::new(events_db.clone()));
Expand All @@ -112,7 +112,7 @@ impl WatcherData {
let prefix = BasicPrefix::Ed25519NT(signer.public_key()); // watcher uses non transferable key
let processor = BasicProcessor::new(events_db.clone(), Some(notification_bus));

let storage = Arc::new(EventStorage::new(events_db));
let storage = Arc::new(EventStorage::new_redb(events_db));

// construct witness loc scheme oobi
let loc_scheme = LocationScheme::new(
Expand Down Expand Up @@ -529,7 +529,7 @@ impl WatcherData {
}

/// Query roles in oobi manager to check if controller with given ID is allowed to communicate with us.
fn check_role(&self, cid: &IdentifierPrefix) -> Result<bool, RedbError> {
fn check_role(&self, cid: &IdentifierPrefix) -> Result<bool, OobiError> {
Ok(self
.oobi_manager
.get_end_role(cid, Role::Watcher)?
Expand Down
6 changes: 3 additions & 3 deletions components/witness/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn test_not_fully_witnessed() -> Result<(), Error> {
let not = Notice::Event(inception_event.clone());
w.process_notice(not).unwrap();
w.event_storage
.mailbox_data
.mailbox_data.as_ref().unwrap()
.get_mailbox_receipts(controller.prefix(), 0)
.into_iter()
.flatten()
Expand Down Expand Up @@ -185,7 +185,7 @@ fn test_not_fully_witnessed() -> Result<(), Error> {
// first_witness.respond(signer_arc.clone())?;
let first_receipt = first_witness
.event_storage
.mailbox_data
.mailbox_data.as_ref().unwrap()
.get_mailbox_receipts(controller.prefix(), 0)
.unwrap()
.map(Notice::NontransferableRct)
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_qry_rpy() -> Result<(), ActorError> {
// send receipts to alice
let receipt_to_alice = witness
.event_storage
.mailbox_data
.mailbox_data.as_ref().unwrap()
.get_mailbox_receipts(alice.prefix(), 0)
.unwrap()
.map(Notice::NontransferableRct)
Expand Down
12 changes: 9 additions & 3 deletions components/witness/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Notifier for WitnessReceiptGenerator {

impl WitnessReceiptGenerator {
pub fn new(signer: Arc<Signer>, events_db: Arc<RedbDatabase>) -> Self {
let storage = EventStorage::new(events_db.clone());
let storage = EventStorage::new_redb(events_db.clone());
let prefix = BasicPrefix::Ed25519NT(signer.public_key());
Self {
prefix,
Expand Down Expand Up @@ -137,6 +137,12 @@ impl From<RedbError> for WitnessError {
}
}

impl From<keri_core::oobi::error::OobiError> for WitnessError {
fn from(err: keri_core::oobi::error::OobiError) -> Self {
WitnessError::DatabaseError(err.to_string())
}
}

pub struct Witness {
pub address: Url,
pub prefix: BasicPrefix,
Expand Down Expand Up @@ -172,7 +178,7 @@ impl Witness {
let events_db =
Arc::new(RedbDatabase::new(&events_database_path).map_err(|_| Error::DbError)?);
let mut witness_processor = WitnessProcessor::new(events_db.clone(), escrow_config);
let event_storage = Arc::new(EventStorage::new(events_db.clone()));
let event_storage = Arc::new(EventStorage::new_redb(events_db.clone()));

let receipt_generator = Arc::new(WitnessReceiptGenerator::new(
signer.clone(),
Expand Down Expand Up @@ -217,7 +223,7 @@ impl Witness {
signer,
event_storage,
receipt_generator,
oobi_manager: OobiManager::new(events_db.clone()),
oobi_manager: OobiManager::new(events_db.clone())?,
tel,
})
}
Expand Down
14 changes: 10 additions & 4 deletions keriox_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ repository.workspace = true
crate-type = ["cdylib", "rlib"]

[features]
default = []
default = ["storage-redb"]
storage-redb = ["redb"]
storage-postgres = ["sqlx", "async-std"]
query = ["serde_cbor"]
oobi = ["url", "strum_macros", "strum"]
oobi-manager = ["oobi", "query", "reqwest", "async-trait", "serde_cbor"]
mailbox = ["query", "serde_cbor"]
oobi-manager = ["oobi", "query", "storage-redb", "reqwest", "async-trait", "serde_cbor"]
mailbox = ["query", "storage-redb", "serde_cbor"]

[dependencies]
bytes = "1.3.0"
Expand All @@ -43,7 +45,11 @@ chrono = { version = "0.4.18", features = ["serde"] }
arrayref = "0.3.6"
zeroize = "1.3.0"
fraction = { version = "0.9", features = ["with-serde-support"] }
redb = "2.3.0"
redb = { version = "2.3.0", optional = true }

# postgres db deps
sqlx = { version = "0.8", features = ["runtime-async-std", "postgres"], optional = true }
async-std = { version = "1", features = ["attributes"], optional = true }

# oobis dependecies
async-trait = { version = "0.1.57", optional = true }
Expand Down
2 changes: 2 additions & 0 deletions keriox_core/src/actor/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use http::StatusCode;

#[cfg(feature = "storage-redb")]
use crate::database::redb::RedbError;
use crate::event_message::cesr_adapter::ParseError;
use crate::keys::KeysError;
Expand Down Expand Up @@ -74,6 +75,7 @@ impl From<VersionError> for ActorError {
}
}

#[cfg(feature = "storage-redb")]
impl From<RedbError> for ActorError {
fn from(err: RedbError) -> Self {
ActorError::DbError(err.to_string())
Expand Down
10 changes: 5 additions & 5 deletions keriox_core/src/actor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::convert::TryFrom;
use serde::{Deserialize, Serialize};

#[cfg(feature = "oobi-manager")]
use crate::oobi_manager::OobiManager;
use crate::oobi_manager::{storage::OobiStorageBackend, OobiManager};
#[cfg(feature = "query")]
use crate::{
database::EventDatabase,
Expand Down Expand Up @@ -91,9 +91,9 @@ pub fn process_notice<P: Processor>(msg: Notice, processor: &P) -> Result<(), Er
}

#[cfg(feature = "query")]
pub fn process_reply<P: Processor>(
pub fn process_reply<P: Processor, #[cfg(feature = "oobi-manager")] S: OobiStorageBackend>(
sr: SignedReply,
#[cfg(feature = "oobi-manager")] oobi_manager: &OobiManager,
#[cfg(feature = "oobi-manager")] oobi_manager: &OobiManager<S>,
processor: &P,
event_storage: &EventStorage<P::Database>,
) -> Result<(), Error> {
Expand All @@ -108,9 +108,9 @@ pub fn process_reply<P: Processor>(
}

#[cfg(feature = "oobi-manager")]
pub fn process_signed_oobi<D: EventDatabase + 'static>(
pub fn process_signed_oobi<D: EventDatabase + 'static, S: OobiStorageBackend>(
signed_oobi: &SignedReply,
oobi_manager: &OobiManager,
oobi_manager: &OobiManager<S>,
event_storage: &EventStorage<D>,
) -> Result<(), Error> {
use crate::processor::validator::EventValidator;
Expand Down
7 changes: 5 additions & 2 deletions keriox_core/src/actor/simple_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::{
sync::{Arc, Mutex},
};

#[cfg(feature = "storage-redb")]
use crate::database::redb::RedbDatabase;
use crate::{
database::{redb::RedbDatabase, EscrowCreator, EventDatabase},
database::{EscrowCreator, EventDatabase},
processor::escrow::{
maybe_out_of_order_escrow::MaybeOutOfOrderEscrow,
partially_witnessed_escrow::PartiallyWitnessedEscrow,
Expand Down Expand Up @@ -72,6 +74,7 @@ pub struct SimpleController<K: KeyManager + 'static, D: EventDatabase + EscrowCr
}

// impl<K: KeyManager, D: EventDatabase + Send + Sync + 'static> SimpleController<K, D> {
#[cfg(feature = "storage-redb")]
impl<K: KeyManager> SimpleController<K, RedbDatabase> {
// incept a state and keys
pub fn new(
Expand All @@ -86,7 +89,7 @@ impl<K: KeyManager> SimpleController<K, RedbDatabase> {
Ok(SimpleController {
prefix: IdentifierPrefix::default(),
key_manager,
oobi_manager: OobiManager::new(event_db.clone()),
oobi_manager: OobiManager::new(event_db.clone())?,
processor,
storage: EventStorage::new(event_db.clone()),
groups: vec![],
Expand Down
Loading