carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "errors"
5 "github.com/carlosframework/platform/internal/moves"
6)
7
8var errRootFloorHistory = errors.New("root floor history unavailable")
9
10// This is a reconstruction decision, not an authority source. history is a
11// complete root-authorized reconstruction; legacy supplies only extra denies.
12// A nil history cannot be upgraded into authority by today's remote object.
13func reconstructRootFloor(history, remote *moves.Floor, legacy []*moves.Floor) (*moves.Floor, error) {
14 if history == nil {
15 return nil, errRootFloorHistory
16 }
17 out := *history
18 valid := func(f *moves.Floor) bool { return f != nil && f.Min > 0 && validFloorRelease(f.MinRelease) }
19 if !valid(&out) {
20 return nil, errRootFloorHistory
21 }
22 for _, f := range legacy {
23 if !valid(f) {
24 return nil, errRootFloorHistory
25 }
26 if err := floorRegression(&out, f); err == nil {
27 out = *f
28 continue
29 }
30 // Independent maxima: a larger protocol and a larger release can occur
31 // in different files. Never choose just one file by its release string.
32 if f.Min > out.Min {
33 out.Min = f.Min
34 }
35 if ok, _ := moves.ReleaseAtOrAbove(f.MinRelease, out.MinRelease); ok {
36 out.MinRelease = f.MinRelease
37 }
38 }
39 if remote == nil {
40 if out != *history {
41 return &out, errRootFloorHistory
42 }
43 return &out, nil
44 }
45 if !valid(remote) {
46 return &out, errRootFloorHistory
47 }
48 if err := floorRegression(&out, remote); err != nil {
49 return &out, err
50 }
51 next := *remote
52 return &next, nil
53}
54