Skip to content

Commit

Permalink
Store did-exchange thread info before sending response
Browse files Browse the repository at this point in the history
Signed-off-by: Patrik Stas <[email protected]>
  • Loading branch information
Patrik-Stas committed Mar 12, 2024
1 parent 0f3665c commit 035563d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 14 additions & 7 deletions aries/agents/rust/aries-vcx-agent/src/services/did_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl ServiceDidExchange {
&our_peer_did,
)
.await?;
let request_id = request
let thid = request
.clone()
.decorators
.thread
Expand All @@ -99,12 +99,15 @@ impl ServiceDidExchange {
service.id(),
)
.await?;
self.did_exchange.insert(&thid, requester.clone())?;
VcxHttpClient
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&request_id, requester.clone())
Ok(thid)
}

// todo: one would expect this to be just IO utility - split this to process_request /
// send_response
pub async fn send_response(
&self,
request: Request,
Expand All @@ -113,7 +116,9 @@ impl ServiceDidExchange {
// TODO: We should fetch the out of band invite associated with the request.
// We don't want to be sending response if we don't know if there is any invitation
// associated with the request.
let request_id = request
// Todo: messages should expose fallible API to get thid (for any aries msg). It's common
// pattern
let thid = request
.clone()
.decorators
.thread
Expand Down Expand Up @@ -150,17 +155,18 @@ impl ServiceDidExchange {
service.id(),
)
.await?;
self.did_exchange.insert(&thid, responder.clone())?;
VcxHttpClient
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&request_id, responder.clone())
Ok(thid)
}

pub async fn send_complete(&self, response: Response) -> AgentResult<String> {
let thread_id = response.decorators.thread.thid.clone();
let thid = response.decorators.thread.thid.clone();
let (requester, complete) = self
.did_exchange
.get(&thread_id)?
.get(&thid)?
.handle_response(response)
.await?;
let ddo_their = requester.their_did_doc();
Expand All @@ -174,10 +180,11 @@ impl ServiceDidExchange {
service.id(),
)
.await?;
self.did_exchange.insert(&thid, requester.clone())?;
VcxHttpClient
.send_message(encryption_envelope.0, service.service_endpoint())
.await?;
self.did_exchange.insert(&thread_id, requester.clone())
Ok(thid)
}

pub fn receive_complete(&self, complete: Complete) -> AgentResult<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ where
}

fn insert(&self, id: &str, obj: T) -> AgentResult<String> {
info!("Inserting object {} into in-mem storage: {}", id, self.cache_name);
info!(
"Inserting object {} into in-mem storage: {}",
id, self.cache_name
);
let mut store = self._lock_store_write()?;

match store.insert(id.to_string(), Mutex::new(obj)) {
Expand Down

0 comments on commit 035563d

Please sign in to comment.