package hostbox import ( "reflect" "github.com/carlosframework/platform/internal/registry" ) // GenerationHandover is retained transfer evidence, read from root's journal. // It cannot authorize a new handover or discard a launch reservation. type GenerationHandover coldJournal func DecodeGenerationHandover(raw []byte) (GenerationHandover, error) { var j coldJournal if decodeStrict(raw, &j) != nil || j.V != 1 || j.Phase != "complete" || j.IntendedAbsent || j.ServingInstallation == nil { return GenerationHandover{}, ErrTypedJournal } p, n, in := j.Prior, j.Successor, j.Inventory if p.Host == "" || p.Incarnation == "" || n.Host != p.Host || n.Incarnation != p.Incarnation || n.Box != p.Box || n.Enrollment != p.Enrollment || n.Stamp <= p.Stamp || n.Session != n.Stamp || n.Session <= p.Session || n.Generation == "" || n.ETag == "" || n.Op != "" || n.Phase != "" || p.Op != "" || p.Phase != "" || p.ObligationID != "" || j.ID != "serving-handover-"+ownershipFor(n.Host, n.Incarnation, n.Stamp, n.Box) || !in.Complete || in.Host != p.Host || in.Incarnation != p.Incarnation || in.InstallationStamp != p.Stamp || in.Box != p.Box || in.Enrollment != p.Enrollment || in.DirectoryRevision != p.DirectoryRevision { return GenerationHandover{}, ErrTypedJournal } barrier := p barrier.FenceID, barrier.Stamp, barrier.Session, barrier.ClaimETag, barrier.DirectoryRevision = j.ID, n.Stamp, n.Session, n.ETag, n.DirectoryRevision if j.Barrier != barrier { return GenerationHandover{}, ErrTypedJournal } after := j.Before after.Timers = append([]registry.Timer(nil), j.Before.Timers...) owner := ownershipFor(n.Host, n.Incarnation, n.Stamp, n.Box) after.Route.ClaimOwnership = registry.ClaimOwnership{ClaimIncarnation: n.Incarnation, ClaimStamp: n.Stamp, ClaimOwner: owner, ClaimRowID: rowIDFor(owner, "route", n.Host)} for i := range after.Timers { after.Timers[i].ClaimOwnership = after.Route.ClaimOwnership after.Timers[i].ClaimRowID = rowIDFor(owner, "timer", after.Timers[i].Name) } if !reflect.DeepEqual(after, j.After) { return GenerationHandover{}, ErrTypedJournal } return GenerationHandover(j), nil }