From 530a1a865876d1f2ea446053fc62259d9308d7a8 Mon Sep 17 00:00:00 2001 From: Patrik Stas Date: Mon, 14 Aug 2023 23:45:58 +0200 Subject: [PATCH] Tweak inviter to extract msg sending out Signed-off-by: Patrik Stas --- .../src/services/connection.rs | 6 +++-- .../src/protocols/connection/generic/mod.rs | 5 +--- .../src/protocols/connection/inviter/mod.rs | 27 ++++++++----------- .../src/api_vcx/api_handle/connection.rs | 6 +++-- .../src/handlers/connection/connection.rs | 6 +++-- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/agents/rust/aries-vcx-agent/src/services/connection.rs b/agents/rust/aries-vcx-agent/src/services/connection.rs index 52244dc830..6d93568b4a 100644 --- a/agents/rust/aries-vcx-agent/src/services/connection.rs +++ b/agents/rust/aries-vcx-agent/src/services/connection.rs @@ -102,9 +102,11 @@ impl ServiceConnections { pub async fn send_response(&self, thread_id: &str) -> AgentResult<()> { let inviter: Connection<_, _> = self.connections.get(thread_id)?.try_into()?; - let inviter = inviter - .send_response(&self.profile.inject_wallet(), &HttpClient) + let response = inviter.get_connection_response_msg(); + inviter + .send_message(&self.profile.inject_wallet(), &response.into(), &HttpClient) .await?; + let inviter = inviter.mark_response_sent()?; self.connections.insert(thread_id, inviter.into())?; diff --git a/aries_vcx/src/protocols/connection/generic/mod.rs b/aries_vcx/src/protocols/connection/generic/mod.rs index 4312d263de..afbc4a4fa2 100644 --- a/aries_vcx/src/protocols/connection/generic/mod.rs +++ b/aries_vcx/src/protocols/connection/generic/mod.rs @@ -483,12 +483,9 @@ mod connection_serde_tests { } async fn make_inviter_responded() -> InviterConnection { - let wallet: Arc = Arc::new(MockWallet {}); - make_inviter_requested() .await - .send_response(&wallet, &MockTransport) - .await + .mark_response_sent::() .unwrap() } diff --git a/aries_vcx/src/protocols/connection/inviter/mod.rs b/aries_vcx/src/protocols/connection/inviter/mod.rs index 2255875f19..86d6bdc970 100644 --- a/aries_vcx/src/protocols/connection/inviter/mod.rs +++ b/aries_vcx/src/protocols/connection/inviter/mod.rs @@ -233,31 +233,26 @@ impl InviterConnection { } impl InviterConnection { - /// Sends a [`Response`] to the invitee and transitions to [`InviterConnection`]. + /// Returns pre-built [`Response`] message which shall be delivered to counterparty /// /// # Errors /// /// Will return an error if sending the response fails. - pub async fn send_response( - self, - wallet: &Arc, - transport: &T, - ) -> VcxResult> + pub fn get_connection_response_msg(self) -> Response { + self.state.signed_response + } + + /// Transitions to [`InviterConnection`] under assumption the caller has assured delivery of [`Response`] message + /// + /// # Errors + /// + /// Will return an error if sending the response fails. + pub fn mark_response_sent(self) -> VcxResult> where T: Transport, { - trace!( - "Connection::send_response >>> signed_response: {:?}", - &self.state.signed_response - ); - let thread_id = self.state.signed_response.decorators.thread.thid.clone(); - - self.send_message(wallet, &self.state.signed_response.clone().into(), transport) - .await?; - let state = Responded::new(self.state.did_doc, thread_id); - Ok(Connection { state, source_id: self.source_id, diff --git a/libvcx_core/src/api_vcx/api_handle/connection.rs b/libvcx_core/src/api_vcx/api_handle/connection.rs index b2d1436e84..0d73e48008 100644 --- a/libvcx_core/src/api_vcx/api_handle/connection.rs +++ b/libvcx_core/src/api_vcx/api_handle/connection.rs @@ -330,8 +330,10 @@ pub async fn send_response(handle: u32) -> LibvcxResult<()> { trace!("send_response >>>"); let con = get_cloned_connection(&handle)?; - let con = con.send_response(&get_main_wallet()?, &HttpClient).await?; - + let response = con.get_connection_response_msg(); + con.send_message(&get_main_wallet()?, &response.into(), &HttpClient) + .await?; + let con = con.mark_response_sent()?; insert_connection(handle, con) } diff --git a/uniffi_aries_vcx/core/src/handlers/connection/connection.rs b/uniffi_aries_vcx/core/src/handlers/connection/connection.rs index 463fa7ea2c..5bc8c2f9eb 100644 --- a/uniffi_aries_vcx/core/src/handlers/connection/connection.rs +++ b/uniffi_aries_vcx/core/src/handlers/connection/connection.rs @@ -149,9 +149,11 @@ impl Connection { let connection = VcxConnection::try_from(handler.clone())?; block_on(async { - let new_conn = connection - .send_response(&profile.inner.inject_wallet(), &HttpClient) + let response = connection.get_connection_response_msg(); + connection + .send_message(&self.profile.inject_wallet(), &response.into(), &HttpClient) .await?; + let new_conn = connection.mark_response_sent()?; *handler = VcxGenericConnection::from(new_conn);