edges: each box publishes its addresses as addrs, inside the write gate (#328)
Each box's edges file carries addrs: every non-loopback address it holds (instancectl.LocalAddresses), /32 and /128 bare, wider LOCAL ranges as prefixes, sorted. The field is set before the gate copy, so a change of address rewrites the file on the next due pass and an unchanged one adds no request, with region HA on or off. [] is a box with nothing to publish; null is a failed read, which the console treats as lacking. edgesFileWriteClaims takes the reader as a parameter (ruling C17); the loop passes instancectl.LocalAddresses, and edgesFileWrite passes none. internal/edgesfile reads them: ReadAddrs (the grant check's full read), ReadAddrsCached (one ListETags, a Get only for a new or changed file) and AddrInventory.Holder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+771
−17
internal/edgesfile/addrs.go+211 −0internal/edgesfile/addrs_test.go+261 −0internal/edgesfile/edgesfile.go+5 −0internal/host/boxaddress_test.go+7 −7internal/host/edgesclaims_test.go+1 −1internal/host/edgesfile.go+64 −5internal/host/edgesfile_test.go+222 −4
diff --git a/internal/edgesfile/addrs.go b/internal/edgesfile/addrs.go| new file mode 100644 |
| index 000000000..150e17ae3 |
| --- /dev/null |
| +++ b/internal/edgesfile/addrs.go |
| @@ -0,0 +1,211 @@ |
| +package edgesfile |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "net/netip" |
| + "slices" |
| + "strings" |
| + "sync" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The fleet's box addresses (#328, spec §4.2): each box publishes every |
| +// non-loopback address it holds as its file's addrs, and the console checks |
| +// an egress grant against them (ReadAddrs) and reports allows that a box |
| +// has since taken (ReadAddrsCached, which reads only changed files). |
| + |
| +// AddrInventory is one read of every box's published addresses. |
| +type AddrInventory struct { |
| + Boxes map[string][]netip.Prefix // box -> published addrs (bare address = full-length prefix) |
| + Unreadable []string // keys that could not be read or parsed |
| + Missing []string // boxes whose file has no addrs (absent or null: an older box, or a failed read) |
| +} |
| + |
| +// Holder names a box whose published addresses contain a, if any. An |
| +// IPv4-mapped address is matched as IPv4 and a zone is ignored. With two |
| +// holders the first by box name is answered. |
| +func (inv AddrInventory) Holder(a netip.Addr) (box string, ok bool) { |
| + a = a.Unmap().WithZone("") |
| + boxes := make([]string, 0, len(inv.Boxes)) |
| + for b := range inv.Boxes { |
| + boxes = append(boxes, b) |
| + } |
| + slices.Sort(boxes) |
| + for _, b := range boxes { |
| + for _, p := range inv.Boxes[b] { |
| + if p.Contains(a) { |
| + return b, true |
| + } |
| + } |
| + } |
| + return "", false |
| +} |
| + |
| +// addrEntry is what one file says: its box and addresses, its box lacking |
| +// them, or nothing usable. |
| +type addrEntry struct { |
| + box string |
| + addrs []netip.Prefix // nil when missing |
| + missing bool |
| + unreadable bool |
| +} |
| + |
| +// parseAddrEntry reads one file's body. A file this package cannot parse, |
| +// with no box, or with an entry that is not an address or a prefix is |
| +// unreadable: its box's addresses are not known. |
| +func parseAddrEntry(body []byte) addrEntry { |
| + f, err := Parse(body) |
| + if err != nil || f.Box == "" { |
| + return addrEntry{unreadable: true} |
| + } |
| + if f.Addrs == nil { |
| + return addrEntry{box: f.Box, missing: true} |
| + } |
| + out := make([]netip.Prefix, 0, len(f.Addrs)) |
| + for _, s := range f.Addrs { |
| + p, err := parseAddr(s) |
| + if err != nil { |
| + return addrEntry{unreadable: true} |
| + } |
| + out = append(out, p) |
| + } |
| + return addrEntry{box: f.Box, addrs: out} |
| +} |
| + |
| +// parseAddr reads a bare address as its full-length prefix, or a prefix. |
| +func parseAddr(s string) (netip.Prefix, error) { |
| + if strings.Contains(s, "/") { |
| + p, err := netip.ParsePrefix(s) |
| + if err != nil { |
| + return netip.Prefix{}, err |
| + } |
| + return p.Masked(), nil |
| + } |
| + a, err := netip.ParseAddr(s) |
| + if err != nil || a.Zone() != "" { |
| + return netip.Prefix{}, fmt.Errorf("edgesfile: %q is not an address", s) |
| + } |
| + return netip.PrefixFrom(a, a.BitLen()), nil |
| +} |
| + |
| +// edgesKey reports whether key is a box's file: directly under Prefix, |
| +// ending .json (ReadSnapshot's rule). |
| +func edgesKey(key string) bool { |
| + name, ok := strings.CutPrefix(key, Prefix) |
| + return ok && strings.HasSuffix(name, ".json") && !strings.Contains(name, "/") |
| +} |
| + |
| +// addrsBuilder folds entries, keyed by bucket key, into an inventory. |
| +type addrsBuilder struct{ inv AddrInventory } |
| + |
| +func newAddrsBuilder() *addrsBuilder { |
| + return &addrsBuilder{inv: AddrInventory{Boxes: map[string][]netip.Prefix{}}} |
| +} |
| + |
| +func (b *addrsBuilder) add(key string, e addrEntry) { |
| + switch { |
| + case e.unreadable: |
| + b.inv.Unreadable = append(b.inv.Unreadable, key) |
| + case e.missing: |
| + b.inv.Missing = append(b.inv.Missing, e.box) |
| + default: |
| + // A copy, never the cache's slice; empty stays non-nil. |
| + cur, ok := b.inv.Boxes[e.box] |
| + if !ok { |
| + cur = []netip.Prefix{} |
| + } |
| + b.inv.Boxes[e.box] = append(cur, e.addrs...) |
| + } |
| +} |
| + |
| +func (b *addrsBuilder) done() AddrInventory { |
| + slices.Sort(b.inv.Unreadable) |
| + slices.Sort(b.inv.Missing) |
| + b.inv.Missing = slices.Compact(b.inv.Missing) |
| + return b.inv |
| +} |
| + |
| +// ReadAddrs lists control/edges/ and reads every box's file: the grant |
| +// check's read (one List and a Get per file, on a grant only). The error |
| +// is the listing's; a file that cannot be read is in Unreadable. |
| +func ReadAddrs(ctx context.Context, s release.Store) (AddrInventory, error) { |
| + keys, err := s.List(ctx, Prefix) |
| + if err != nil { |
| + return AddrInventory{}, err |
| + } |
| + b := newAddrsBuilder() |
| + for _, key := range keys { |
| + if !edgesKey(key) { |
| + continue |
| + } |
| + body, _, err := s.Get(ctx, key) |
| + if err != nil { |
| + b.add(key, addrEntry{unreadable: true}) |
| + continue |
| + } |
| + b.add(key, parseAddrEntry(body)) |
| + } |
| + return b.done(), nil |
| +} |
| + |
| +// AddrCache keeps each edges file's ETag and parsed addrs between reads. |
| +// The zero value is empty and ready; one cache serves one store. |
| +type AddrCache struct { |
| + mu sync.Mutex |
| + entries map[string]cachedAddrs // by key |
| +} |
| + |
| +type cachedAddrs struct { |
| + etag string |
| + entry addrEntry |
| +} |
| + |
| +// ReadAddrsCached is ReadAddrs for the report (Task 10, spec §3a): one |
| +// ListETags of control/edges/, a Get only for a key that is new or whose ETag |
| +// changed, cached entries dropped for keys no longer listed. A store that is |
| +// not a release.ETagLister falls back to ReadAddrs, reading every file. |
| +// |
| +// A file whose Get fails is unreadable this time and is not cached, so the |
| +// next read asks again; a file that was read but does not parse is cached |
| +// under its ETag, since the same body parses the same way. |
| +func ReadAddrsCached(ctx context.Context, s release.Store, c *AddrCache) (AddrInventory, error) { |
| + l, ok := s.(release.ETagLister) |
| + if !ok { |
| + return ReadAddrs(ctx, s) |
| + } |
| + listed, err := l.ListETags(ctx, Prefix) |
| + if errors.Is(err, errors.ErrUnsupported) { |
| + // A prefix wrapper over a store with no ETag listing. |
| + return ReadAddrs(ctx, s) |
| + } |
| + if err != nil { |
| + return AddrInventory{}, err |
| + } |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + next := make(map[string]cachedAddrs, len(listed)) |
| + b := newAddrsBuilder() |
| + for _, ke := range listed { |
| + if !edgesKey(ke.Key) { |
| + continue |
| + } |
| + if prev, ok := c.entries[ke.Key]; ok && ke.ETag != "" && prev.etag == ke.ETag { |
| + next[ke.Key] = prev |
| + b.add(ke.Key, prev.entry) |
| + continue |
| + } |
| + body, _, err := s.Get(ctx, ke.Key) |
| + if err != nil { |
| + b.add(ke.Key, addrEntry{unreadable: true}) |
| + continue |
| + } |
| + e := parseAddrEntry(body) |
| + next[ke.Key] = cachedAddrs{etag: ke.ETag, entry: e} |
| + b.add(ke.Key, e) |
| + } |
| + c.entries = next |
| + return b.done(), nil |
| +} |
diff --git a/internal/edgesfile/addrs_test.go b/internal/edgesfile/addrs_test.go| new file mode 100644 |
| index 000000000..4251ab780 |
| --- /dev/null |
| +++ b/internal/edgesfile/addrs_test.go |
| @@ -0,0 +1,261 @@ |
| +package edgesfile |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "net/netip" |
| + "slices" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +func putEdgesBody(t *testing.T, s release.Store, box, body string) { |
| + t.Helper() |
| + if _, err := s.Put(context.Background(), Key(box), []byte(body), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func replaceEdgesBody(t *testing.T, s release.Store, box, body string) { |
| + t.Helper() |
| + _, etag, err := s.Get(context.Background(), Key(box)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := s.Put(context.Background(), Key(box), []byte(body), etag); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// getFailing fails the Get of one key and serves the rest. |
| +type getFailing struct { |
| + release.Store |
| + key string |
| +} |
| + |
| +func (g getFailing) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == g.key { |
| + return nil, "", errors.New("read refused") |
| + } |
| + return g.Store.Get(ctx, key) |
| +} |
| + |
| +// Each kind of file lands in exactly one place: published addresses (an |
| +// empty list included) in Boxes, no addresses (absent: an older box; null: |
| +// a failed read) in Missing, and anything that cannot be read or parsed in |
| +// Unreadable, by key. |
| +func TestReadAddrsInventory(t *testing.T) { |
| + t.Parallel() |
| + dir := release.NewDirStore(t.TempDir()) |
| + putEdgesBody(t, dir, "annie", `{"v":1,"box":"annie","eip":"","addrs":["10.0.1.5","fd00:5::/64"],"hosts":{}}`) |
| + putEdgesBody(t, dir, "betty", `{"v":1,"box":"betty","eip":"","hosts":{}}`) |
| + putEdgesBody(t, dir, "carla", `{"v":1,"box":"carla","eip":"","addrs":null,"hosts":{}}`) |
| + putEdgesBody(t, dir, "dora", `{"v":1,"box":"dora","eip":"","addrs":[],"hosts":{}}`) |
| + putEdgesBody(t, dir, "edna", `{"v":1,"box":"edna",`) |
| + putEdgesBody(t, dir, "fran", `{"box":"fran","eip":"","addrs":["10.0.1.9"],"hosts":{}}`) |
| + putEdgesBody(t, dir, "gwen", `{"v":1,"box":"gwen","eip":"","addrs":["not-an-address"],"hosts":{}}`) |
| + putEdgesBody(t, dir, "hope", `{"v":1,"box":"hope","eip":"","addrs":["10.0.1.7"],"hosts":{}}`) |
| + // Not edges files: never read. |
| + if _, err := dir.Put(context.Background(), Prefix+"notes.txt", []byte("x"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := dir.Put(context.Background(), Prefix+"old/annie.json", []byte("x"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + s := getFailing{Store: dir, key: Key("hope")} |
| + |
| + inv, err := ReadAddrs(context.Background(), s) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + want := map[string][]netip.Prefix{ |
| + "annie": {netip.MustParsePrefix("10.0.1.5/32"), netip.MustParsePrefix("fd00:5::/64")}, |
| + "dora": {}, |
| + } |
| + if fmt.Sprint(inv.Boxes) != fmt.Sprint(want) || len(inv.Boxes) != 2 { |
| + t.Errorf("Boxes = %v, want %v", inv.Boxes, want) |
| + } |
| + if got, ok := inv.Boxes["dora"]; !ok || got == nil { |
| + t.Errorf("an empty list is a box with nothing to publish, not a missing one: %v %v", got, ok) |
| + } |
| + if want := []string{"betty", "carla"}; !slices.Equal(inv.Missing, want) { |
| + t.Errorf("Missing = %v, want %v", inv.Missing, want) |
| + } |
| + if want := []string{Key("edna"), Key("fran"), Key("gwen"), Key("hope")}; !slices.Equal(inv.Unreadable, want) { |
| + t.Errorf("Unreadable = %v, want %v", inv.Unreadable, want) |
| + } |
| + |
| + if _, err := ReadAddrs(context.Background(), brokenStore{}); !errors.Is(err, errBrokenStore) { |
| + t.Errorf("a failed listing must be an error, got %v", err) |
| + } |
| +} |
| + |
| +func TestReadAddrsHolderMatchesPrefixes(t *testing.T) { |
| + t.Parallel() |
| + inv := AddrInventory{Boxes: map[string][]netip.Prefix{ |
| + "annie": {netip.MustParsePrefix("10.0.1.5/32")}, |
| + "betty": {netip.MustParsePrefix("fd00:5::/64"), netip.MustParsePrefix("fe80::1/128")}, |
| + "carla": {}, |
| + }} |
| + for addr, want := range map[string]string{ |
| + "10.0.1.5": "annie", |
| + "::ffff:10.0.1.5": "annie", |
| + "fd00:5::20": "betty", |
| + "fe80::1%eth0": "betty", |
| + "10.0.1.6": "", |
| + "fd00:6::20": "", |
| + "10.0.5.20": "", |
| + "fe80::2": "", |
| + } { |
| + box, ok := inv.Holder(netip.MustParseAddr(addr)) |
| + if box != want || ok != (want != "") { |
| + t.Errorf("Holder(%s) = %q, %v; want %q", addr, box, ok, want) |
| + } |
| + } |
| +} |
| + |
| +// countingETagStore counts requests and forwards the listing with ETags. |
| +type countingETagStore struct { |
| + release.Store |
| + lists, listETags, gets int |
| +} |
| + |
| +func (c *countingETagStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + c.gets++ |
| + return c.Store.Get(ctx, key) |
| +} |
| + |
| +func (c *countingETagStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + c.lists++ |
| + return c.Store.List(ctx, prefix) |
| +} |
| + |
| +func (c *countingETagStore) ListETags(ctx context.Context, prefix string) ([]release.KeyETag, error) { |
| + c.listETags++ |
| + return c.Store.(release.ETagLister).ListETags(ctx, prefix) |
| +} |
| + |
| +// countingPlainStore counts requests and has no listing with ETags. |
| +type countingPlainStore struct { |
| + release.Store |
| + lists, gets int |
| +} |
| + |
| +func (c *countingPlainStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + c.gets++ |
| + return c.Store.Get(ctx, key) |
| +} |
| + |
| +func (c *countingPlainStore) List(ctx context.Context, prefix string) ([]string, error) { |
| + c.lists++ |
| + return c.Store.List(ctx, prefix) |
| +} |
| + |
| +// The report's read (spec §3a): one listing with ETags, and a Get only for |
| +// a file that is new or changed. A deleted file's box leaves the inventory. |
| +func TestReadAddrsCachedGetsOnlyChangedFiles(t *testing.T) { |
| + t.Parallel() |
| + ctx := context.Background() |
| + dir := release.NewDirStore(t.TempDir()) |
| + putEdgesBody(t, dir, "annie", `{"v":1,"box":"annie","eip":"","addrs":["10.0.1.5"],"hosts":{}}`) |
| + putEdgesBody(t, dir, "betty", `{"v":1,"box":"betty","eip":"","addrs":["10.0.1.6"],"hosts":{}}`) |
| + putEdgesBody(t, dir, "carla", `{"v":1,"box":"carla","eip":"","hosts":{}}`) |
| + |
| + s := &countingETagStore{Store: dir} |
| + var c AddrCache |
| + read := func(step string, wantGets int) AddrInventory { |
| + t.Helper() |
| + s.lists, s.listETags, s.gets = 0, 0, 0 |
| + inv, err := ReadAddrsCached(ctx, s, &c) |
| + if err != nil { |
| + t.Fatalf("%s: %v", step, err) |
| + } |
| + if s.listETags != 1 || s.lists != 0 || s.gets != wantGets { |
| + t.Fatalf("%s: %d ListETags, %d List, %d Get; want 1, 0, %d", step, s.listETags, s.lists, s.gets, wantGets) |
| + } |
| + return inv |
| + } |
| + |
| + inv := read("first read", 3) |
| + if len(inv.Boxes) != 2 || !slices.Equal(inv.Missing, []string{"carla"}) { |
| + t.Fatalf("first read: %+v", inv) |
| + } |
| + inv = read("unchanged", 0) |
| + if fmt.Sprint(inv.Boxes) != "map[annie:[10.0.1.5/32] betty:[10.0.1.6/32]]" || !slices.Equal(inv.Missing, []string{"carla"}) { |
| + t.Fatalf("unchanged read from the cache: %+v", inv) |
| + } |
| + |
| + replaceEdgesBody(t, dir, "betty", `{"v":1,"box":"betty","eip":"","addrs":["10.0.1.8"],"hosts":{}}`) |
| + inv = read("one file rewritten", 1) |
| + if h, ok := inv.Holder(netip.MustParseAddr("10.0.1.8")); !ok || h != "betty" { |
| + t.Fatalf("the rewritten file's address: %q %v", h, ok) |
| + } |
| + if _, ok := inv.Holder(netip.MustParseAddr("10.0.1.6")); ok { |
| + t.Fatal("the rewritten file's old address is still held") |
| + } |
| + |
| + if err := dir.Delete(ctx, Key("annie")); err != nil { |
| + t.Fatal(err) |
| + } |
| + inv = read("one file deleted", 0) |
| + if _, ok := inv.Boxes["annie"]; ok { |
| + t.Fatalf("a deleted file's box is still in the inventory: %+v", inv) |
| + } |
| + if len(c.entries) != 2 { |
| + t.Fatalf("the cache kept %d entries, want 2", len(c.entries)) |
| + } |
| + |
| + // A store with no listing with ETags is read in full every time. |
| + plain := &countingPlainStore{Store: dir} |
| + var pc AddrCache |
| + for i := 0; i < 2; i++ { |
| + plain.lists, plain.gets = 0, 0 |
| + inv, err := ReadAddrsCached(ctx, plain, &pc) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if plain.lists != 1 || plain.gets != 2 || len(inv.Boxes) != 1 || !slices.Equal(inv.Missing, []string{"carla"}) { |
| + t.Fatalf("plain store read %d: %d List, %d Get, %+v", i, plain.lists, plain.gets, inv) |
| + } |
| + } |
| +} |
| + |
| +// A file whose Get failed is retried on the next read, not cached as |
| +// unreadable. |
| +func TestReadAddrsCachedRetriesAFailedRead(t *testing.T) { |
| + t.Parallel() |
| + ctx := context.Background() |
| + dir := release.NewDirStore(t.TempDir()) |
| + putEdgesBody(t, dir, "annie", `{"v":1,"box":"annie","eip":"","addrs":["10.0.1.5"],"hosts":{}}`) |
| + failing := &countingETagStore{Store: getFailing{Store: dir, key: Key("annie")}} |
| + var c AddrCache |
| + // getFailing hides ListETags, so forward it from the directory store. |
| + s := &etagForwarding{countingETagStore: failing, lister: dir} |
| + inv, err := ReadAddrsCached(ctx, s, &c) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if !slices.Equal(inv.Unreadable, []string{Key("annie")}) { |
| + t.Fatalf("failed read: %+v", inv) |
| + } |
| + failing.Store = dir |
| + inv, err = ReadAddrsCached(ctx, s, &c) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if len(inv.Unreadable) != 0 || len(inv.Boxes["annie"]) != 1 { |
| + t.Fatalf("after the store recovered: %+v", inv) |
| + } |
| +} |
| + |
| +type etagForwarding struct { |
| + *countingETagStore |
| + lister release.ETagLister |
| +} |
| + |
| +func (e *etagForwarding) ListETags(ctx context.Context, prefix string) ([]release.KeyETag, error) { |
| + e.listETags++ |
| + return e.lister.ListETags(ctx, prefix) |
| +} |
diff --git a/internal/edgesfile/edgesfile.go b/internal/edgesfile/edgesfile.go| index 10346696d..0847b083a 100644 |
| --- a/internal/edgesfile/edgesfile.go |
| +++ b/internal/edgesfile/edgesfile.go |
| @@ -72,6 +72,11 @@ type File struct { |
| Region string `json:"region,omitempty"` |
| Generation string `json:"generation,omitempty"` |
| Hosts map[string]Host `json:"hosts"` |
| + // Addrs is every non-loopback address the box holds, each a bare |
| + // address or a prefix (#328). nil is absent or null: a writer that |
| + // predates the field, or a box whose read failed. Empty is a box with |
| + // nothing to publish. ReadAddrs is its reader. |
| + Addrs []string `json:"addrs"` |
| } |
| // Parse decodes one box's body. Pure — no store I/O. V < 1 (no version field |
diff --git a/internal/host/boxaddress_test.go b/internal/host/boxaddress_test.go| index ec234441f..c57e12d7a 100644 |
| --- a/internal/host/boxaddress_test.go |
| +++ b/internal/host/boxaddress_test.go |
| @@ -160,13 +160,13 @@ func TestEdgesFilePublishesOnlyWhatTheSourceReports(t *testing.T) { |
| var last []byte |
| ident := edgesFile{Box: "annie", BoxID: "annie"} |
| // The loop's own reading (the eip argument) is not what is published. |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "198.51.100.1", &last, false, claims); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "198.51.100.1", &last, false, claims, nil); err != nil { |
| t.Fatal(err) |
| } |
| if f := readEdgesFile(t, s, "annie"); f.EIP != "203.0.113.9" || f.PrivateIP != "10.0.1.5" || f.PrivateCIDR != "10.0.0.0/16" { |
| t.Fatalf("first publication: %+v", f) |
| } |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, false, claims); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, false, claims, nil); err != nil { |
| t.Fatal(err) |
| } |
| if f := readEdgesFile(t, s, "annie"); f.EIP != "" || f.PrivateIP != "10.0.1.5" { |
| @@ -184,10 +184,10 @@ func TestEdgesFileWithRegionHAOffKeepsTheEIPHold(t *testing.T) { |
| seedRoute(t, reg, "app.example.com") |
| var last []byte |
| ident := edgesFile{Box: "annie"} |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "203.0.113.9", &last, false, nil); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "203.0.113.9", &last, false, nil, nil); err != nil { |
| t.Fatal(err) |
| } |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, nil); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, nil, nil); err != nil { |
| t.Fatal(err) |
| } |
| if f := readEdgesFile(t, s, "annie"); f.EIP != "203.0.113.9" || f.PrivateIP != "" || f.PrivateCIDR != "" { |
| @@ -277,7 +277,7 @@ func TestEdgesFileUnknownAddressesLeaveThePublishedFileStanding(t *testing.T) { |
| claims.addrs = src |
| var last []byte |
| ident := edgesFile{Box: "annie", BoxID: "annie"} |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, false, claims); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, false, claims, nil); err != nil { |
| t.Fatal(err) |
| } |
| before, _, err := s.Get(context.Background(), edgesFileKey("annie")) |
| @@ -286,7 +286,7 @@ func TestEdgesFileUnknownAddressesLeaveThePublishedFileStanding(t *testing.T) { |
| } |
| lastBefore := string(last) |
| // A forced timed pass, which would rewrite an unchanged body. |
| - err = edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, claims) |
| + err = edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, claims, nil) |
| if !errors.Is(err, errBoxAddressesUnknown) { |
| t.Fatalf("unknown read: err %v, want errBoxAddressesUnknown", err) |
| } |
| @@ -301,7 +301,7 @@ func TestEdgesFileUnknownAddressesLeaveThePublishedFileStanding(t *testing.T) { |
| t.Fatalf("published file lost its addresses: %+v", f) |
| } |
| // The retry reads again and publishes what it now reports. |
| - if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, claims); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), s, reg, ident, "", &last, true, claims, nil); err != nil { |
| t.Fatal(err) |
| } |
| if f := readEdgesFile(t, s, "annie"); f.PrivateIP != "10.0.1.6" { |
diff --git a/internal/host/edgesclaims_test.go b/internal/host/edgesclaims_test.go| index a3f40a519..aed820ba6 100644 |
| --- a/internal/host/edgesclaims_test.go |
| +++ b/internal/host/edgesclaims_test.go |
| @@ -57,7 +57,7 @@ func publishWithClaims(t *testing.T, reg *registry.Registry, claims *edgesClaims |
| } |
| st := release.NewDirStore(t.TempDir()) |
| var last []byte |
| - if err := edgesFileWriteClaims(context.Background(), st, reg, edgesFile{Box: "annie", BoxID: "annie"}, "1.2.3.4", &last, false, claims); err != nil { |
| + if err := edgesFileWriteClaims(context.Background(), st, reg, edgesFile{Box: "annie", BoxID: "annie"}, "1.2.3.4", &last, false, claims, nil); err != nil { |
| t.Fatal(err) |
| } |
| body, _, err := st.Get(context.Background(), edgesFileKey("annie")) |
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go| index c51489b2f..878612673 100644 |
| --- a/internal/host/edgesfile.go |
| +++ b/internal/host/edgesfile.go |
| @@ -8,6 +8,7 @@ import ( |
| "fmt" |
| "log" |
| "math/rand/v2" |
| + "net/netip" |
| "os" |
| "slices" |
| "strings" |
| @@ -16,6 +17,7 @@ import ( |
| "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/hostclaim" |
| + "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -354,6 +356,18 @@ type edgesFile struct { |
| SeedsFloorMinRelease string `json:"seeds_floor_min_release,omitempty"` |
| PrevSeedsAllowedFor string `json:"prev_seeds_allowed_for,omitempty"` |
| + // Facts this box reads about itself on every pass, inside the change |
| + // gate: a change rewrites the file on the next pass, an unchanged |
| + // reading writes nothing (spec §3a), with region HA on or off. |
| + // |
| + // Addrs is every non-loopback address this box holds (boxAddrs), read |
| + // by the console's egress grant check and report (#328, spec §4.2): an |
| + // allow must not open a fleet box. NOT omitempty, and the two empty |
| + // forms differ: [] is a box with nothing to publish, null a box whose |
| + // read failed, which the console treats as lacking, like a file |
| + // written before the field existed. |
| + Addrs []string `json:"addrs"` |
| + |
| Generation string `json:"generation"` |
| Hosts map[string]edgeHost `json:"hosts"` |
| } |
| @@ -406,8 +420,49 @@ func edgesFilePass(ctx context.Context, s release.Store, reg *registry.Registry, |
| // its headroom reading changed, so headroom is never more than one timer |
| // period stale. On every other pass a headroom change alone is not a |
| // reason to write. |
| +// |
| +// It reads no box addresses, so it publishes "addrs":null; the loop passes |
| +// its reader to edgesFileWriteClaims. |
| func edgesFileWrite(ctx context.Context, s release.Store, reg *registry.Registry, ident edgesFile, eip string, last *[]byte, refresh bool) error { |
| - return edgesFileWriteClaims(ctx, s, reg, ident, eip, last, refresh, nil) |
| + return edgesFileWriteClaims(ctx, s, reg, ident, eip, last, refresh, nil, nil) |
| +} |
| + |
| +// boxAddrs is what Addrs publishes from read (instancectl.LocalAddresses |
| +// in production): every non-loopback LOCAL entry, a /32 or /128 as the |
| +// bare address and a wider range as its prefix, once each, ordered by |
| +// address (IPv4 first). Nothing left is an empty list; a failed read, or |
| +// no reader, is nil, which marshals as null. |
| +func boxAddrs(read func() ([]netip.Prefix, error)) []string { |
| + if read == nil { |
| + return nil |
| + } |
| + local, err := read() |
| + if err != nil { |
| + return nil |
| + } |
| + var keep []netip.Prefix |
| + for _, p := range local { |
| + p = p.Masked() |
| + if !p.IsValid() || p.Addr().IsLoopback() || slices.Contains(keep, p) { |
| + continue |
| + } |
| + keep = append(keep, p) |
| + } |
| + slices.SortFunc(keep, func(a, b netip.Prefix) int { |
| + if c := a.Addr().Compare(b.Addr()); c != 0 { |
| + return c |
| + } |
| + return a.Bits() - b.Bits() |
| + }) |
| + out := make([]string, 0, len(keep)) |
| + for _, p := range keep { |
| + if p.IsSingleIP() { |
| + out = append(out, p.Addr().String()) |
| + } else { |
| + out = append(out, p.String()) |
| + } |
| + } |
| + return out |
| } |
| // errBoxAddressesUnknown fails an edges file pass whose address source could |
| @@ -415,9 +470,11 @@ func edgesFileWrite(ctx context.Context, s release.Store, reg *registry.Registry |
| var errBoxAddressesUnknown = errors.New("edges file: the box's addresses could not be read") |
| // edgesFileWriteClaims is edgesFileWrite with the claim reader region HA |
| -// adds (edgesclaims.go). claims is nil unless CARLOS_REGION_HA is on, and |
| -// nil publishes exactly what edgesFileWrite always has. |
| -func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Registry, ident edgesFile, eip string, last *[]byte, refresh bool, claims *edgesClaims) error { |
| +// adds (edgesclaims.go) and the box-address reader. claims is nil unless |
| +// CARLOS_REGION_HA is on, and nil publishes exactly what edgesFileWrite |
| +// always has. localAddrs is read on every pass for Addrs (boxAddrs); the |
| +// loop passes instancectl.LocalAddresses, and tests their own. |
| +func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Registry, ident edgesFile, eip string, last *[]byte, refresh bool, claims *edgesClaims, localAddrs func() ([]netip.Prefix, error)) error { |
| box := ident.Box |
| routes, err := reg.List() |
| if err != nil { |
| @@ -657,6 +714,8 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re |
| f := ident |
| f.V, f.EIP, f.Hosts, f.Generation = 1, eip, hosts, "" |
| f.PrivateIP, f.PrivateCIDR = private.Private, private.PrivateCIDR |
| + // Before the gate copy, so an address change is a reason to write. |
| + f.Addrs = boxAddrs(localAddrs) |
| gateCopy := f |
| gateCopy.Headroom = nil // a changing reading is not, by itself, a reason to write |
| gate, err := json.Marshal(gateCopy) |
| @@ -896,7 +955,7 @@ func edgesFileLoop(reg *registry.Registry) { |
| ident.Headroom = headroomFor(headroomCapabilities(ident.Capabilities), dataDir, reg) |
| ident = withMovesFields(ident, dataDir, optDir) |
| ident = withSeedsFields(ident, dataDir, optDir) |
| - err = edgesFileWriteClaims(ctx, store, reg, ident, eip, &last, state.timed(), claims) |
| + err = edgesFileWriteClaims(ctx, store, reg, ident, eip, &last, state.timed(), claims, instancectl.LocalAddresses) |
| if err != nil { |
| // Throttled: a bucket that refuses every write (an IAM Deny, an |
| // outage) is retried on a backoff, and each retry must not be a |
diff --git a/internal/host/edgesfile_test.go b/internal/host/edgesfile_test.go| index 75f022545..8a828556c 100644 |
| --- a/internal/host/edgesfile_test.go |
| +++ b/internal/host/edgesfile_test.go |
| @@ -6,9 +6,12 @@ import ( |
| "crypto/ecdh" |
| "encoding/base64" |
| "encoding/json" |
| + "errors" |
| "log" |
| + "net/netip" |
| "os" |
| "path/filepath" |
| + "slices" |
| "strings" |
| "sync" |
| "testing" |
| @@ -317,7 +320,7 @@ func TestEdgesFileRawWireBodyMatchesSchema(t *testing.T) { |
| t.Fatalf("generation %q is not RFC3339: %v", probe.Generation, err) |
| } |
| - want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"generation":"` + |
| + want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"` + |
| probe.Generation + `","hosts":{"app.example.com":{"role":"home","platform":false}}}` |
| if string(got) != want { |
| t.Fatalf("raw wire body =\n%s\nwant\n%s", got, want) |
| @@ -360,7 +363,7 @@ func TestEdgesFileRawWireBodyRegionField(t *testing.T) { |
| t.Fatal(err) |
| } |
| gen := genOf(t, got) |
| - want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"generation":"` + |
| + want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"` + |
| gen + `","hosts":{"app.example.com":{"role":"home","platform":false}}}` |
| if string(got) != want { |
| t.Fatalf("raw wire body (region unset) =\n%s\nwant\n%s", got, want) |
| @@ -379,7 +382,7 @@ func TestEdgesFileRawWireBodyRegionField(t *testing.T) { |
| t.Fatal(err) |
| } |
| gen := genOf(t, got) |
| - want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","region":"eu-west-1","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"generation":"` + |
| + want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","region":"eu-west-1","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"` + |
| gen + `","hosts":{"app.example.com":{"role":"home","platform":false}}}` |
| if string(got) != want { |
| t.Fatalf("raw wire body (region set) =\n%s\nwant\n%s", got, want) |
| @@ -933,7 +936,7 @@ func TestEdgesFileRawWireBodyPlacementField(t *testing.T) { |
| if err := json.Unmarshal(got, &probe); err != nil { |
| t.Fatal(err) |
| } |
| - want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","region":"eu-west-2","placement":"uk","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"generation":"` + |
| + want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","region":"eu-west-2","placement":"uk","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"` + |
| probe.Generation + `","hosts":{"app.example.com":{"role":"home","platform":false}}}` |
| if string(got) != want { |
| t.Fatalf("raw wire body (placement set) =\n%s\nwant\n%s", got, want) |
| @@ -1587,3 +1590,218 @@ func TestEdgesFileQuietBoxStaysFreshOnTimedPassesOnlyWithRegionHA(t *testing.T) |
| t.Fatalf("region HA off: puts = %d untimed, %d after a timed pass; want 1, 1", untimed, timed) |
| } |
| } |
| + |
| +// addrsReader is a box-address reader that answers what it holds now. |
| +type addrsReader struct { |
| + mu sync.Mutex |
| + out []netip.Prefix |
| + err error |
| +} |
| + |
| +func (a *addrsReader) set(err error, prefixes ...string) { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + a.out, a.err = nil, err |
| + for _, p := range prefixes { |
| + a.out = append(a.out, netip.MustParsePrefix(p)) |
| + } |
| +} |
| + |
| +func (a *addrsReader) read() ([]netip.Prefix, error) { |
| + a.mu.Lock() |
| + defer a.mu.Unlock() |
| + return slices.Clone(a.out), a.err |
| +} |
| + |
| +// What procfs answers on a box (instancectl.LocalAddresses over a |
| +// fib_trie and if_inet6 like hardening_test.go's): loopback's range and |
| +// address, the interface address once from each routing table, and the v6 |
| +// loopback and link-local addresses. |
| +var fibTrieBox = []string{"127.0.0.0/8", "127.0.0.1/32", "10.0.1.5/32", "10.0.1.5/32", "::1/128", "fe80::1/128"} |
| + |
| +func TestBoxAddrsDropsLoopback(t *testing.T) { |
| + t.Parallel() |
| + r := &addrsReader{} |
| + r.set(nil, fibTrieBox...) |
| + if got := boxAddrs(r.read); !slices.Equal(got, []string{"10.0.1.5", "fe80::1"}) { |
| + t.Errorf("boxAddrs = %q", got) |
| + } |
| + // A wider LOCAL range is published as a prefix; the order is by address. |
| + r.set(nil, "fd00:5::20/128", "10.0.9.0/24", "127.0.0.1/32", "10.0.1.5/32") |
| + if got := boxAddrs(r.read); !slices.Equal(got, []string{"10.0.1.5", "10.0.9.0/24", "fd00:5::20"}) { |
| + t.Errorf("boxAddrs = %q", got) |
| + } |
| + // Loopback alone is nothing to publish, which is not a failed read. |
| + r.set(nil, "127.0.0.0/8", "127.0.0.1/32", "::1/128") |
| + if got := boxAddrs(r.read); got == nil || len(got) != 0 { |
| + t.Errorf("loopback only: boxAddrs = %#v, want an empty list", got) |
| + } |
| + r.set(errors.New("no fib_trie")) |
| + if got := boxAddrs(r.read); got != nil { |
| + t.Errorf("failed read: boxAddrs = %#v, want nil", got) |
| + } |
| + if got := boxAddrs(nil); got != nil { |
| + t.Errorf("no reader: boxAddrs = %#v, want nil", got) |
| + } |
| +} |
| + |
| +// addrs is part of the change gate: the same routes with a different |
| +// address list write the file again, the same list writes nothing, and a |
| +// restart's seeded gate carries the list through. |
| +func TestEdgesFileAddrsInTheGate(t *testing.T) { |
| + t.Parallel() |
| + ctx := context.Background() |
| + st := &putCountingStore{Store: release.NewDirStore(t.TempDir())} |
| + reg := edgesTestRegistry(t) |
| + seedRoute(t, reg, "app.example.com") |
| + r := &addrsReader{} |
| + r.set(nil, fibTrieBox...) |
| + ident := edgesFile{Box: "annie"} |
| + var last []byte |
| + for i := 0; i < 2; i++ { |
| + if err := edgesFileWriteClaims(ctx, st, reg, ident, "1.2.3.4", &last, true, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if st.puts != 1 { |
| + t.Fatalf("puts = %d, want 1: an unchanged address list is not a reason to write", st.puts) |
| + } |
| + r.set(nil, "10.0.1.6/32") |
| + if err := edgesFileWriteClaims(ctx, st, reg, ident, "1.2.3.4", &last, false, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.puts != 2 { |
| + t.Fatalf("puts = %d, want 2: a changed address list must be published", st.puts) |
| + } |
| + if f := readEdgesFile(t, st, "annie"); !slices.Equal(f.Addrs, []string{"10.0.1.6"}) { |
| + t.Fatalf("published addrs = %q", f.Addrs) |
| + } |
| + // A restart with the same addresses writes nothing, an empty list |
| + // included. |
| + for _, addrs := range [][]string{{"10.0.1.6/32"}, {"127.0.0.1/32"}} { |
| + r.set(nil, addrs...) |
| + if err := edgesFileWriteClaims(ctx, st, reg, ident, "1.2.3.4", &last, false, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + puts := st.puts |
| + seeded := seedEdgesFileGate(ctx, st, "annie") |
| + if err := edgesFileWriteClaims(ctx, st, reg, ident, "1.2.3.4", &seeded, false, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + if st.puts != puts { |
| + t.Fatalf("%v: a restart rewrote an unchanged file", addrs) |
| + } |
| + } |
| +} |
| + |
| +// Review Focus 5: a box with no non-loopback address publishes "addrs":[], |
| +// and a box whose procfs read fails publishes "addrs":null, which the |
| +// console's reader takes as lacking. |
| +func TestEdgesFileAddrsEmptyAndUnreadable(t *testing.T) { |
| + t.Parallel() |
| + ctx := context.Background() |
| + reg := edgesTestRegistry(t) |
| + seedRoute(t, reg, "app.example.com") |
| + s := release.NewDirStore(t.TempDir()) |
| + write := func(box string, r *addrsReader) string { |
| + t.Helper() |
| + var last []byte |
| + if err := edgesFileWriteClaims(ctx, s, reg, edgesFile{Box: box}, "203.0.113.10", &last, false, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + body, _, err := s.Get(ctx, edgesFileKey(box)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var probe struct { |
| + Generation string `json:"generation"` |
| + } |
| + if err := json.Unmarshal(body, &probe); err != nil { |
| + t.Fatal(err) |
| + } |
| + return strings.Replace(string(body), probe.Generation, "GEN", 1) |
| + } |
| + const head = `{"v":1,"box":"%s","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,` |
| + const tail = `,"generation":"GEN","hosts":{"app.example.com":{"role":"home","platform":false}}}` |
| + |
| + r := &addrsReader{} |
| + r.set(nil, "127.0.0.0/8", "127.0.0.1/32", "::1/128") |
| + if got, want := write("annie", r), strings.Replace(head, "%s", "annie", 1)+`"addrs":[]`+tail; got != want { |
| + t.Errorf("no non-loopback address:\n%s\nwant\n%s", got, want) |
| + } |
| + r.set(errors.New("open /proc/net/fib_trie: permission denied")) |
| + if got, want := write("betty", r), strings.Replace(head, "%s", "betty", 1)+`"addrs":null`+tail; got != want { |
| + t.Errorf("failed read:\n%s\nwant\n%s", got, want) |
| + } |
| + r.set(nil, fibTrieBox...) |
| + if got, want := write("carla", r), strings.Replace(head, "%s", "carla", 1)+`"addrs":["10.0.1.5","fe80::1"]`+tail; got != want { |
| + t.Errorf("addresses:\n%s\nwant\n%s", got, want) |
| + } |
| + |
| + // The console's reader: an empty list is a box with nothing to |
| + // publish, null is a box lacking. |
| + inv, err := edgesfile.ReadAddrs(ctx, s) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if got, ok := inv.Boxes["annie"]; !ok || len(got) != 0 { |
| + t.Errorf("annie = %v, %v; want present and empty", got, ok) |
| + } |
| + if !slices.Equal(inv.Missing, []string{"betty"}) || len(inv.Unreadable) != 0 { |
| + t.Errorf("Missing = %v, Unreadable = %v", inv.Missing, inv.Unreadable) |
| + } |
| + if h, ok := inv.Holder(netip.MustParseAddr("fe80::1")); !ok || h != "carla" { |
| + t.Errorf("Holder(fe80::1) = %q, %v", h, ok) |
| + } |
| +} |
| + |
| +// The box-side request budget (spec §3a): a day of the loop's passes |
| +// (288, one per five minutes) with the routes and the addresses unchanged |
| +// makes exactly the requests the same passes make with no addresses |
| +// published at all, with or without headroom. A changed address adds one |
| +// write: putReplacing's read of the ETag and its Put. |
| +func TestEdgesFileAddrsAddNoRequests(t *testing.T) { |
| + t.Parallel() |
| + ctx := context.Background() |
| + reg := edgesTestRegistry(t) |
| + seedRoute(t, reg, "app.example.com") |
| + day := func(ident edgesFile, read func() ([]netip.Prefix, error)) []string { |
| + st := &egressCountingStore{Store: release.NewDirStore(t.TempDir())} |
| + var last []byte |
| + for i := 0; i < 288; i++ { |
| + if err := edgesFileWriteClaims(ctx, st, reg, ident, "1.2.3.4", &last, i%2 == 0, nil, read); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + return slices.Clone(st.seen) |
| + } |
| + r := &addrsReader{} |
| + r.set(nil, fibTrieBox...) |
| + for _, ident := range []edgesFile{ |
| + {Box: "annie"}, |
| + {Box: "annie", Capabilities: []string{capRegionHA1}, Headroom: &edgeHeadroom{MemFreeMiB: 100, MemTotalMiB: 1000}}, |
| + } { |
| + without, with := day(ident, nil), day(ident, r.read) |
| + if !slices.Equal(with, without) { |
| + t.Errorf("headroom %v: with addrs %d requests %v, without %d %v", ident.Headroom != nil, len(with), with, len(without), without) |
| + } |
| + } |
| + |
| + st := &egressCountingStore{Store: release.NewDirStore(t.TempDir())} |
| + var last []byte |
| + pass := func() { |
| + t.Helper() |
| + if err := edgesFileWriteClaims(ctx, st, reg, edgesFile{Box: "annie"}, "1.2.3.4", &last, false, nil, r.read); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + pass() |
| + before := st.total() |
| + pass() |
| + r.set(nil, "10.0.1.6/32") |
| + pass() |
| + pass() |
| + if got, want := st.seen[before:], []string{"GET " + edgesFileKey("annie"), "PUT " + edgesFileKey("annie")}; !slices.Equal(got, want) { |
| + t.Errorf("a changed address made %v, want %v", got, want) |
| + } |
| +} |