From 6c1b102f3476df71d69ee6d8c5fb528f095a9e5a Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 08:45:25 -0800 Subject: [PATCH 1/7] fix Signed-off-by: Shaanjot Gill --- .../connections/models/conn_record.py | 17 ++++++++++ .../models/tests/test_conn_record.py | 34 +++++++++++++++++++ .../protocols/out_of_band/v1_0/manager.py | 4 +++ 3 files changed, 55 insertions(+) diff --git a/aries_cloudagent/connections/models/conn_record.py b/aries_cloudagent/connections/models/conn_record.py index c456b2d050..edbee7da6d 100644 --- a/aries_cloudagent/connections/models/conn_record.py +++ b/aries_cloudagent/connections/models/conn_record.py @@ -9,6 +9,7 @@ from ...core.profile import ProfileSession from ...messaging.models.base_record import BaseRecord, BaseRecordSchema +from ...messaging.util import datetime_now, str_to_datetime from ...messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY, UUIDFour from ...protocols.connections.v1_0.message_types import ( @@ -348,6 +349,22 @@ async def retrieve_by_alias( post_filter = {"alias": alias} return await cls.query(session, post_filter_positive=post_filter) + @classmethod + async def flush_stale_connections(cls, session: ProfileSession): + """Retrieve and delete stale connection records.""" + + # To delete stale ConnRecords added when generating + # OOB invitations, for example, if other agent uses + # existing connection then subsequent invitations and + # associated ConnRecords will remain unused. + post_filter = {"state": "invitation", "invitation_mode": "once"} + records = await cls.query(session, post_filter_positive=post_filter) + for record in records: + updated_time = str_to_datetime(record.updated_at) + current_time = datetime_now() + if ((current_time - updated_time).total_seconds() / 3600) >= 3: + await record.delete_record(session) + async def attach_invitation( self, session: ProfileSession, diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index 2923065cfa..de0dc0d902 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -1,6 +1,9 @@ from asynctest import TestCase as AsyncTestCase +from asynctest import mock as async_mock +from datetime import timedelta from ....core.in_memory import InMemoryProfile +from ....messaging.util import datetime_now, datetime_to_str, str_to_datetime from ....protocols.connections.v1_0.messages.connection_invitation import ( ConnectionInvitation, ) @@ -420,3 +423,34 @@ async def test_delete_conn_record_deletes_metadata(self): ) == [] ) + + async def test_flush_stale_connections(self): + current_datetime = datetime_now() + older_datetime = current_datetime - timedelta(hours=4) + record_a = ConnRecord( + my_did=self.test_did, + their_did=self.test_target_did, + their_role=ConnRecord.Role.RESPONDER.rfc160, + state=ConnRecord.State.INVITATION.rfc23, + invitation_key="dummy1", + invitation_mode="once", + updated_at=datetime_to_str(current_datetime), + ) + record_b = ConnRecord( + my_did=self.test_did, + their_did="FBmi5JLf5g58kDnNXMy4QM", + their_role=ConnRecord.Role.RESPONDER.rfc160, + state=ConnRecord.State.INVITATION.rfc160, + invitation_key="dummy2", + invitation_mode="once", + updated_at=datetime_to_str(older_datetime), + ) + records = [record_a, record_b] + with async_mock.patch.object( + ConnRecord, "query", async_mock.CoroutineMock() + ) as mock_connrecord_query, async_mock.patch.object( + ConnRecord, "delete_record", async_mock.CoroutineMock() + ) as mock_connrecord_delete: + mock_connrecord_query.return_value = records + await ConnRecord.flush_stale_connections(self.session) + mock_connrecord_delete.assert_called_once() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index 71b10883e5..cee2ce0f3b 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -369,6 +369,10 @@ async def create_invitation( for key, value in metadata.items(): await conn_rec.metadata_set(session, key, value) + # Flushing stale connections + async with self.profile.session() as session: + await ConnRecord.flush_stale_connections(session) + return InvitationRecord( # for return via admin API, not storage state=InvitationRecord.STATE_INITIAL, invi_msg_id=invi_msg._id, From c26865bf7697a9a6a11e68c770afb5729f1303cf Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 09:02:28 -0800 Subject: [PATCH 2/7] cleanup Signed-off-by: Shaanjot Gill --- aries_cloudagent/connections/models/conn_record.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/connections/models/conn_record.py b/aries_cloudagent/connections/models/conn_record.py index edbee7da6d..e4658c5be4 100644 --- a/aries_cloudagent/connections/models/conn_record.py +++ b/aries_cloudagent/connections/models/conn_record.py @@ -359,10 +359,13 @@ async def flush_stale_connections(cls, session: ProfileSession): # associated ConnRecords will remain unused. post_filter = {"state": "invitation", "invitation_mode": "once"} records = await cls.query(session, post_filter_positive=post_filter) + current_time = datetime_now() + stale_record_time_filter = 3 for record in records: updated_time = str_to_datetime(record.updated_at) - current_time = datetime_now() - if ((current_time - updated_time).total_seconds() / 3600) >= 3: + if ( + (current_time - updated_time).total_seconds() / 3600 + ) >= stale_record_time_filter: await record.delete_record(session) async def attach_invitation( From e420f264771c414cc105ba3fefe313d8fafd0f6d Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 12:57:21 -0800 Subject: [PATCH 3/7] fixed reuse impl Signed-off-by: Shaanjot Gill --- .../connections/models/conn_record.py | 20 ---- .../models/tests/test_conn_record.py | 31 ------ .../v1_0/handlers/reuse_handler.py | 4 +- .../v1_0/handlers/tests/test_reuse_handler.py | 8 +- .../protocols/out_of_band/v1_0/manager.py | 95 ++++++------------- .../out_of_band/v1_0/tests/test_manager.py | 75 +++++++-------- 6 files changed, 73 insertions(+), 160 deletions(-) diff --git a/aries_cloudagent/connections/models/conn_record.py b/aries_cloudagent/connections/models/conn_record.py index e4658c5be4..c456b2d050 100644 --- a/aries_cloudagent/connections/models/conn_record.py +++ b/aries_cloudagent/connections/models/conn_record.py @@ -9,7 +9,6 @@ from ...core.profile import ProfileSession from ...messaging.models.base_record import BaseRecord, BaseRecordSchema -from ...messaging.util import datetime_now, str_to_datetime from ...messaging.valid import INDY_DID, INDY_RAW_PUBLIC_KEY, UUIDFour from ...protocols.connections.v1_0.message_types import ( @@ -349,25 +348,6 @@ async def retrieve_by_alias( post_filter = {"alias": alias} return await cls.query(session, post_filter_positive=post_filter) - @classmethod - async def flush_stale_connections(cls, session: ProfileSession): - """Retrieve and delete stale connection records.""" - - # To delete stale ConnRecords added when generating - # OOB invitations, for example, if other agent uses - # existing connection then subsequent invitations and - # associated ConnRecords will remain unused. - post_filter = {"state": "invitation", "invitation_mode": "once"} - records = await cls.query(session, post_filter_positive=post_filter) - current_time = datetime_now() - stale_record_time_filter = 3 - for record in records: - updated_time = str_to_datetime(record.updated_at) - if ( - (current_time - updated_time).total_seconds() / 3600 - ) >= stale_record_time_filter: - await record.delete_record(session) - async def attach_invitation( self, session: ProfileSession, diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index de0dc0d902..d146c19222 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -423,34 +423,3 @@ async def test_delete_conn_record_deletes_metadata(self): ) == [] ) - - async def test_flush_stale_connections(self): - current_datetime = datetime_now() - older_datetime = current_datetime - timedelta(hours=4) - record_a = ConnRecord( - my_did=self.test_did, - their_did=self.test_target_did, - their_role=ConnRecord.Role.RESPONDER.rfc160, - state=ConnRecord.State.INVITATION.rfc23, - invitation_key="dummy1", - invitation_mode="once", - updated_at=datetime_to_str(current_datetime), - ) - record_b = ConnRecord( - my_did=self.test_did, - their_did="FBmi5JLf5g58kDnNXMy4QM", - their_role=ConnRecord.Role.RESPONDER.rfc160, - state=ConnRecord.State.INVITATION.rfc160, - invitation_key="dummy2", - invitation_mode="once", - updated_at=datetime_to_str(older_datetime), - ) - records = [record_a, record_b] - with async_mock.patch.object( - ConnRecord, "query", async_mock.CoroutineMock() - ) as mock_connrecord_query, async_mock.patch.object( - ConnRecord, "delete_record", async_mock.CoroutineMock() - ) as mock_connrecord_delete: - mock_connrecord_query.return_value = records - await ConnRecord.flush_stale_connections(self.session) - mock_connrecord_delete.assert_called_once() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/reuse_handler.py index b12ec3a767..0a34e5c85c 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/reuse_handler.py @@ -27,6 +27,8 @@ async def handle(self, context: RequestContext, responder: BaseResponder): profile = context.profile mgr = OutOfBandManager(profile) try: - await mgr.receive_reuse_message(context.message, context.message_receipt) + await mgr.receive_reuse_message( + context.message, context.message_receipt, context.connection_record + ) except OutOfBandManagerError as e: self._logger.exception(f"Error processing Handshake Reuse message, {e}") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py index 946994a18b..ea54f754b3 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py @@ -38,10 +38,13 @@ async def test_called(self, mock_oob_mgr, request_context): mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() + request_context.connection_record = ConnRecord() responder = MockResponder() await handler.handle(request_context, responder) mock_oob_mgr.return_value.receive_reuse_message.assert_called_once_with( - request_context.message, request_context.message_receipt + request_context.message, + request_context.message_receipt, + request_context.connection_record, ) @pytest.mark.asyncio @@ -52,11 +55,13 @@ async def test_reuse_accepted(self, mock_oob_mgr, request_context): mock_oob_mgr.return_value.receive_reuse_message.return_value = reuse_accepted request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() + request_context.connection_record = ConnRecord() responder = MockResponder() await handler.handle(request_context, responder) mock_oob_mgr.return_value.receive_reuse_message.assert_called_once_with( request_context.message, request_context.message_receipt, + request_context.connection_record, ) @pytest.mark.asyncio @@ -68,6 +73,7 @@ async def test_exception(self, mock_oob_mgr, request_context): ) request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() + request_context.connection_record = ConnRecord() responder = MockResponder() await handler.handle(request_context, responder) assert mock_oob_mgr.return_value._logger.exception.called_once_("error") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index cee2ce0f3b..19190ba6dc 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -369,10 +369,6 @@ async def create_invitation( for key, value in metadata.items(): await conn_rec.metadata_set(session, key, value) - # Flushing stale connections - async with self.profile.session() as session: - await ConnRecord.flush_stale_connections(session) - return InvitationRecord( # for return via admin API, not storage state=InvitationRecord.STATE_INITIAL, invi_msg_id=invi_msg._id, @@ -989,9 +985,7 @@ async def create_handshake_reuse_message( """ try: - # ID of Out-of-Band invitation to use as a pthid - # pthid = invi_msg._id - pthid = conn_record.invitation_msg_id + pthid = invi_msg._id reuse_msg = HandshakeReuse() thid = reuse_msg._id reuse_msg.assign_thread_id(thid=thid, pthid=pthid) @@ -1016,10 +1010,25 @@ async def create_handshake_reuse_message( f"Error on creating and sending a handshake reuse message: {err}" ) + async def delete_stale_connection_by_invitation(self, invi_msg_id: str): + """Delete unused connections, using existing an active connection instead.""" + post_filter = {} + post_filter["invitation_msg_id"] = invi_msg_id + post_filter["invitation_mode"] = "once" + post_filter["state"] = "invitation" + async with self.profile.session() as session: + conn_records = await ConnRecord.query( + session, + post_filter_positive=post_filter, + ) + for conn_rec in conn_records: + await conn_rec.delete_record(session) + async def receive_reuse_message( self, reuse_msg: HandshakeReuse, receipt: MessageReceipt, + conn_rec: ConnRecord, ) -> None: """ Receive and process a HandshakeReuse message under RFC 0434. @@ -1038,67 +1047,19 @@ async def receive_reuse_message( or the connection does not exists """ - try: - invi_msg_id = reuse_msg._thread.pthid - reuse_msg_id = reuse_msg._thread.thid - tag_filter = {} - post_filter = {} - # post_filter["state"] = "active" - # tag_filter["their_did"] = receipt.sender_did - post_filter["invitation_msg_id"] = invi_msg_id - conn_record = await self.find_existing_connection( - tag_filter=tag_filter, post_filter=post_filter - ) - responder = self.profile.inject_or(BaseResponder) - if conn_record is not None: - # For ConnRecords created using did-exchange - reuse_accept_msg = HandshakeReuseAccept() - reuse_accept_msg.assign_thread_id(thid=reuse_msg_id, pthid=invi_msg_id) - connection_targets = await self.fetch_connection_targets( - connection=conn_record - ) - if responder: - await responder.send( - message=reuse_accept_msg, - target_list=connection_targets, - ) - # This is not required as now we attaching the invitation_msg_id - # using original invitation [from existing connection] - # - # Delete the ConnRecord created; re-use existing connection - # invi_id_post_filter = {} - # invi_id_post_filter["invitation_msg_id"] = invi_msg_id - # conn_rec_to_delete = await self.find_existing_connection( - # tag_filter={}, - # post_filter=invi_id_post_filter, - # ) - # if conn_rec_to_delete is not None: - # if conn_record.connection_id != conn_rec_to_delete.connection_id: - # await conn_rec_to_delete.delete_record(session=self._session) - else: - conn_record = await self.find_existing_connection( - tag_filter={"their_did": receipt.sender_did}, post_filter={} - ) - # Problem Report is redundant in this case as with no active - # connection, it cannot reach the invitee any way - if conn_record is not None: - # For ConnRecords created using RFC 0160 connections - reuse_accept_msg = HandshakeReuseAccept() - reuse_accept_msg.assign_thread_id( - thid=reuse_msg_id, pthid=invi_msg_id - ) - connection_targets = await self.fetch_connection_targets( - connection=conn_record - ) - if responder: - await responder.send( - message=reuse_accept_msg, - target_list=connection_targets, - ) - except StorageNotFoundError: - raise OutOfBandManagerError( - (f"No existing ConnRecord found for OOB Invitee, {receipt.sender_did}"), + invi_msg_id = reuse_msg._thread.pthid + reuse_msg_id = reuse_msg._thread.thid + responder = self.profile.inject_or(BaseResponder) + reuse_accept_msg = HandshakeReuseAccept() + reuse_accept_msg.assign_thread_id(thid=reuse_msg_id, pthid=invi_msg_id) + connection_targets = await self.fetch_connection_targets(connection=conn_rec) + if responder: + await responder.send( + message=reuse_accept_msg, + target_list=connection_targets, ) + # Delete the ConnRecord created; re-use existing connection + await self.delete_stale_connection_by_invitation(invi_msg_id) async def receive_reuse_accepted_message( self, diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 4330b4a63b..b3582730db 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -5,7 +5,7 @@ from asynctest import mock as async_mock, TestCase as AsyncTestCase from copy import deepcopy -from datetime import datetime, timezone +from datetime import datetime, timezone, timedelta from uuid import UUID from .....connections.models.conn_record import ConnRecord @@ -22,7 +22,7 @@ ) from .....messaging.decorators.attach_decorator import AttachDecorator from .....messaging.responder import BaseResponder, MockResponder -from .....messaging.util import str_to_epoch +from .....messaging.util import str_to_epoch, datetime_now, datetime_to_str from .....multitenant.base import BaseMultitenantManager from .....multitenant.manager import MultitenantManager from .....protocols.coordinate_mediation.v1_0.models.mediation_record import ( @@ -1567,7 +1567,9 @@ async def test_receive_reuse_message_existing_found(self): retrieve_invi_rec.return_value = InvitationRecord( invi_msg_id="test_123" ) - await self.manager.receive_reuse_message(reuse_msg, receipt) + await self.manager.receive_reuse_message( + reuse_msg, receipt, self.test_conn_rec + ) assert ( len( await ConnRecord.query( @@ -1622,44 +1624,11 @@ async def test_receive_reuse_message_existing_not_found(self): retrieve_invi_rec.return_value = InvitationRecord( invi_msg_id="test_123" ) - await self.manager.receive_reuse_message(reuse_msg, receipt) + await self.manager.receive_reuse_message( + reuse_msg, receipt, self.test_conn_rec + ) assert len(self.responder.messages) == 0 - async def test_receive_reuse_message_storage_not_found(self): - self.profile.context.update_settings({"public_invites": True}) - receipt = MessageReceipt( - recipient_did=TestConfig.test_did, - recipient_did_public=False, - sender_did="test_did", - ) - reuse_msg = HandshakeReuse() - reuse_msg.assign_thread_id(thid="test_123", pthid="test_123") - - with async_mock.patch.object( - DIDXManager, "receive_invitation", autospec=True - ) as didx_mgr_receive_invitation, async_mock.patch( - "aries_cloudagent.protocols.out_of_band.v1_0.manager.InvitationMessage", - autospec=True, - ) as inv_message_cls, async_mock.patch.object( - OutOfBandManager, - "fetch_connection_targets", - autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( - InvitationRecord, - "retrieve_by_tag_filter", - autospec=True, - ) as retrieve_invi_rec, async_mock.patch.object( - OutOfBandManager, - "find_existing_connection", - autospec=True, - ) as oob_mgr_find_existing_conn: - oob_mgr_find_existing_conn.side_effect = StorageNotFoundError() - with self.assertRaises(OutOfBandManagerError) as context: - await self.manager.receive_reuse_message(reuse_msg, receipt) - assert "No existing ConnRecord found for OOB Invitee" in str( - context.exception - ) - async def test_receive_reuse_message_problem_report_logic(self): async with self.profile.session() as session: self.profile.context.update_settings({"public_invites": True}) @@ -1685,7 +1654,9 @@ async def test_receive_reuse_message_problem_report_logic(self): recipient_keys=TestConfig.test_verkey, sender_key=TestConfig.test_verkey, ) - await self.manager.receive_reuse_message(reuse_msg, receipt) + await self.manager.receive_reuse_message( + reuse_msg, receipt, self.test_conn_rec + ) async def test_receive_reuse_accepted(self): async with self.profile.session() as session: @@ -3580,3 +3551,27 @@ async def test_request_attach_cred_offer_v2_check_conn_rec_active_timeout(self): ) mock_logger_warning.assert_called_once() assert conn_rec is not None + + async def test_delete_stale_connection_by_invitation(self): + current_datetime = datetime_now() + older_datetime = current_datetime - timedelta(hours=4) + records = [ + ConnRecord( + my_did=self.test_did, + their_did="FBmi5JLf5g58kDnNXMy4QM", + their_role=ConnRecord.Role.RESPONDER.rfc160, + state=ConnRecord.State.INVITATION.rfc160, + invitation_key="dummy2", + invitation_mode="once", + invitation_msg_id="test123", + updated_at=datetime_to_str(older_datetime), + ) + ] + with async_mock.patch.object( + ConnRecord, "query", async_mock.CoroutineMock() + ) as mock_connrecord_query, async_mock.patch.object( + ConnRecord, "delete_record", async_mock.CoroutineMock() + ) as mock_connrecord_delete: + mock_connrecord_query.return_value = records + await self.manager.delete_stale_connection_by_invitation("test123") + mock_connrecord_delete.assert_called_once() From 30a66018469ba611f831f1da1207c6ec679f12a8 Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 13:15:59 -0800 Subject: [PATCH 4/7] cleanup Signed-off-by: Shaanjot Gill --- aries_cloudagent/connections/models/tests/test_conn_record.py | 1 - 1 file changed, 1 deletion(-) diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index d146c19222..5f357140e1 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -3,7 +3,6 @@ from datetime import timedelta from ....core.in_memory import InMemoryProfile -from ....messaging.util import datetime_now, datetime_to_str, str_to_datetime from ....protocols.connections.v1_0.messages.connection_invitation import ( ConnectionInvitation, ) From efb860fffb7fe999f85a85c0f5c220ce57eae1c3 Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 13:17:23 -0800 Subject: [PATCH 5/7] cleanup Signed-off-by: Shaanjot Gill --- aries_cloudagent/connections/models/tests/test_conn_record.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index 5f357140e1..2923065cfa 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -1,6 +1,4 @@ from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock -from datetime import timedelta from ....core.in_memory import InMemoryProfile from ....protocols.connections.v1_0.messages.connection_invitation import ( From 16b8c988d3cec3e43fcbd9618b2c262e72cccacb Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 14:44:00 -0800 Subject: [PATCH 6/7] update invitation_msg_id Signed-off-by: Shaanjot Gill --- aries_cloudagent/protocols/out_of_band/v1_0/manager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index 19190ba6dc..7cf6dafbae 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -1058,6 +1058,10 @@ async def receive_reuse_message( message=reuse_accept_msg, target_list=connection_targets, ) + # Update ConnRecord's invi_msg_id + async with self._profile.session() as session: + conn_rec.invitation_msg_id = invi_msg_id + await conn_rec.save(session, reason="Assigning new invitation_msg_id") # Delete the ConnRecord created; re-use existing connection await self.delete_stale_connection_by_invitation(invi_msg_id) @@ -1095,6 +1099,8 @@ async def receive_reuse_accepted_message( await conn_record.metadata_set( session=session, key="reuse_msg_state", value="accepted" ) + conn_record.invitation_msg_id = invi_msg_id + await conn_record.save(session, reason="Assigning new invitation_msg_id") except Exception as e: raise OutOfBandManagerError( ( From fc7d0dba6a8fc9810227f23f88b295ed92316b75 Mon Sep 17 00:00:00 2001 From: Shaanjot Gill Date: Thu, 25 Nov 2021 14:46:54 -0800 Subject: [PATCH 7/7] format fix Signed-off-by: Shaanjot Gill --- aries_cloudagent/protocols/out_of_band/v1_0/manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py index 7cf6dafbae..4a0124238b 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/manager.py @@ -1100,7 +1100,9 @@ async def receive_reuse_accepted_message( session=session, key="reuse_msg_state", value="accepted" ) conn_record.invitation_msg_id = invi_msg_id - await conn_record.save(session, reason="Assigning new invitation_msg_id") + await conn_record.save( + session, reason="Assigning new invitation_msg_id" + ) except Exception as e: raise OutOfBandManagerError( (