Skip to content

Commit

Permalink
Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Jul 5, 2023
1 parent ed14fb7 commit f3aafa7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ trait After {
case (e, a, _) if e == a => Chain.empty
case (e, a, l) if l.contains(e) =>
// Pingback in case no relays involved
Chain.fromOption(a.headOption.map(_.peerId))
Chain.fromOption(
a.headOption
.filterNot(e.headOption.contains)
.map(_.peerId)
)
case (e, a, _) =>
// We wasn't at e, so need to get through the last peer in case it matches with the relay
Topology.findRelayPathEnforcement(a, e) ++ Chain.fromOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import aqua.model.{OnModel, ParGroupModel, SeqGroupModel, ValueModel}

import cats.Eval
import cats.data.Chain
import cats.syntax.functor.*
import cats.instances.lazyList.*
import cats.syntax.option.*

// Parent == Xor
object XorBranch extends Before with After {
Expand All @@ -13,24 +16,24 @@ object XorBranch extends Before with After {
override def beforeOn(current: Topology): Eval[List[OnModel]] =
current.prevSibling.map(_.endsOn) getOrElse super.beforeOn(current)

private def closestParExit(current: Topology): Option[Topology] =
private def closestParExitChild(current: Topology): Option[Topology] =
current.parents
.map(t => t -> t.parent.map(_.cursor.op))
.takeWhile {
case (t, Some(_: ParGroupModel)) => true
case (t, Some(_: SeqGroupModel)) => t.nextSibling.isEmpty
.fproduct(_.parent.map(_.cursor.op))
.dropWhile {
case (t, Some(_: SeqGroupModel)) =>
t.nextSibling.isEmpty
case _ => false
}
.map(_._1)
.map(t => t -> t.cursor.op)
.collectFirst { case (t, _: ParGroupModel) =>
// println(Console.GREEN + s"collect ${t}" + Console.RESET)
t
}
.headOption
.collect { case (t, Some(_: ParGroupModel)) => t }

private def closestParExit(current: Topology): Option[Topology] =
closestParExitChild(current).flatMap(_.parent)

override def forceExit(current: Topology): Eval[Boolean] =
closestParExit(current)
.fold(Eval.later(current.cursor.moveUp.exists(_.hasExecLater)))(_.forceExit)
closestParExitChild(current).fold(
Eval.later(current.cursor.moveUp.exists(_.hasExecLater))
)(_.forceExit)

override def afterOn(current: Topology): Eval[List[OnModel]] =
current.forceExit.flatMap {
Expand All @@ -41,5 +44,5 @@ object XorBranch extends Before with After {

// Parent of this branch's parent xor – fixes the case when this xor is in par
override def pathAfter(current: Topology): Eval[Chain[ValueModel]] =
closestParExit(current).fold(super.pathAfter(current))(_ => pathAfterAndPingNext(current))
closestParExit(current).fold(super.pathAfter(current))(_ => super.pathAfterAndPingNext(current))
}

0 comments on commit f3aafa7

Please sign in to comment.