diff --git a/Mediator-Error_Handling.md b/Mediator-Error_Handling.md index 0cf21521..0de0d33f 100644 --- a/Mediator-Error_Handling.md +++ b/Mediator-Error_Handling.md @@ -12,22 +12,22 @@ https://identity.foundation/didcomm-messaging/spec/#problem-reports This table defines the expected behavior of the mediator in different scenarios not covered by the specifications. -| Mediators | Atala Mediator | Roadmap Atala Mediator | RootsId | Blocktrust | -|-------------|----------------|------------------------|---------|------------| -| Scenario G1 | G1C | - | ? | ? | -| Scenario G2 | G2A | [TODO ATL-5840] G2B | ? | ? | -| Scenario G3 | G3A | [TODO (next)] G3B | ? | ? | -| Scenario G4 | G4B | - | ? | ? | -| Scenario G5 | Fallback G4B | [TODO] G5B | ? | ? | -| Scenario G6 | Fallback G4B | [WIP] G6B | ? | ? | -| Scenario G7 | Fallback G4B | [TODO] G7B | ? | ? | -| Scenario G8 | G8C | - | ? | ? | -| | | | | | -| Scenario M1 | M1B | - | ? | ? | -| Scenario M2 | M2B | - | ? | ? | -| Scenario M3 | Fallback G4 | M3B | ? | ? | -| Scenario M4 | M4B | - | ? | ? | -| Scenario M5 | M5A | [TODO] M5B | ? | ? | +| Mediators | Atala Mediator | Roadmap Atala Mediator | │ | RootsId | Blocktrust | +|-------------|----------------|------------------------|---|---------|------------| +| Scenario G1 | G1C | - | │ | ? | ? | +| Scenario G2 | G2B [ATL-5840] | - | │ | | ? | +| Scenario G3 | Fallback G2B | [TODO] G3B | │ | | ? | +| Scenario G4 | G4B | - | │ | | ? | +| Scenario G5 | Fallback G4B | [TODO] G5B | │ | | ? | +| Scenario G6 | Fallback G4B | [WIP] G6B | │ | | ? | +| Scenario G7 | Fallback G4B | [TODO] G7B | │ | | ? | +| Scenario G8 | G8C | - | │ | | ? | +| | | | | | | +| Scenario M1 | M1B | - | │ | | ? | +| Scenario M2 | M2B | - | │ | | ? | +| Scenario M3 | Fallback G4 | M3B | │ | | ? | +| Scenario M4 | M4B | - | │ | | ? | +| Scenario M5 | M5A | [TODO] M5B | │ | | ? | ### Scenarios Description diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/actions/ActionUtils.scala b/mediator/src/main/scala/io/iohk/atala/mediator/actions/ActionUtils.scala index 498c8728..6133e29d 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/actions/ActionUtils.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/actions/ActionUtils.scala @@ -10,7 +10,6 @@ import fmgp.did.comm.protocol.trustping2.* import io.iohk.atala.mediator.* import io.iohk.atala.mediator.comm.* import io.iohk.atala.mediator.db.* -import io.iohk.atala.mediator.protocols.NullProtocolExecuter import zio.* import zio.json.* import io.iohk.atala.mediator.protocols.MissingProtocolExecuter diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/actions/ProtocolExecute.scala b/mediator/src/main/scala/io/iohk/atala/mediator/actions/ProtocolExecute.scala index aa4f1590..3738a443 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/actions/ProtocolExecute.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/actions/ProtocolExecute.scala @@ -10,21 +10,29 @@ import fmgp.did.comm.protocol.trustping2.* import io.iohk.atala.mediator.* import io.iohk.atala.mediator.comm.* import io.iohk.atala.mediator.db.* -import io.iohk.atala.mediator.protocols.NullProtocolExecuter +import io.iohk.atala.mediator.protocols.MissingProtocolExecuter import zio.* import zio.json.* -import io.iohk.atala.mediator.protocols.MissingProtocolExecuter //TODO pick a better name // maybe "Protocol" only trait ProtocolExecuter[-R, +E] { // <: MediatorError | StorageError] { def supportedPIURI: Seq[PIURI] - /** @return can return a Sync Reply Msg */ + /** @return + * can return a Sync Reply Msg + * + * MUST be override + * {{{ + * override def execute[R1 <: R]( + * plaintextMessage: PlaintextMessage + * ): ZIO[R1, E, Option[SignedMessage | EncryptedMessage]] = + * program(plaintextMessage) *> ZIO.none + * }}} + */ def execute[R1 <: R]( plaintextMessage: PlaintextMessage - ): ZIO[R1, E, Option[SignedMessage | EncryptedMessage]] = - program(plaintextMessage) *> ZIO.none + ): ZIO[R1, E, Option[SignedMessage | EncryptedMessage]] def program[R1 <: R](plaintextMessage: PlaintextMessage): ZIO[R1, E, Action] } @@ -33,9 +41,10 @@ object ProtocolExecuter { type Services = Resolver & Agent & Operations & MessageDispatcher & OutboxMessageRepo type Erros = MediatorError | StorageError } -case class ProtocolExecuterCollection[-R <: Agent, +E]( +case class ProtocolExecuterCollection[-R, +E]( executers: ProtocolExecuter[R, E]* -) extends ProtocolExecuter[R, E] { +)(fallback: ProtocolExecuter[R, E]) + extends ProtocolExecuter[R, E] { override def supportedPIURI: Seq[PIURI] = executers.flatMap(_.supportedPIURI) @@ -43,10 +52,10 @@ case class ProtocolExecuterCollection[-R <: Agent, +E]( override def execute[R1 <: R]( plaintextMessage: PlaintextMessage, - ): ZIO[R1, E, Option[SignedMessage | EncryptedMessage]] = + ): ZIO[R, E, Option[SignedMessage | EncryptedMessage]] = selectExecutersFor(plaintextMessage.`type`) match // case None => NullProtocolExecuter.execute(plaintextMessage) - case None => MissingProtocolExecuter.execute(plaintextMessage) + case None => fallback.execute(plaintextMessage) case Some(px) => px.execute(plaintextMessage) override def program[R1 <: R]( @@ -54,7 +63,7 @@ case class ProtocolExecuterCollection[-R <: Agent, +E]( ): ZIO[R1, E, Action] = selectExecutersFor(plaintextMessage.`type`) match // case None => NullProtocolExecuter.program(plaintextMessage) - case None => MissingProtocolExecuter.program(plaintextMessage) + case None => fallback.program(plaintextMessage) case Some(px) => px.program(plaintextMessage) } @@ -70,6 +79,7 @@ trait ProtocolExecuterWithServices[ program(plaintextMessage) .tap(v => ZIO.logDebug(v.toString)) // DEBUG .flatMap(action => ActionUtils.packResponse(Some(plaintextMessage), action)) + .debug override def program[R1 <: R]( plaintextMessage: PlaintextMessage, diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala index 77c324bf..ccaeaeab 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/app/MediatorAgent.scala @@ -46,7 +46,7 @@ case class MediatorAgent( MediatorCoordinationExecuter, ForwardMessageExecuter, PickupExecuter, - ) + )(fallback = MissingProtocolExecuter()) ) val messageDispatcherLayer: ZLayer[Client, MediatorThrowable, MessageDispatcher] = diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/BasicMessageExecuter.scala b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/BasicMessageExecuter.scala index c5141d00..71bb73ba 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/BasicMessageExecuter.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/BasicMessageExecuter.scala @@ -1,7 +1,7 @@ package io.iohk.atala.mediator.protocols import fmgp.crypto.error.FailToParse -import fmgp.did.comm.{PIURI, PlaintextMessage} +import fmgp.did.comm.{PIURI, PlaintextMessage, SignedMessage, EncryptedMessage} import fmgp.did.comm.protocol.basicmessage2.BasicMessage import io.iohk.atala.mediator.{MediatorError, MediatorDidError, MediatorThrowable} import io.iohk.atala.mediator.actions.{NoReply, ProtocolExecuter} @@ -10,6 +10,12 @@ import zio.{Console, ZIO} object BasicMessageExecuter extends ProtocolExecuter[Any, MediatorError] { override def supportedPIURI: Seq[PIURI] = Seq(BasicMessage.piuri) + + override def execute[R]( + plaintextMessage: PlaintextMessage + ): ZIO[R, MediatorError, Option[SignedMessage | EncryptedMessage]] = + program(plaintextMessage).debug *> ZIO.none + override def program[R1 <: Any](plaintextMessage: PlaintextMessage) = for { job <- BasicMessage.fromPlaintextMessage(plaintextMessage) match case Left(error) => ZIO.fail(MediatorDidError(FailToParse(error))) diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MissingProtocolExecuter.scala b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MissingProtocolExecuter.scala index 5058497e..4656c181 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MissingProtocolExecuter.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/MissingProtocolExecuter.scala @@ -7,8 +7,10 @@ import fmgp.did.comm.PlaintextMessage import io.iohk.atala.mediator.MissingProtocolError import io.iohk.atala.mediator.actions.ProtocolExecuter import io.iohk.atala.mediator.actions.Reply +import io.iohk.atala.mediator.actions.ProtocolExecuterWithServices +import io.iohk.atala.mediator.MediatorError -object MissingProtocolExecuter extends ProtocolExecuter[Agent, Nothing] { +case class MissingProtocolExecuter() extends ProtocolExecuterWithServices[ProtocolExecuter.Services, MediatorError] { override def supportedPIURI = Seq() override def program[R1 <: Agent](plaintextMessage: PlaintextMessage) = diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/NullProtocolExecuter.scala b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/NullProtocolExecuter.scala index fc865bfb..65c211b3 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/protocols/NullProtocolExecuter.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/protocols/NullProtocolExecuter.scala @@ -4,10 +4,18 @@ import fmgp.did.comm.PlaintextMessage import io.iohk.atala.mediator.MissingProtocolError import io.iohk.atala.mediator.actions.ProtocolExecuter import zio.ZIO +import fmgp.did.comm.SignedMessage +import fmgp.did.comm.EncryptedMessage object NullProtocolExecuter extends ProtocolExecuter[Any, MissingProtocolError] { override def supportedPIURI = Seq() + + override def execute[Any]( + plaintextMessage: PlaintextMessage + ): ZIO[Any, MissingProtocolError, Option[SignedMessage | EncryptedMessage]] = + program(plaintextMessage).debug *> ZIO.none + override def program[R1 <: Any](plaintextMessage: PlaintextMessage) = ZIO.fail(MissingProtocolError(plaintextMessage.`type`)) }