-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
Codecov Report
@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
todo: tests Done. |
5ed2f8c
to
55c259e
Compare
b3a07df
to
cd73500
Compare
2470758
to
4b50d89
Compare
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. |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>) { |
There was a problem hiding this comment.
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())?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
4b50d89
to
b26a101
Compare
Signed-off-by: Naian <[email protected]>
Signed-off-by: Naian <[email protected]>
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]>
Signed-off-by: Naian <[email protected]>
There was a problem hiding this 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
No description provided.