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

feat(mediator): support for pickup protocol processing #1029

Merged
merged 5 commits into from
Nov 2, 2023

Conversation

nain-F49FF806
Copy link
Member

No description provided.

@nain-F49FF806 nain-F49FF806 changed the title feat(mediator): support for pickup protocol feat(mediator): support for pickup protocol processing Oct 26, 2023
@nain-F49FF806 nain-F49FF806 changed the title feat(mediator): support for pickup protocol processing WIP: feat(mediator): support for pickup protocol processing Oct 26, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 26, 2023

Codecov Report

Merging #1029 (2470758) into main (63590d1) will not change coverage.
The diff coverage is n/a.

❗ Current head 2470758 differs from pull request most recent head 4b50d89. Consider uploading reports for the commit 4b50d89 to get more accurate results

@@          Coverage Diff          @@
##            main   #1029   +/-   ##
=====================================
  Coverage   0.05%   0.05%           
=====================================
  Files        384     384           
  Lines      21249   21249           
  Branches    3835    3835           
=====================================
  Hits          12      12           
  Misses     21236   21236           
  Partials       1       1           
Flag Coverage Δ
unittests-aries-vcx 0.05% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
messages/src/msg_fields/protocols/pickup/mod.rs 0.00% <ø> (ø)

@nain-F49FF806
Copy link
Member Author

nain-F49FF806 commented Oct 26, 2023

todo: tests

Done.

@nain-F49FF806 nain-F49FF806 force-pushed the nain/mediator/feat/pickup branch from 5ed2f8c to 55c259e Compare October 27, 2023 11:16
@nain-F49FF806
Copy link
Member Author

nain-F49FF806 commented Oct 27, 2023

Note: This PR depends on #1028, hence the WIP tag.
Clearer diff can be found at #1031

@nain-F49FF806 nain-F49FF806 force-pushed the nain/mediator/feat/pickup branch 2 times, most recently from b3a07df to cd73500 Compare October 30, 2023 12:48
@nain-F49FF806 nain-F49FF806 changed the title WIP: feat(mediator): support for pickup protocol processing feat(mediator): support for pickup protocol processing Oct 30, 2023
@nain-F49FF806 nain-F49FF806 force-pushed the nain/mediator/feat/pickup branch 2 times, most recently from 2470758 to 4b50d89 Compare October 31, 2023 13:33
agents/rust/mediator/mediation/src/didcomm_types.rs Outdated Show resolved Hide resolved
agents/rust/mediator/mediation/src/didcomm_types.rs Outdated Show resolved Hide resolved
StatusCode::OK,
handle_pickup_status_req(status_request, storage).await,
handle_pickup_status_req(&status_request.content, storage, auth_pubkey).await,
),
// Why is client sending us status? That's server's job.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than writing a comment, I think we could improve the code to be bit more self documenting - we could return a message string to the return type, which could in this case be something like "Unexpected message of type <the message type>"

StatusCode::BAD_REQUEST,
handle_pickup_type_not_implemented().await,
handle_pickup_default_status(storage, auth_pubkey).await,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With respect to your comment above, what is this handling we call here? We should probably really just return BAD_REQUEST http response, but I don't see what any handle_* function is actually called upon receiving invalid request.

On slightly other note, from mediator client perspective, even more graceful response than getting 400 HTTP error, would be to actually return 200 with properly encrypted ProblemReport reporting that a message they submitted was unexpected.

Copy link
Member Author

@nain-F49FF806 nain-F49FF806 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I am responding with a simple Pickup Status message on receipt of any non-request type pickup message that the client sends.

Here for example, if client sends mediator a status message (they should be sending status-request), then we respond with the correct status message, assuming that is what the client actually, wants.

Agreed, problem report feels more elegant. For the time being, I was having the handler functions map from Pickup (receipt) to Pickup (response). To keep everything within the same protocol at protocol handler level.

Ideally, these protocol handler functions should return a Result so the error case can be converted to Problem Report messages, like you mentioned elsewhere. In combination with your MediatorError suggestion, for example.

Is it okay if I do this as part of another PR, since this would be a useful change for all protocols and not just pickup?

Copy link
Contributor

@Patrik-Stas Patrik-Stas Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here for example, if client sends mediator a status message (they should be sending status-request), then we respond with the correct status message, assuming that is what the client actually, wants.

You are too kind to these buggy clients 😆

do this as part of another PR

Fair enough, let's leave this for later

) -> (StatusCode, Json<PickupMsgEnum>) {
Json(pickup_message): Json<Pickup>,
auth_pubkey: &str,
) -> (StatusCode, Json<Pickup>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could imagine that this function could return custom Result type (using custom MediatorError type).
In that model you would typically return Ok(response) or Error(<some_err_info_struct/enum>)

@@ -35,7 +34,7 @@ pub async fn handle_aries<T: BaseWallet + 'static, P: MediatorPersistence>(
log::info!("processing message {:?}", &didcomm_msg);
let unpacked = agent.unpack_didcomm(&didcomm_msg).await.unwrap();
let aries_message: GeneralAriesMessage =
serde_json::from_str(&unpacked.message).expect("Decoding unpacked message as AriesMessage");
serde_json::from_str(&unpacked.message).map_err(|e| e.to_string())?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned elsewhere, consider introducing custom MediatorError error type, along with something like MediatorResult<T> as alias to Result<T, MediatorError>. See how we do the same in many of our other crates.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding custom errors is sounds like a separate PR though :-)

@@ -47,13 +46,21 @@ pub async fn handle_aries<T: BaseWallet + 'static, P: MediatorPersistence>(
handle_routing_forward(agent.clone(), forward).await?;
return Ok(Json(json!({})));
} else {
let (account_name, our_signing_key, their_diddoc) =
// Auth known VerKey then process account related messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a "todo", consider prefixing the comment text with // todo: , it tends to have different highlighting in IDEs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is just a comment. The auth_and_get_details method does the auth.
Just had the comment to explain the latter flow.

Thanks for tip about // todo:

@nain-F49FF806 nain-F49FF806 force-pushed the nain/mediator/feat/pickup branch from 4b50d89 to b26a101 Compare November 1, 2023 12:55
Messages can be serialized after wrapping in surrounding AriesMessage enum

Signed-off-by: Naian <[email protected]>
and other .expect -> errors

Signed-off-by: Naian <[email protected]>
Copy link
Contributor

@Patrik-Stas Patrik-Stas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some stuff has been addressed, some improvements we agreed to do in separate PRs, some of my comments you acknowledged, but I am not sure if you want to address them in this PR or separately. We can merge this but please keep track of the things I've noted. You already have stuff planned out so I don't want to hold you back on a PR when your other upcoming work is already built on this one.

Let me know if we shall merge

@Patrik-Stas Patrik-Stas merged commit ad26ecf into main Nov 2, 2023
28 checks passed
@Patrik-Stas Patrik-Stas deleted the nain/mediator/feat/pickup branch November 2, 2023 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants