-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from adorsys/203-add-a-messaging-plugin-conta…
…iner-with-the-various-messaging-plugins-add-the-plugin-architecture-to-the-didcomm-messaging-route adding messaging plugin container with the various messaging plugins
- Loading branch information
Showing
52 changed files
with
831 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
crates/web-plugins/didcomm-messaging/message-api/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
53
crates/web-plugins/didcomm-messaging/message-api/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
crates/web-plugins/didcomm-messaging/protocols/discover-features/src/constants.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
crates/web-plugins/didcomm-messaging/protocols/discover-features/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
34 changes: 34 additions & 0 deletions
34
crates/web-plugins/didcomm-messaging/protocols/discover-features/src/plugin.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
crates/web-plugins/didcomm-messaging/protocols/forward/src/constants.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
crates/web-plugins/didcomm-messaging/protocols/forward/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
34 changes: 34 additions & 0 deletions
34
crates/web-plugins/didcomm-messaging/protocols/forward/src/plugin.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.