Source code for aries_cloudagent.messaging.routing.handlers.forward_handler

"""Handler for incoming forward messages."""

from ...base_handler import BaseHandler, BaseResponder, HandlerException, RequestContext

from ..manager import RoutingManager, RoutingManagerError
from ..messages.forward import Forward


[docs]class ForwardHandler(BaseHandler): """Handler for incoming forward messages."""
[docs] async def handle(self, context: RequestContext, responder: BaseResponder): """Message handler implementation.""" self._logger.debug("ForwardHandler called with context %s", context) assert isinstance(context.message, Forward) if not context.message_delivery.recipient_verkey: raise HandlerException("Cannot forward message: unknown recipient") self._logger.info( "Received forward for: %s", context.message_delivery.recipient_verkey ) packed = context.message.msg.encode("ascii") rt_mgr = RoutingManager(context) target = context.message.to try: recipient = await rt_mgr.get_recipient(target) except RoutingManagerError: self._logger.exception("Error resolving recipient for forwarded message") return # 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)