carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1package regionname
2
3import "regexp"
4
5// HomeRegion is the engine region of the home placement (home-region parks,
6// part 1, Paul 2026-10-11). The home's placement code is "", and "" already
7// means unset to the engine and to the claim: an engine, view, chore or
8// admission with region "" is refused or read as "holds nothing anywhere".
9// So home is never "" here. It is this token, mapped once from the placement
10// code by PlacementRegion where a box's or a record's code becomes an engine
11// region.
12//
13// The "@" is outside the placement-code alphabet (provision.ValidRegion:
14// lowercase a-z, 0-9 and hyphen), so no named region, one named "home"
15// included, can ever equal it. It reaches the claim's obligation region, its
16// "region:" owner, its quiet_after key and one control key, the home lane's
17// staging lease (control/staging-leases/@home/<host>, keyed in the host's
18// wiring). It never reaches an archive path: the archive is
19// parked/<incarnation>/<host>/<retirement>/.
20const HomeRegion = "@home"
21
22// placementCode is a named placement code: provision.ValidRegion without the
23// empty code. TestHomeRegionIsReserved holds the two together.
24var placementCode = regexp.MustCompile(`^[a-z0-9-]{1,16}$`)
25
26// PlacementRegion is the engine region of a placement code: HomeRegion for
27// the home's "", a named code unchanged, and "" (unset, which every engine
28// entry refuses) for anything that is not a placement code, HomeRegion
29// itself included.
30func PlacementRegion(code string) string {
31 switch {
32 case code == "":
33 return HomeRegion
34 case placementCode.MatchString(code):
35 return code
36 }
37 return ""
38}
39
40func HomePlacementCode(home, region string) string {
41 if home != "" && region == home {
42 return ""
43 }
44 return region
45}
46
47// SameRegion preserves exact stored identities. The only alias is a verified
48// home roster name and @home. Empty always means unset at this boundary.
49func SameRegion(home, a, b string) bool {
50 if a == "" || b == "" {
51 return false
52 }
53 if a == b {
54 return true
55 }
56 return home != "" && PlacementRegion(home) == home &&
57 ((a == home && b == HomeRegion) || (a == HomeRegion && b == home))
58}
59