| 1 | package hostops |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "crypto/ed25519" |
| 6 | "slices" |
| 7 | |
| 8 | "github.com/carlosframework/platform/internal/hostclaim" |
| 9 | "github.com/carlosframework/platform/internal/hostfence" |
| 10 | "github.com/carlosframework/platform/internal/hostresolve" |
| 11 | "github.com/carlosframework/platform/internal/release" |
| 12 | ) |
| 13 | |
| 14 | // MoveLossKind reports a claim op kind whose target loss the moves owner |
| 15 | // resolves. Doors use it only to route; the typed methods check again. |
| 16 | func MoveLossKind(kind string) bool { return slices.Contains(moveLossKinds, kind) } |
| 17 | |
| 18 | // InspectMoveLoss is ControlWriter.InspectMoveLoss under the authority's |
| 19 | // own root signer and deployment bucket. |
| 20 | func (a *ProductionAuthority) InspectMoveLoss(ctx context.Context, actor, account, app, host, box string) (hostresolve.Inspection, error) { |
| 21 | if a == nil || a.Control == nil { |
| 22 | return hostresolve.Inspection{}, ErrContract |
| 23 | } |
| 24 | return a.Control.InspectMoveLoss(ctx, a.Signer, a.Directory.Bucket, actor, account, app, host, box) |
| 25 | } |
| 26 | |
| 27 | // DeclareMoveLoss is ControlWriter.DeclareMoveLoss under the authority's |
| 28 | // own root signer and deployment bucket. |
| 29 | func (a *ProductionAuthority) DeclareMoveLoss(ctx context.Context, actor, account, app, host, box string, in hostfence.Submission) error { |
| 30 | if a == nil || a.Control == nil { |
| 31 | return ErrContract |
| 32 | } |
| 33 | _, err := a.Control.DeclareMoveLoss(ctx, a.Signer, a.Directory.Bucket, actor, account, app, host, box, in) |
| 34 | return err |
| 35 | } |
| 36 | |
| 37 | // DeclaresMoveTargetLoss reports whether a submitted declaration's signed |
| 38 | // challenge declares the loss of a move's target, the rollback path |
| 39 | // (move-target-lost), and of which move and instance incarnation. A |
| 40 | // destroyed-local-only declaration, which changes no move state, is not |
| 41 | // one, and neither is a challenge that does not verify under pub. The move |
| 42 | // log names only a target loss (Plan 6 final re-review 1, N1). |
| 43 | func DeclaresMoveTargetLoss(pub ed25519.PublicKey, in hostfence.Submission) (op, incarnation string, ok bool) { |
| 44 | var c hostfence.Challenge |
| 45 | if len(pub) != ed25519.PublicKeySize || release.VerifyRootEnvelope(pub, in.Challenge, &c) != nil { |
| 46 | return "", "", false |
| 47 | } |
| 48 | if c.Consequences.Transition != moveLossTransition || c.Op.ID == "" { |
| 49 | return "", "", false |
| 50 | } |
| 51 | return c.Op.ID, c.HolderIncarnation, true |
| 52 | } |
| 53 | |
| 54 | // MoveTargetLossOf reports whether a loss record's signed consequences are |
| 55 | // the loss of a move's target (its recovery intent is move-target-lost), and |
| 56 | // of which move and instance incarnation. A destroyed-local-only record is |
| 57 | // not (Plan 6 final re-review 1, N1). |
| 58 | func MoveTargetLossOf(l hostclaim.LossRecord) (op, incarnation string, ok bool) { |
| 59 | in, err := decodeMoveLossIntent(l.ConfirmedConsequences.RecoveryIntent) |
| 60 | if err != nil { |
| 61 | return "", "", false |
| 62 | } |
| 63 | return in.Move, in.Incarnation, true |
| 64 | } |
| 65 | |