Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding messaging plugin container with the various messaging plugins #219

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
820268f
adding meesaging plugin container with the various messaging plugins
ndefokou Oct 16, 2024
753fa22
Merge branch 'main' into 203-add-a-messaging-plugin-container-with-th…
ndefokou Oct 16, 2024
5bf46a1
adding meesaging plugin container with the various messaging plugins
ndefokou Oct 16, 2024
70c4ac9
resolving conflicts
ndefokou Oct 17, 2024
015aca1
implimenting a handler for protocol-plugins
ndefokou Oct 22, 2024
0ef4874
removing keystore and databade from didcomm-messaging
ndefokou Oct 23, 2024
bc06447
removing keystore and databade from didcomm-messaging
ndefokou Oct 23, 2024
e246f72
removing the cargo.toml in the root of traite and modifying the handler
ndefokou Oct 23, 2024
7969e22
fixing the test
ndefokou Oct 23, 2024
8611847
renaming didcom-mediator to didcom-messaging
ndefokou Oct 24, 2024
523a078
updating the protocole manager
ndefokou Oct 29, 2024
93e6958
Adjusting the manager and the implementation of the protocols.
ndefokou Oct 31, 2024
99a7012
Adjusting the manager and the implementation of the protocols.
ndefokou Nov 4, 2024
1b32b17
Adjusting the manager and the implementation of the protocols.
ndefokou Nov 5, 2024
976e6c0
Adjusting the manager and the implementation of the protocols.
ndefokou Nov 5, 2024
03dc8ce
implementing the route fn for the manager in didcomm-messaging
ndefokou Nov 6, 2024
f62819c
fixing the route fn and modifying protocol.rs
ndefokou Nov 7, 2024
28890b2
implimenting plugin in the different protocols
ndefokou Nov 8, 2024
2d82527
implimenting plugin in the different protocols
ndefokou Nov 8, 2024
a8b9bc1
Merge branch 'main' into 203-add-a-messaging-plugin-container-with-th…
ndefokou Nov 11, 2024
e4bbf90
adjusting the output on message api
ndefokou Nov 12, 2024
4e92320
adjusting the output on message api
ndefokou Nov 13, 2024
c13cade
fixe():adjusting the message-api
ndefokou Nov 14, 2024
e31ca83
fixe():adjusting the message-api
ndefokou Nov 14, 2024
4ff2b02
fixe():adjusting the message-api
ndefokou Nov 14, 2024
6fcc46b
fixe():adjusting the message-api
ndefokou Nov 14, 2024
1a7bb5f
Fix conflicts
Hermann-Core Nov 15, 2024
f4b884f
define the message plugin API
Hermann-Core Nov 15, 2024
f263a54
Implement the didcomm messages plugin container
Hermann-Core Nov 15, 2024
9a34103
feat(didcomm-messaging): add dynamic handler registration and dispatc…
Hermann-Core Nov 18, 2024
50beae0
Merge remote-tracking branch 'origin/main' into 203-add-a-messaging-p…
Hermann-Core Nov 18, 2024
9ba0921
Adding test on manager.rs
ndefokou Nov 19, 2024
b17a748
Adding Debug trait
ndefokou Nov 19, 2024
988c026
fixe(): crate.io
ndefokou Nov 19, 2024
433d86d
fixe(): MessagePluginContainer
ndefokou Nov 20, 2024
1d44c98
improve the didcomm message container loading logic
Hermann-Core Nov 22, 2024
be8c08d
improve the message container loading logic
Hermann-Core Nov 22, 2024
687f0ea
fix didcomm messages dynamic dispatch tests failures
Hermann-Core Nov 25, 2024
067b04a
Merge remote-tracking branch 'origin/main' into 203-add-a-messaging-p…
Hermann-Core Nov 25, 2024
ca87e8d
fix tests
Hermann-Core Nov 25, 2024
4691022
fix CI yaml syntax error
Hermann-Core Nov 25, 2024
02b638a
fix formatting
Hermann-Core Nov 25, 2024
cf6b64c
fixe(); Removing the test for unloading plugin
ndefokou Nov 25, 2024
d4d8f8a
fixe(): resolving conflicts
ndefokou Nov 25, 2024
30e7f51
fixe(): formating the handler file
ndefokou Nov 25, 2024
7fb2f98
fixe(): formating the files
ndefokou Nov 25, 2024
d25bf4e
fixe(): adding constant in workspace
ndefokou Nov 25, 2024
d8b5eb9
fixe(): removing constant in workspace
ndefokou Nov 25, 2024
bf11879
Merge remote-tracking branch 'origin/main' into 203-add-a-messaging-p…
Hermann-Core Nov 26, 2024
128c317
fix code formatting
Hermann-Core Nov 26, 2024
efcfed0
integrate the discover-features protocol to didcomm messaging plugin
Hermann-Core Nov 26, 2024
f8faee6
add missing discover-features feature to the workspace manifest file
Hermann-Core Nov 27, 2024
f111f96
clean up the dynamic didcomm messages dispatch implementation
Hermann-Core Nov 27, 2024
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
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ members = [
"crates/web-plugins/didcomm-messaging/protocols/*",
]


