Skip to content

Commit

Permalink
feat: Send problem report on missing protocol or wrong version or wor…
Browse files Browse the repository at this point in the history
…ng role
  • Loading branch information
FabioPinheiro committed Jul 24, 2023
1 parent 6dbd93c commit 6a6603a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inThisBuild(

/** Versions */
lazy val V = new {
val scalaDID = "0.1.0-M6"
val scalaDID = "0.1.0-M6+0-b02d2b9e+20230724-1637-SNAPSHOT"
// val scalajsJavaSecureRandom = "1.0.0"

// FIXME another bug in the test framework https://github.com/scalameta/munit/issues/554
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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
//TODO pick a better name // maybe "Protocol" only

trait ProtocolExecuter[-R] {
Expand All @@ -29,7 +30,7 @@ trait ProtocolExecuter[-R] {
object ProtocolExecuter {
type Services = Resolver & Agent & Operations & MessageDispatcher
}
case class ProtocolExecuterCollection[-R](executers: ProtocolExecuter[R]*) extends ProtocolExecuter[R] {
case class ProtocolExecuterCollection[-R <: Agent](executers: ProtocolExecuter[R]*) extends ProtocolExecuter[R] {

override def suportedPIURI: Seq[PIURI] = executers.flatMap(_.suportedPIURI)

Expand All @@ -39,14 +40,16 @@ case class ProtocolExecuterCollection[-R](executers: ProtocolExecuter[R]*) exten
plaintextMessage: PlaintextMessage,
): ZIO[R1, MediatorError, Option[EncryptedMessage]] =
selectExecutersFor(plaintextMessage.`type`) match
case None => NullProtocolExecuter.execute(plaintextMessage)
// case None => NullProtocolExecuter.execute(plaintextMessage)
case None => MissingProtocolExecuter.execute(plaintextMessage)
case Some(px) => px.execute(plaintextMessage)

override def program[R1 <: R](
plaintextMessage: PlaintextMessage,
): ZIO[R1, MediatorError, Action] =
selectExecutersFor(plaintextMessage.`type`) match
case None => NullProtocolExecuter.program(plaintextMessage)
// case None => NullProtocolExecuter.program(plaintextMessage)
case None => MissingProtocolExecuter.program(plaintextMessage)
case Some(px) => px.program(plaintextMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,34 @@ object MediatorCoordinationExecuter extends ProtocolExecuterWithServices[Protoco
case `piuriKeylistQuery` => plaintextMessage.toKeylistQuery
case `piuriKeylist` => plaintextMessage.toKeylist
}).map {
case m: MediateGrant => ZIO.logWarning("MediateGrant") *> ZIO.succeed(NoReply)
case m: MediateDeny => ZIO.logWarning("MediateDeny") *> ZIO.succeed(NoReply)
case m: MediateGrant =>
ZIO.logWarning("MediateGrant") *> ZIO.succeed(NoReply) *>
ZIO.succeed(
SyncReplyOnly(
Problems
.unsupportedProtocolRole(
from = m.to.asFROM,
to = m.from.asTO,
pthid = m.id, // TODO CHECK pthid
piuri = m.piuri,
)
.toPlaintextMessage
)
)
case m: MediateDeny =>
ZIO.logWarning("MediateDeny") *> ZIO.succeed(NoReply) *>
ZIO.succeed(
SyncReplyOnly(
Problems
.unsupportedProtocolRole(
from = m.to.asFROM,
to = m.from.asTO,
pthid = m.id, // TODO CHECK pthid
piuri = m.piuri,
)
.toPlaintextMessage
)
)
case m: MediateRequest =>
for {
_ <- ZIO.logInfo("MediateRequest")
Expand Down Expand Up @@ -74,7 +100,20 @@ object MediatorCoordinationExecuter extends ProtocolExecuterWithServices[Protoco
}
}
} yield SyncReplyOnly(m.makeKeylistResponse(updateResponse).toPlaintextMessage)
case m: KeylistResponse => ZIO.logWarning("KeylistResponse") *> ZIO.succeed(NoReply)
case m: KeylistResponse =>
ZIO.logWarning("KeylistResponse") *> ZIO.succeed(NoReply) *>
ZIO.succeed(
SyncReplyOnly(
Problems
.unsupportedProtocolRole(
from = m.to.asFROM,
to = m.from.asTO,
pthid = m.id, // TODO CHECK pthid
piuri = m.piuri,
)
.toPlaintextMessage
)
)
case m: KeylistQuery =>
for {
_ <- ZIO.logInfo("KeylistQuery")
Expand All @@ -94,7 +133,7 @@ object MediatorCoordinationExecuter extends ProtocolExecuterWithServices[Protoco
case Some(response) => SyncReplyOnly(response.toPlaintextMessage)
case m: Keylist => ZIO.logWarning("Keylist") *> ZIO.succeed(NoReply)
} match
case Left(error) => ZIO.logError(error) *> ZIO.succeed(NoReply)
case Left(error) => ZIO.logError(error) *> ZIO.succeed(NoReply) // TODO error report
case Right(program) => program
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,20 @@ object PickupExecuter
live_delivery = None, // TODO
)
} yield SyncReplyOnly(status.toPlaintextMessage)
case m: Status => ZIO.logInfo("Status") *> ZIO.succeed(NoReply)
case m: Status =>
ZIO.logInfo("Status") *>
ZIO.succeed(
SyncReplyOnly(
Problems
.unsupportedProtocolRole(
from = m.to.asFROM,
to = m.from.asTO,
pthid = m.id, // TODO CHECK pthid
piuri = m.piuri,
)
.toPlaintextMessage
)
)
case m: DeliveryRequest =>
for {
_ <- ZIO.logInfo("DeliveryRequest")
Expand All @@ -73,7 +86,7 @@ object PickupExecuter
didRequestingMessages = m.from.asFROMTO
mDidAccount <- repoDidAccount.getDidAccount(didRequestingMessages.toDID)
msgHash = mDidAccount match
case None => ???
case None => ??? // TODO ERROR
case Some(didAccount) => didAccount.messagesRef.filter(_.state == false).map(_.hash)
allMessagesFor <- repoMessageItem.findByIds(msgHash)
messagesToReturn =
Expand Down Expand Up @@ -115,7 +128,20 @@ object PickupExecuter
m.message_id_list
)
} yield NoReply
case m: LiveModeChange => ZIO.logWarning("LiveModeChange not implemented") *> ZIO.succeed(NoReply) // TODO
case m: LiveModeChange =>
ZIO.logWarning("LiveModeChange not implemented") *>
ZIO.succeed(
SyncReplyOnly(
Problems
.protocolNotImplemented(
from = m.to.asFROM,
to = m.from.asTO,
pthid = m.id, // TODO CHECK pthid
piuri = m.piuri,
)
.toPlaintextMessage
)
)

} match
case Left(error) => ZIO.logError(error) *> ZIO.succeed(NoReply)
Expand Down

0 comments on commit 6a6603a

Please sign in to comment.