package host import ( "errors" "github.com/carlosframework/platform/internal/moves" ) var errRootFloorHistory = errors.New("root floor history unavailable") // This is a reconstruction decision, not an authority source. history is a // complete root-authorized reconstruction; legacy supplies only extra denies. // A nil history cannot be upgraded into authority by today's remote object. func reconstructRootFloor(history, remote *moves.Floor, legacy []*moves.Floor) (*moves.Floor, error) { if history == nil { return nil, errRootFloorHistory } out := *history valid := func(f *moves.Floor) bool { return f != nil && f.Min > 0 && validFloorRelease(f.MinRelease) } if !valid(&out) { return nil, errRootFloorHistory } for _, f := range legacy { if !valid(f) { return nil, errRootFloorHistory } if err := floorRegression(&out, f); err == nil { out = *f continue } // Independent maxima: a larger protocol and a larger release can occur // in different files. Never choose just one file by its release string. if f.Min > out.Min { out.Min = f.Min } if ok, _ := moves.ReleaseAtOrAbove(f.MinRelease, out.MinRelease); ok { out.MinRelease = f.MinRelease } } if remote == nil { if out != *history { return &out, errRootFloorHistory } return &out, nil } if !valid(remote) { return &out, errRootFloorHistory } if err := floorRegression(&out, remote); err != nil { return &out, err } next := *remote return &next, nil }