[workspace.dependencies]
database = { path = "./crates/database", version = "0.1.0" }
filesystem = { path = "./crates/filesystem", version = "0.1.0" }
Expand All @@ -37,12 +36,14 @@ oob-messages = { path = "./crates/web-plugins/oob-messages", version = "0.1.0" }
didcomm-messaging = { path = "./crates/web-plugins/didcomm-messaging", version = "0.1.0" }
did-utils = { path = "./crates/web-plugins/didcomm-messaging/did-utils", version = "0.1.0" }
shared = { path = "./crates/web-plugins/didcomm-messaging/shared", version = "0.1.0" }
message-api = { path = "./crates/web-plugins/didcomm-messaging/message-api", version = "0.1.0" }
pickup = { path = "./crates/web-plugins/didcomm-messaging/protocols/pickup", version = "0.1.0" }
forward = { path = "./crates/web-plugins/didcomm-messaging/protocols/forward", version = "0.1.0" }
trust-ping = { path = "./crates/web-plugins/didcomm-messaging/protocols/trust-ping", version = "0.1.0" }
discover-features = { path = "./crates/web-plugins/didcomm-messaging/protocols/discover-features", version = "0.1.0" }
mediator-coordination = { path = "./crates/web-plugins/didcomm-messaging/protocols/mediator-coordination", version = "0.1.0" }


# Other common dependencies
serde = "1.0"
sha2 = "0.10"
Expand Down Expand Up @@ -127,6 +128,12 @@ plugin-did_endpoint = ["dep:did-endpoint"]
plugin-oob_messages = ["dep:oob-messages"]
plugin-didcomm_messaging = ["dep:didcomm-messaging"]

routing = ["plugin-didcomm_messaging", "didcomm-messaging/routing"]
pickup = ["plugin-didcomm_messaging", "didcomm-messaging/pickup"]
trust-ping = ["plugin-didcomm_messaging", "didcomm-messaging/trust-ping"]
discover-features = ["plugin-didcomm_messaging", "didcomm-messaging/discover-features"]
mediator-coordination = ["plugin-didcomm_messaging", "didcomm-messaging/mediator-coordination"]


[dev-dependencies]
tower = { version = "0.4.13", features = ["util"] }
2 changes: 1 addition & 1 deletion crates/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["full"] }

[features]
test-utils = []
test-utils = []
32 changes: 27 additions & 5 deletions crates/web-plugins/didcomm-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,45 @@ keystore.workspace = true
shared.workspace = true
plugin-api.workspace = true
filesystem.workspace = true
forward.workspace = true
pickup.workspace = true
trust-ping.workspace = true
discover-features.workspace = true
mediator-coordination.workspace = true
message-api.workspace = true

# optional dependencies
forward = { workspace = true, optional = true }
pickup = { workspace = true, optional = true }
trust-ping = { workspace = true, optional = true }
discover-features = { workspace = true, optional = true }
mediator-coordination = { workspace = true, optional = true }

mongodb.workspace = true
didcomm.workspace = true
tracing.workspace = true
once_cell.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
hyper = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["macros"] }
serde = { version = "1.0", features = ["derive"] }


[features]
default = [
"routing",
"pickup",
"trust-ping",
"discover-features",
"mediator-coordination",
]

