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

allow forwarded messages to use existing connections and the outbound queue #631

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
HandlerException,
RequestContext,
)

from .....protocols.connections.v1_0.manager import ConnectionManager
from ..manager import RoutingManager, RoutingManagerError
from ..messages.forward import Forward

Expand Down Expand Up @@ -38,8 +38,21 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
self._logger.exception("Error resolving recipient for forwarded message")
return

# load connection
connection_mgr = ConnectionManager(context)
connection_targets = await connection_mgr.get_connection_targets(
connection_id=recipient.connection_id
)
# TODO: validate that there is 1 target, with 1 verkey. warn otherwise
connection_verkey = connection_targets[0].recipient_keys[0]

# Note: not currently vetting the state of the connection here
self._logger.info(
f"Forwarding message to connection: {recipient.connection_id}"
)
await responder.send(packed, connection_id=recipient.connection_id)
await responder.send(
packed,
connection_id=recipient.connection_id,
Copy link
Member

Choose a reason for hiding this comment

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

Looking at the responder code, I think you can pass connection_targets as target_list, instead of passing connection_id, and it would avoid the need to look up the connection information twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I needed to pass connection_id as well, but it accepted both. Updated.

target_list=connection_targets,
reply_to_verkey=connection_verkey,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from aries_cloudagent.storage.base import BaseStorage
from aries_cloudagent.storage.basic import BasicStorage
from aries_cloudagent.transport.inbound.receipt import MessageReceipt
from aries_cloudagent.connections.models.connection_target import ConnectionTarget

from ...models.route_record import RouteRecord
from ...messages.forward import Forward
Expand Down Expand Up @@ -39,10 +40,15 @@ async def test_handle(self):
responder = MockResponder()
with async_mock.patch.object(
test_module, "RoutingManager", autospec=True
) as mock_mgr:
) as mock_mgr, async_mock.patch.object(
test_module, "ConnectionManager", autospec=True
) as mock_connection_mgr:
mock_mgr.return_value.get_recipient = async_mock.CoroutineMock(
return_value=RouteRecord(connection_id="dummy")
)
mock_connection_mgr.return_value.get_connection_targets = async_mock.CoroutineMock(
return_value=[ConnectionTarget(recipient_keys=["recip_key"],)]
)

await handler.handle(self.context, responder)

Expand Down