routing = ["dep:forward"]
pickup = ["dep:pickup"]
trust-ping = ["dep:trust-ping"]
discover-features = ["dep:discover-features"]
mediator-coordination = ["dep:mediator-coordination"]


[dev-dependencies]
async-trait.workspace = true
mockall = "0.13.0"
uuid = { workspace = true, features = ["v4"] }
json-canon = "0.1.3"
Expand Down
27 changes: 27 additions & 0 deletions crates/web-plugins/didcomm-messaging/message-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "message-api"
version = "0.1.0"
edition = "2021"

[dependencies]
keystore.workspace = true
shared.workspace = true
database.workspace = true
filesystem.workspace = true

async-trait.workspace = true
mongodb.workspace = true
anyhow.workspace = true
tracing.workspace = true
serde_json.workspace = true
thiserror.workspace = true
didcomm = { workspace = true, features = ["uniffi"] }
hyper = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["macros"] }

[dev-dependencies]
keystore = { workspace = true, features = ["test-utils"] }
shared = { workspace = true, features = ["test-utils"] }
did-utils.workspace = true
uuid = { workspace = true, features = ["v4"] }
tokio = { version = "1.27.0", default-features = false, features = ["macros", "rt"] }
53 changes: 53 additions & 0 deletions crates/web-plugins/didcomm-messaging/message-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use async_trait::async_trait;
use axum::response::Response;
use didcomm::Message;
use shared::state::AppState;
use std::{collections::HashMap, sync::Arc};

#[async_trait]
pub trait MessageHandler: Send + Sync {
async fn handle(&self, state: Arc<AppState>, msg: Message)
-> Result<Option<Message>, Response>;
}

#[derive(Default, Clone)]
pub struct MessageRouter {
handlers: HashMap<String, Arc<dyn MessageHandler>>,
}

impl MessageRouter {
pub fn new() -> Self {
Self {
handlers: HashMap::new(),
}
}

pub fn register<F>(mut self, msg: &str, f: F) -> Self
where
F: MessageHandler + 'static,
{
self.handlers.insert(msg.to_string(), Arc::new(f));
self
}

pub fn merge(mut self, other: Self) -> Self {
self.handlers.extend(other.handlers);
self
}

pub fn get_handler(&self, msg: &str) -> Option<&Arc<dyn MessageHandler>> {
self.handlers.get(msg)
}

pub fn messages_types(&self) -> Vec<String> {
self.handlers.keys().cloned().collect()
}
}

pub trait MessagePlugin: Send + Sync {
/// Define a unique identifier
fn name(&self) -> &'static str;

/// Return a mapping of message types to handlers
fn didcomm_routes(&self) -> MessageRouter;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ edition = "2021"

[dependencies]
shared.workspace = true
keystore.workspace = true
message-api.workspace = true

axum.workspace = true
didcomm.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
uuid.workspace = true
thiserror.workspace = true
serde_json.workspace = true
async-trait.workspace = true
serde = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["full", "rt"] }
uuid.workspace = true
keystore.workspace = true

[dev-dependencies]
shared = { workspace = true, features = ["test-utils"] }
keystore = { workspace = true, features = ["test-utils"] }
did-utils.workspace = true
did-utils.workspace = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) const DISCOVER_FEATURE: &str = "https://didcomm.org/discover-features/2.0/disclose";
pub(crate) const QUERY_FEATURE: &str = "https://didcomm.org/discover-features/2.0/queries";
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axum::{http::StatusCode, response::IntoResponse, Json};
use thiserror::Error;

#[derive(Debug, Error)]
pub enum DiscoveryError {
pub(crate) enum DiscoveryError {
#[error("message body is malformed")]
MalformedBody,
#[error("No queries field in body")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::{
constants::DISCOVER_FEATURE,
errors::DiscoveryError,
model::{Disclosures, DisclosuresContent},
};
use didcomm::Message;
use serde_json::json;
use shared::{constants::DISCOVER_FEATURE, state::AppState};
use shared::state::AppState;
use std::{collections::HashSet, sync::Arc};
use uuid::Uuid;

// handle discover feature request
// https://didcomm.org/discover-features/2.0/
pub async fn handle_query_request(
pub(crate) async fn handle_query_request(
state: Arc<AppState>,
message: Message,
) -> Result<Option<Message>, DiscoveryError> {
Expand Down Expand Up @@ -117,21 +118,18 @@ fn build_response(disclosed_protocols: HashSet<String>) -> Message {
#[cfg(test)]
mod test {

use std::{sync::Arc, vec};

use crate::{constants::QUERY_FEATURE, model::Queries};
use did_utils::didcore::Document;
use didcomm::Message;
use keystore::tests::MockKeyStore;
use serde_json::json;
use shared::{
constants::QUERY_FEATURE,
repository::tests::{MockConnectionRepository, MockMessagesRepository},
state::{AppState, AppStateRepository},
};
use std::{sync::Arc, vec};
use uuid::Uuid;

use crate::model::Queries;

use super::handle_query_request;
const MEDIATION: &str = "https://didcomm.org/coordinate-mediation/2.0";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod constants;
mod errors;
mod handler;
mod model;

pub mod handler;
pub mod plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::constants::QUERY_FEATURE;
use async_trait::async_trait;
use axum::response::{IntoResponse, Response};
use didcomm::Message;
use message_api::{MessageHandler, MessagePlugin, MessageRouter};
use shared::state::AppState;
use std::sync::Arc;

pub struct DiscoverFeaturesProtocol;

struct DiscoverFeaturesHandler;

#[async_trait]
impl MessageHandler for DiscoverFeaturesHandler {
async fn handle(
&self,
state: Arc<AppState>,
msg: Message,
) -> Result<Option<Message>, Response> {
crate::handler::handle_query_request(state, msg)
.await
.map_err(|e| e.into_response())
}
}

impl MessagePlugin for DiscoverFeaturesProtocol {
fn name(&self) -> &'static str {
"discover-features"
}

fn didcomm_routes(&self) -> MessageRouter {
MessageRouter::new().register(QUERY_FEATURE, DiscoverFeaturesHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ edition = "2021"
keystore.workspace = true
shared.workspace = true
database.workspace = true
filesystem.workspace = true
message-api.workspace = true

mongodb.workspace = true
async-trait.workspace = true
serde_json.workspace = true
thiserror.workspace = true
didcomm = { workspace = true, features = ["uniffi"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) const MEDIATE_FORWARD_2_0: &str = "https://didcomm.org/routing/2.0/forward";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use hyper::StatusCode;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum ForwardError {
pub(crate) enum ForwardError {
#[error("message body is malformed")]
MalformedBody,
#[error("Uncoordinated sender")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::ForwardError;
use crate::error::ForwardError;
use database::Repository;
use didcomm::{AttachmentData, Message};
use mongodb::bson::doc;
Expand All @@ -11,7 +11,7 @@ use std::sync::Arc;

/// Mediator receives forwarded messages, extract the next field in the message body, and the attachments in the message
/// then stores the attachment with the next field as key for pickup
pub async fn mediator_forward_process(
pub(crate) async fn mediator_forward_process(
state: Arc<AppState>,
message: Message,
) -> Result<Option<Message>, ForwardError> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod constants;
mod error;
pub mod handler;
mod handler;

// Re-exports
pub use error::ForwardError;
pub mod plugin;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::constants::MEDIATE_FORWARD_2_0;
use async_trait::async_trait;
use axum::response::{IntoResponse, Response};
use didcomm::Message;
use message_api::{MessageHandler, MessagePlugin, MessageRouter};
use shared::state::AppState;
use std::sync::Arc;

pub struct RoutingProtocol;

struct ForwardHandler;

#[async_trait]
impl MessageHandler for ForwardHandler {
async fn handle(
&self,
state: Arc<AppState>,
msg: Message,
) -> Result<Option<Message>, Response> {
crate::handler::mediator_forward_process(state, msg)
.await
.map_err(|e| e.into_response())
}
}

impl MessagePlugin for RoutingProtocol {
fn name(&self) -> &'static str {
"routing"
}

fn didcomm_routes(&self) -> MessageRouter {
MessageRouter::new().register(MEDIATE_FORWARD_2_0, ForwardHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ shared.workspace = true
did-utils.workspace = true
database.workspace = true
keystore.workspace = true
filesystem.workspace = true
message-api.workspace = true

mongodb.workspace = true
multibase.workspace = true
serde.workspace = true
async-trait.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tracing.workspace = true
Expand Down
Loading
Loading