carlos / platform Public

edge: signed probe-burst notices between platform edges

A trip on one edge now queues a notice to every other platform edge whose
edges file says burst_notices, and that edge applies the same cool-down.
Notices are HMAC-signed under the mesh key in their own domain
(carlos-burst-notice), bound to the receiving box and body, timestamped
within hopSkew, and verified under either mirrored key. The receiver
intercepts POST /.carlos/burst-notice with X-Carlos-Burst-Auth after
acceptHop, reads at most 512 bytes within 2 s, and answers 204 or 404.

Each peer has its own queue (64) and goroutine; the box-wide budget of
120 messages in any 60 s is taken at dispatch, immediately before
transmitting; a notice that cannot be sent within 10 s of its trip, or
past its expiry, is dropped and counted. Receivers apply at most 600 a
minute. The host's edges-file pass writes burst_notices: true.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 5b91ae3553e96364d757bbe648e722abfbbe30ba parent d6e9168
10 files changed, +1,399 −16
  • internal/edge/burst_notice.go +542 −0
  • internal/edge/burst_notice_test.go +742 −0
  • internal/edge/edge.go +12 −1
  • internal/edge/guard.go +0 −6
  • internal/edge/homemap.go +4 −0
  • internal/edge/mesh.go +56 −0
  • internal/edge/testdata/edges-forward-hub.json +1 −1
  • internal/host/edgesfile.go +8 −0
  • internal/host/edgesfile_test.go +28 −5
  • internal/host/egress_nopolicy_linux_test.go +6 −3
diff --git a/internal/edge/burst_notice.go b/internal/edge/burst_notice.go
new file mode 100644
index 000000000..c57d3a611
--- /dev/null
+++ b/internal/edge/burst_notice.go
@@ -0,0 +1,542 @@
+package edge
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "log"
+ "net/http"
+ "net/netip"
+ "net/url"
+ "slices"
+ "strings"
+ "sync"
+ "time"
+
+ "github.com/carlosframework/platform/internal/edgesfile"
+)
+
+// Probe-burst notices between platform edges (probe-burst spec §4, #491).
+// When a client trips here, every other platform edge is told, and applies
+// the same cool-down ending at the same moment.
+//
+// Only boxes holding the deployment's mesh key send or accept a notice, so a
+// fleet box (which never gets the key) does neither. A notice goes only to a
+// box whose edges file says burst_notices: an older box has no interceptor,
+// and the notice path would reach a tenant's app there.
+//
+// Sending never blocks serving. A trip puts one notice on each peer's own
+// bounded queue, and each peer has its own goroutine, so a slow peer delays
+// nobody else. The box-wide budget is taken once per message, by the peer's
+// goroutine, immediately before it transmits: at most 120 in any 60 seconds,
+// so the cap holds however the trips and the queues line up. A notice that
+// cannot be sent within 10 seconds of its trip is dropped, since the scanner
+// will trip the other box by itself if it gets there. Every drop is counted.
+const (
+ burstNoticePath = "/.carlos/burst-notice"
+ burstNoticeAuthHeader = "X-Carlos-Burst-Auth"
+ // burstNoticeMaxBody bounds a notice's body; a real one is under 200
+ // bytes.
+ burstNoticeMaxBody = 512
+ // burstNoticeQueue is each peer's queue length.
+ burstNoticeQueue = 64
+ // burstNoticeMaxAge is how long after its trip a notice may still be
+ // sent.
+ burstNoticeMaxAge = 10 * time.Second
+ // The two caps, each over any burstWindow (60 s): notices this box
+ // transmits, and notices it applies from the other edges.
+ burstNoticeSendPerMinute = 120
+ burstNoticeAcceptPerMinute = 600
+ // burstNoticeSendTimeout bounds one send from dial to the end of the
+ // answer.
+ burstNoticeSendTimeout = 3 * time.Second
+ // burstNoticeReadTimeout bounds reading a received notice's body.
+ burstNoticeReadTimeout = 2 * time.Second
+ // burstNoticeIdle is how long a peer's goroutine waits with nothing to
+ // send before it ends; the next notice for that peer starts another.
+ burstNoticeIdle = 10 * time.Minute
+ // burstNoticeMaxWait is the longest a peer's goroutine sleeps between
+ // looks at the budget.
+ burstNoticeMaxWait = time.Second
+)
+
+// burstNoticeWire is a notice's JSON body.
+type burstNoticeWire struct {
+ Client string `json:"client"`
+ Until int64 `json:"until"`
+ From string `json:"from"`
+ Ref string `json:"ref"`
+}
+
+// burstNoticeStats counts what happened to every notice sent and received.
+// Transmitted is Sent plus Failed; every other sending count is a notice
+// dropped unsent.
+type burstNoticeStats struct {
+ Sent int64 // answered 204
+ Failed int64 // transmitted, and not answered 204 within the timeout
+ Overflow int64 // the peer's queue was full
+ OverBudget int64 // no slot in the budget within 10 s of the trip
+ Stale int64 // more than 10 s old, or past its expiry, before a slot
+ Gone int64 // the peer left the edges files with it still queued
+
+ Accepted int64
+ RefusedNoKey int64 // no mesh key or no box name to check against
+ RefusedBody int64 // too big, too slow or unreadable
+ RefusedAuth int64 // bad, stale or another box's signature
+ RefusedNotice int64 // malformed, or the client not a canonical /32 or /64
+ RefusedUntil int64 // expiry passed or more than a cool-down ahead
+ RefusedCap int64 // over burstNoticeAcceptPerMinute
+}
+
+// burstTarget is one peer as its edges file publishes it: where to dial and
+// the host its certificate is fetched for.
+type burstTarget struct {
+ box, dial, host string
+}
+
+type burstNotice struct {
+ burstTarget
+ body []byte
+ trip, until time.Time
+}
+
+// burstPeer is one peer's queue and the goroutine draining it.
+type burstPeer struct {
+ box string
+ q chan burstNotice
+ stop chan struct{}
+}
+
+type burstNotices struct {
+ budget burstWindowCap
+ accept burstWindowCap
+
+ mu sync.Mutex
+ peers map[string]*burstPeer
+ // targets is the peer list worked out from targetsFrom, an immutable
+ // home-map snapshot, so a run of trips reads the edges files once.
+ targetsFrom *homeSnapshot
+ targetsSelf string
+ targetsPrivate bool
+ targets []burstTarget
+
+ statMu sync.Mutex
+ st burstNoticeStats
+}
+
+func newBurstNotices() *burstNotices {
+ return &burstNotices{
+ budget: burstWindowCap{n: burstNoticeSendPerMinute},
+ accept: burstWindowCap{n: burstNoticeAcceptPerMinute},
+ peers: make(map[string]*burstPeer),
+ }
+}
+
+func (n *burstNotices) stats() burstNoticeStats {
+ n.statMu.Lock()
+ defer n.statMu.Unlock()
+ return n.st
+}
+
+func (n *burstNotices) count(f func(*burstNoticeStats)) {
+ n.statMu.Lock()
+ f(&n.st)
+ n.statMu.Unlock()
+}
+
+// burstWindowCap admits at most n events in any burstWindow. It keeps the
+// times of the last n admissions in a ring, so a slot frees exactly 60 s
+// after the admission that took it, never at a calendar minute.
+type burstWindowCap struct {
+ n int
+ mu sync.Mutex
+ at []int64 // unix nanos, oldest at head once full
+ head int
+}
+
+// take admits one event if the window has room, reading the clock under
+// the lock so the ring stays in time order. When it has none, next is when
+// the oldest admission leaves the window.
+func (c *burstWindowCap) take(clock func() time.Time) (ok bool, now, next time.Time) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ now = clock()
+ t := now.UnixNano()
+ if len(c.at) < c.n {
+ c.at = append(c.at, t)
+ return true, now, time.Time{}
+ }
+ if oldest := c.at[c.head]; t-oldest < int64(burstWindow) {
+ return false, now, time.Unix(0, oldest).Add(burstWindow)
+ }
+ c.at[c.head] = t
+ c.head = (c.head + 1) % c.n
+ return true, now, time.Time{}
+}
+
+// burstNow is the probe-burst clock: the limiter's, so a notice's age, its
+// expiry and its signature's timestamp are read on the clock that set them.
+func (e *Edge) burstNow() time.Time {
+ if e.burst != nil {
+ return e.burst.now()
+ }
+ return time.Now()
+}
+
+// sendBurstNotices tells the platform's other edges that client tripped
+// here, so they apply the same cool-down. It queues one notice per peer
+// and returns; it never waits on the network.
+func (e *Edge) sendBurstNotices(client netip.Prefix, until time.Time, ref string) {
+ n, m := e.notices, e.homes.Load()
+ if n == nil || m == nil || e.box == "" {
+ return
+ }
+ if current, next := m.meshKeys(); len(current) == 0 && len(next) == 0 {
+ return
+ }
+ body, err := json.Marshal(burstNoticeWire{Client: client.String(), Until: until.Unix(), From: e.box, Ref: ref})
+ if err != nil || len(body) > burstNoticeMaxBody {
+ e.logThrottled("burst-notice-too-big", fmt.Sprintf("probe-burst notice for %s not sent: its body is over %d bytes", client, burstNoticeMaxBody))
+ return
+ }
+ trip := e.burstNow()
+ n.mu.Lock()
+ defer n.mu.Unlock()
+ targets := n.targetsLocked(m.snapshot(), e.box, m.privateDial)
+ n.pruneLocked(targets)
+ for _, t := range targets {
+ p := n.peers[t.box]
+ if p == nil {
+ p = &burstPeer{box: t.box, q: make(chan burstNotice, burstNoticeQueue), stop: make(chan struct{})}
+ n.peers[t.box] = p
+ go e.runBurstPeer(n, p)
+ }
+ select {
+ case p.q <- burstNotice{burstTarget: t, body: body, trip: trip, until: until}:
+ default:
+ n.count(func(s *burstNoticeStats) { s.Overflow++ })
+ e.logThrottled("burst-notice-overflow", fmt.Sprintf("probe-burst notice to %s dropped: its queue of %d is full", t.box, burstNoticeQueue))
+ }
+ }
+}
+
+// targetsLocked is the peer list for snap, worked out again only when the
+// snapshot changes. Caller holds n.mu.
+func (n *burstNotices) targetsLocked(snap *homeSnapshot, self string, privateDial bool) []burstTarget {
+ if snap != n.targetsFrom || self != n.targetsSelf || privateDial != n.targetsPrivate {
+ n.targets = burstTargets(snap.files, self, privateDial)
+ n.targetsFrom, n.targetsSelf, n.targetsPrivate = snap, self, privateDial
+ }
+ return n.targets
+}
+
+// pruneLocked stops the goroutine of every peer no longer in targets: a box
+// that left the edges files, stopped advertising notices or lost its dial
+// address. Caller holds n.mu.
+func (n *burstNotices) pruneLocked(targets []burstTarget) {
+ for box, p := range n.peers {
+ if !slices.ContainsFunc(targets, func(t burstTarget) bool { return t.box == box }) {
+ close(p.stop)
+ delete(n.peers, box)
+ }
+ }
+}
+
+// burstTargets lists the boxes a notice goes to: every edges file but this
+// box's own that says burst_notices, has a dial address and names a host
+// to ask for. The dial is foldHomes', through edgesfile.Reader.Dial with
+// this box's own file, so a same-region peer is dialled where a hop would
+// be. In sorted key order, so every edge works through its peers alike.
+func burstTargets(files map[string]edgesFileView, self string, privateDial bool) []burstTarget {
+ keys := make([]string, 0, len(files))
+ for k := range files {
+ keys = append(keys, k)
+ }
+ slices.Sort(keys)
+ var own edgesFileView
+ ownKnown := false
+ for _, k := range keys {
+ if f := files[k]; f.Box == self {
+ own, ownKnown = f, true
+ }
+ }
+ reader := edgesfile.Reader{Box: self, Self: own.dialPoint(), SelfKnown: ownKnown, PrivateDial: privateDial}
+ var out []burstTarget
+ for _, k := range keys {
+ f := files[k]
+ if f.Box == "" || f.Box == self || !f.BurstNotices {
+ continue
+ }
+ if slices.ContainsFunc(out, func(t burstTarget) bool { return t.box == f.Box }) {
+ continue
+ }
+ dial := reader.Dial(f.dialPoint())
+ host := burstNoticeHost(f.Hosts)
+ if dial == "" || host == "" {
+ continue
+ }
+ out = append(out, burstTarget{box: f.Box, dial: dial, host: host})
+ }
+ return out
+}
+
+// burstNoticeHost is the host a notice to a peer is addressed to: the
+// lowest of the names its file publishes that is not a wildcard, so the
+// peer holds a certificate for it.
+func burstNoticeHost(hosts map[string]edgesHostView) string {
+ best := ""
+ for h := range hosts {
+ if h == "" || strings.Contains(h, "*") {
+ continue
+ }
+ if best == "" || h < best {
+ best = h
+ }
+ }
+ return best
+}
+
+// runBurstPeer drains one peer's queue, one notice at a time, until the
+// peer is pruned or has had nothing to send for burstNoticeIdle.
+func (e *Edge) runBurstPeer(n *burstNotices, p *burstPeer) {
+ idle := time.NewTimer(burstNoticeIdle)
+ defer idle.Stop()
+ for {
+ select {
+ case <-p.stop:
+ // Nothing is queued after stop closes: both happen under n.mu.
+ if left := len(p.q); left > 0 {
+ n.count(func(s *burstNoticeStats) { s.Gone += int64(left) })
+ e.logThrottled("burst-notice-gone", fmt.Sprintf("%d probe-burst notice(s) to %s dropped: the box left the edges files", left, p.box))
+ }
+ return
+ case nt := <-p.q:
+ e.dispatchBurstNotice(n, p, nt)
+ idle.Reset(burstNoticeIdle)
+ case <-idle.C:
+ if n.retire(p) {
+ return
+ }
+ idle.Reset(burstNoticeIdle)
+ }
+ }
+}
+
+// retire removes an idle peer, unless a notice arrived for it meanwhile.
+func (n *burstNotices) retire(p *burstPeer) bool {
+ n.mu.Lock()
+ defer n.mu.Unlock()
+ if len(p.q) > 0 {
+ return false
+ }
+ if n.peers[p.box] == p {
+ delete(n.peers, p.box)
+ }
+ return true
+}
+
+// dispatchBurstNotice waits for a slot in the budget, then signs and sends
+// one notice. A notice that is too old, past its expiry, or cannot get a
+// slot within burstNoticeMaxAge of its trip is dropped unsent. There is no
+// retry.
+func (e *Edge) dispatchBurstNotice(n *burstNotices, p *burstPeer, nt burstNotice) {
+ var at time.Time
+ for {
+ now := e.burstNow()
+ if now.Sub(nt.trip) > burstNoticeMaxAge || !nt.until.After(now) {
+ n.count(func(s *burstNoticeStats) { s.Stale++ })
+ e.logThrottled("burst-notice-stale", fmt.Sprintf("probe-burst notice to %s dropped unsent: more than %v old or past its expiry", nt.box, burstNoticeMaxAge))
+ return
+ }
+ ok, took, next := n.budget.take(e.burstNow)
+ if ok {
+ at = took
+ break
+ }
+ if next.Sub(nt.trip) > burstNoticeMaxAge {
+ n.count(func(s *burstNoticeStats) { s.OverBudget++ })
+ e.logThrottled("burst-notice-budget", fmt.Sprintf("probe-burst notice to %s kept local: this box has sent %d notices in the last minute", nt.box, burstNoticeSendPerMinute))
+ return
+ }
+ wait := time.NewTimer(min(next.Sub(now), burstNoticeMaxWait))
+ select {
+ case <-p.stop:
+ wait.Stop()
+ n.count(func(s *burstNoticeStats) { s.Gone++ })
+ return
+ case <-wait.C:
+ }
+ }
+ if err := e.transmitBurstNotice(nt, at); err != nil {
+ n.count(func(s *burstNoticeStats) { s.Failed++ })
+ e.logThrottled("burst-notice-failed", fmt.Sprintf("probe-burst notice to %s (%s) failed: %v", nt.box, nt.dial, err))
+ return
+ }
+ n.count(func(s *burstNoticeStats) { s.Sent++ })
+}
+
+// transmitBurstNotice signs nt now, under the key current at dispatch, and
+// sends it to the peer's front door over the backhaul transport, so it is
+// verified against the certificate the peer serves for nt.host.
+func (e *Edge) transmitBurstNotice(nt burstNotice, now time.Time) error {
+ current, next := e.homes.Load().meshKeys()
+ key := signingKey(current, next)
+ if len(key) == 0 {
+ return fmt.Errorf("no mesh key to sign with")
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), burstNoticeSendTimeout)
+ defer cancel()
+ u := url.URL{Scheme: "https", Host: nt.host, Path: burstNoticePath}
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, u.String(), bytes.NewReader(nt.body))
+ if err != nil {
+ return err
+ }
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Set(burstNoticeAuthHeader, signBurstNotice(key, nt.box, now, nt.body))
+ resp, err := e.backhaulTransport(nt.dial).RoundTrip(req)
+ if err != nil {
+ return err
+ }
+ io.Copy(io.Discard, io.LimitReader(resp.Body, 4<<10))
+ resp.Body.Close()
+ if resp.StatusCode != http.StatusNoContent {
+ return fmt.Errorf("answered %d", resp.StatusCode)
+ }
+ return nil
+}
+
+// Refusal reasons, the fixed set the refusal log keys are built from.
+const (
+ burstRefusedNoKey = "no-key"
+ burstRefusedBody = "body"
+ burstRefusedAuth = "auth"
+ burstRefusedNotice = "notice"
+ burstRefusedUntil = "until"
+ burstRefusedCap = "cap"
+)
+
+// serveBurstNotice answers a notice from another edge, and reports whether
+// r was one: a POST to burstNoticePath carrying burstNoticeAuthHeader.
+// Anything else is left for the app, the path without the header included.
+// A notice is answered 204 when it applied and 404 when it was refused for
+// any reason, so a refusal says no more than a missing page does. It is
+// never passed on and never re-sent. An applied notice is one line in the
+// box's own log, at most burstNoticeAcceptPerMinute a minute, and never in a
+// tenant's records.
+func (e *Edge) serveBurstNotice(w http.ResponseWriter, r *http.Request) bool {
+ if r.Method != http.MethodPost || r.URL.Path != burstNoticePath {
+ return false
+ }
+ auth := r.Header.Values(burstNoticeAuthHeader)
+ if len(auth) == 0 {
+ return false
+ }
+ n := e.notices
+ current, next := e.homes.Load().meshKeys()
+ if n == nil || e.burst == nil || e.box == "" || (len(current) == 0 && len(next) == 0) {
+ e.refuseBurstNotice(w, r, burstRefusedNoKey)
+ return true
+ }
+ // Bounded in time as well as size, as the login body is (edge.go): a
+ // sender that stalls its body must not hold the connection. On a failed
+ // read the deadline is left where it is, past for a stall, and the
+ // connection is closed after the answer.
+ rc := http.NewResponseController(w)
+ bounded := rc.SetReadDeadline(time.Now().Add(burstNoticeReadTimeout)) == nil
+ body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, burstNoticeMaxBody))
+ if err != nil {
+ w.Header().Set("Connection", "close")
+ e.refuseBurstNotice(w, r, burstRefusedBody)
+ return true
+ }
+ if bounded {
+ rc.SetReadDeadline(time.Time{})
+ }
+ now := e.burstNow()
+ if len(auth) != 1 || !verifyBurstNoticeEitherKey(current, next, e.box, auth[0], body, now) {
+ e.refuseBurstNotice(w, r, burstRefusedAuth)
+ return true
+ }
+ var msg burstNoticeWire
+ if err := json.Unmarshal(body, &msg); err != nil {
+ e.refuseBurstNotice(w, r, burstRefusedNotice)
+ return true
+ }
+ client, ok := burstNoticeClient(msg.Client)
+ if !ok {
+ e.refuseBurstNotice(w, r, burstRefusedNotice)
+ return true
+ }
+ until := time.Unix(msg.Until, 0)
+ if !until.After(now) || until.After(now.Add(burstCooldown)) {
+ e.refuseBurstNotice(w, r, burstRefusedUntil)
+ return true
+ }
+ if ok, _, _ := n.accept.take(e.burstNow); !ok {
+ e.refuseBurstNotice(w, r, burstRefusedCap)
+ return true
+ }
+ if !e.burst.apply(client, until) {
+ // The clock moved past a bound between the check above and here.
+ e.refuseBurstNotice(w, r, burstRefusedUntil)
+ return true
+ }
+ n.count(func(s *burstNoticeStats) { s.Accepted++ })
+ log.Printf("edge: probe-burst notice from %q applied: client %s cooling until %s (ref %q)", msg.From, client, until.UTC().Format(time.RFC3339), msg.Ref)
+ w.WriteHeader(http.StatusNoContent)
+ return true
+}
+
+// refuseBurstNotice counts a refusal by reason, logs it throttled under a
+// key built from that fixed reason only, and answers 404 with no body.
+func (e *Edge) refuseBurstNotice(w http.ResponseWriter, r *http.Request, reason string) {
+ if n := e.notices; n != nil {
+ n.count(func(s *burstNoticeStats) {
+ switch reason {
+ case burstRefusedNoKey:
+ s.RefusedNoKey++
+ case burstRefusedBody:
+ s.RefusedBody++
+ case burstRefusedAuth:
+ s.RefusedAuth++
+ case burstRefusedNotice:
+ s.RefusedNotice++
+ case burstRefusedUntil:
+ s.RefusedUntil++
+ case burstRefusedCap:
+ s.RefusedCap++
+ }
+ })
+ }
+ e.logThrottled("burst-notice-refused "+reason, fmt.Sprintf("probe-burst notice from %s refused (%s)", r.RemoteAddr, reason))
+ w.WriteHeader(http.StatusNotFound)
+}
+
+// burstNoticeClient parses a notice's client key, accepting only the form
+// ratelimit.ClientKey makes: an IPv4 /32 or an IPv6 /64, masked, in its
+// canonical text. Anything wider would let one notice cool a whole network.
+func burstNoticeClient(s string) (netip.Prefix, bool) {
+ p, err := netip.ParsePrefix(s)
+ if err != nil {
+ return netip.Prefix{}, false
+ }
+ a := p.Addr()
+ switch {
+ case a.Is4():
+ if p.Bits() != 32 {
+ return netip.Prefix{}, false
+ }
+ case a.Is6() && !a.Is4In6():
+ if p.Bits() != 64 {
+ return netip.Prefix{}, false
+ }
+ default:
+ return netip.Prefix{}, false
+ }
+ if p != p.Masked() || p.String() != s {
+ return netip.Prefix{}, false
+ }
+ return p, true
+}
diff --git a/internal/edge/burst_notice_test.go b/internal/edge/burst_notice_test.go
new file mode 100644
index 000000000..925d0b71e
--- /dev/null
+++ b/internal/edge/burst_notice_test.go
@@ -0,0 +1,742 @@
+package edge
+
+import (
+ "bufio"
+ "context"
+ "crypto/rand"
+ "crypto/tls"
+ "errors"
+ "fmt"
+ "io"
+ "net"
+ "net/http"
+ "net/http/httptest"
+ "net/netip"
+ "slices"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "testing"
+ "time"
+
+ "golang.org/x/crypto/acme/autocert"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/reqrec"
+)
+
+// Probe-burst notices between edges (probe-burst plan Task 4, spec §4).
+// Every box here is a real Edge behind a real TLS listener, each on its own
+// loopback address and all on one port (backhaulPort), over one bucket that
+// carries the mesh key, the certificates and every box's edges file, as
+// boxes do. Every edge's limiter, and so every notice's clock, is one
+// hand-driven clock, so ages, budgets and expiries are exact.
+
+// noticeFile is one box's edges file in a scene.
+type noticeFile struct {
+ box, ip, host string
+ // advertise is the burst_notices flag the file carries.
+ advertise bool
+}
+
+// noticeEdge is one box of a noticeScene.
+type noticeEdge struct {
+ be *backhaulEdge
+ file *noticeFile
+ rec *lockedRecorder
+ // at is the scene clock at each request for burstNoticePath that
+ // reached this box's 443.
+ mu sync.Mutex
+ at []time.Time
+ // appNotice counts the requests for burstNoticePath this box's app saw.
+ appNotice atomic.Int64
+}
+
+func (x *noticeEdge) edge() *Edge { return x.be.live.Load().edge }
+
+func (x *noticeEdge) arrivals() []time.Time {
+ x.mu.Lock()
+ defer x.mu.Unlock()
+ return slices.Clone(x.at)
+}
+
+type noticeScene struct {
+ bucket string
+ seed release.Store
+ ca *e2eCA
+ clock *burstClock
+ port string
+ files []*noticeFile
+ boxes []*noticeEdge
+ key []byte
+}
+
+// newNoticeScene is an empty deployment in block mode, holding a mesh key
+// when key is set.
+func newNoticeScene(t *testing.T, key bool) *noticeScene {
+ t.Helper()
+ e2eQuietLogs(t)
+ t.Setenv("CARLOS_EDGE_PROTECT", "block")
+ s := &noticeScene{bucket: t.TempDir(), ca: newE2ECA(t), clock: newBurstClock()}
+ s.seed = release.NewDirStore(s.bucket)
+ if key {
+ if err := MintMeshKey(context.Background(), s.seed); err != nil {
+ t.Fatal(err)
+ }
+ }
+ return s
+}
+
+// listen opens ip on the scene's one port, choosing it on the first call
+// and pointing the backhaul dial and its trust there.
+func (s *noticeScene) listen(t *testing.T, ip string) net.Listener {
+ t.Helper()
+ port := s.port
+ if port == "" {
+ port = "0"
+ }
+ ln, err := net.Listen("tcp", net.JoinHostPort(ip, port))
+ if err != nil && s.port == "" {
+ // A platform that holds only 127.0.0.1 (macOS by default).
+ t.Skipf("no loopback address %s to listen on: %v", ip, err)
+ }
+ if err != nil {
+ t.Fatalf("listen on %s:%s: %v", ip, port, err)
+ }
+ if s.port == "" {
+ _, s.port, _ = net.SplitHostPort(ln.Addr().String())
+ oldPort, oldCAs := backhaulPort, backhaulRootCAs
+ backhaulPort, backhaulRootCAs = s.port, s.ca.pool
+ t.Cleanup(func() { backhaulPort, backhaulRootCAs = oldPort, oldCAs })
+ }
+ return ln
+}
+
+// add boots a box serving host (acct/app) from an app that answers 404 to
+// everything, behind its own TLS listener on ip.
+func (s *noticeScene) add(t *testing.T, box, ip, host, acct, app string, advertise bool) *noticeEdge {
+ t.Helper()
+ x := &noticeEdge{file: &noticeFile{box: box, ip: ip, host: host, advertise: advertise}, rec: &lockedRecorder{}}
+ backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == burstNoticePath {
+ x.appNotice.Add(1)
+ }
+ w.WriteHeader(http.StatusNotFound)
+ io.WriteString(w, "the app's own 404")
+ }))
+ t.Cleanup(backend.Close)
+ be := &backhaulEdge{store: release.NewDirStore(s.bucket), reg: openReg(t), box: box}
+ if err := be.reg.Upsert(registry.Route{Host: host, Kind: "service", Addr: backend.Listener.Addr().String(),
+ Status: "ready", Account: acct, App: app}); err != nil {
+ t.Fatal(err)
+ }
+ be.local = autocert.DirCache(t.TempDir())
+ tlsCfg := be.boot(t)
+ be.edge.burst = newBurstLimiter(s.clock.now)
+ be.edge.EnableRequestRecords(x.rec)
+ t.Cleanup(be.edge.notices.stopAll)
+ x.be = be
+
+ srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path == burstNoticePath {
+ x.mu.Lock()
+ x.at = append(x.at, s.clock.now())
+ x.mu.Unlock()
+ }
+ be.live.Load().edge.ServeHTTP(w, r)
+ }))
+ srv.Listener.Close()
+ srv.Listener = s.listen(t, ip)
+ srv.TLS = tlsCfg
+ srv.StartTLS()
+ t.Cleanup(srv.Close)
+ s.ca.publish(t, s.seed, host)
+ s.files = append(s.files, x.file)
+ s.boxes = append(s.boxes, x)
+ return x
+}
+
+// addStalled is a box that accepts connections on ip and never answers.
+func (s *noticeScene) addStalled(t *testing.T, box, ip, host string) {
+ t.Helper()
+ ln := s.listen(t, ip)
+ var mu sync.Mutex
+ var held []net.Conn
+ go func() {
+ for {
+ c, err := ln.Accept()
+ if err != nil {
+ return
+ }
+ mu.Lock()
+ held = append(held, c)
+ mu.Unlock()
+ }
+ }()
+ t.Cleanup(func() {
+ ln.Close()
+ mu.Lock()
+ defer mu.Unlock()
+ for _, c := range held {
+ c.Close()
+ }
+ })
+ s.files = append(s.files, &noticeFile{box: box, ip: ip, host: host, advertise: true})
+}
+
+// publish writes every box's edges file and brings every edge's mirror
+// and home map up to date.
+func (s *noticeScene) publish(t *testing.T) {
+ t.Helper()
+ for _, f := range s.files {
+ flag := ""
+ if f.advertise {
+ flag = `"burst_notices":true,`
+ }
+ putJSON(t, s.seed, "control/edges/"+f.box+".json", fmt.Sprintf(
+ `{"v":1,"box":%q,"eip":%q,%s"hosts":{%q:{"role":"home"}}}`, f.box, f.ip, flag, f.host))
+ }
+ for _, x := range s.boxes {
+ if err := x.be.mirror.Refresh(context.Background()); err != nil {
+ t.Fatal(err)
+ }
+ refreshHomeMap(t, x.be.homes)
+ }
+ s.key, _ = s.boxes[0].be.homes.meshKeys()
+}
+
+// noticeClient is the i'th scanner address.
+func noticeClient(i int) string {
+ return fmt.Sprintf("198.18.%d.%d", i/250, i%250+1)
+}
+
+func noticePrefix(t *testing.T, ip string) netip.Prefix {
+ t.Helper()
+ return netip.MustParsePrefix(ip + "/32")
+}
+
+// trip has client ask x's app for burstThreshold missing catalogue paths,
+// which trips it on x.
+func (s *noticeScene) trip(t *testing.T, x *noticeEdge, client string) {
+ t.Helper()
+ for i := range burstThreshold {
+ r := httptest.NewRequest(http.MethodGet, "http://"+x.file.host+scanPath(i), nil)
+ r.RemoteAddr = net.JoinHostPort(client, "40000")
+ x.edge().ServeHTTP(httptest.NewRecorder(), r)
+ }
+ if _, _, ok := x.edge().burst.cooling(noticePrefix(t, client)); !ok {
+ t.Fatalf("%s did not trip on %s", client, x.file.box)
+ }
+}
+
+// post sends a notice body to x's ServeHTTP with auth (none when "").
+func (x *noticeEdge) post(auth, body string) *httptest.ResponseRecorder {
+ r := httptest.NewRequest(http.MethodPost, "http://"+x.file.host+burstNoticePath, strings.NewReader(body))
+ if auth != "" {
+ r.Header.Set(burstNoticeAuthHeader, auth)
+ }
+ w := httptest.NewRecorder()
+ x.edge().ServeHTTP(w, r)
+ return w
+}
+
+func noticeBody(client string, until time.Time, from, ref string) string {
+ return fmt.Sprintf(`{"client":%q,"until":%d,"from":%q,"ref":%q}`, client, until.Unix(), from, ref)
+}
+
+// transmitted is how many notices x has put on the wire, answered or not.
+func transmitted(x *noticeEdge) int64 {
+ st := x.edge().notices.stats()
+ return st.Sent + st.Failed
+}
+
+// A client that trips on annie is refused on betty, on betty's own app,
+// with the record saying the cool-down started on another app.
+func TestBurstNoticeAppliesOnThePeer(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+
+ const client = "203.0.113.7"
+ s.trip(t, a, client)
+ until, _, _ := a.edge().burst.cooling(noticePrefix(t, client))
+ waitFor(t, 5*time.Second, "betty applies the notice", func() bool {
+ _, _, ok := b.edge().burst.cooling(noticePrefix(t, client))
+ return ok
+ })
+ if got, from, _ := b.edge().burst.cooling(noticePrefix(t, client)); !got.Equal(until) || from != "" {
+ t.Fatalf("betty cools %s until %v (from %q), want %v from a notice", client, got, from, until)
+ }
+ if st := b.edge().notices.stats(); st.Accepted != 1 {
+ t.Fatalf("betty accepted %d notices, want 1", st.Accepted)
+ }
+
+ r := httptest.NewRequest(http.MethodGet, "http://"+b.file.host+scanPath(0), nil)
+ r.RemoteAddr = net.JoinHostPort(client, "40000")
+ w := httptest.NewRecorder()
+ b.edge().ServeHTTP(w, r)
+ if w.Code != http.StatusTooManyRequests {
+ t.Fatalf("betty answered %d to a cooling client's catalogue request, want 429", w.Code)
+ }
+ ms := b.rec.matches()
+ if len(ms) == 0 {
+ t.Fatal("betty filed no match for the refusal")
+ }
+ m := ms[len(ms)-1]
+ if m.Tier != reqrec.TierBurst || m.Kind != reqrec.KindBlock || m.CooldownFrom != reqrec.CooldownFromOtherApp || !m.CooldownUntil.Equal(until) {
+ t.Fatalf("betty's match %+v, want a burst block from %q until %v", m, reqrec.CooldownFromOtherApp, until)
+ }
+ // Betty applied it and did not tell anyone back.
+ if n := transmitted(b); n != 0 {
+ t.Fatalf("betty transmitted %d notices for a notice it received", n)
+ }
+}
+
+// Review Focus 2: a forged, replayed or misdirected notice is refused and
+// counted, and applies nothing.
+func TestBurstNoticeRefusesForgery(t *testing.T) {
+ s := newNoticeScene(t, true)
+ s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ now := s.clock.now()
+ other := make([]byte, len(s.key))
+ rand.Read(other)
+
+ cases := []struct {
+ name string
+ key []byte
+ to string
+ ts time.Time
+ client string
+ until time.Time
+ }{
+ {"wrong key", other, "betty", now, "203.0.113.1", now.Add(burstCooldown)},
+ {"stale timestamp", s.key, "betty", now.Add(-31 * time.Second), "203.0.113.2", now.Add(burstCooldown)},
+ {"timestamp ahead", s.key, "betty", now.Add(31 * time.Second), "203.0.113.3", now.Add(burstCooldown)},
+ {"another receiver", s.key, "carol", now, "203.0.113.4", now.Add(burstCooldown)},
+ {"until 11 minutes ahead", s.key, "betty", now, "203.0.113.5", now.Add(11 * time.Minute)},
+ {"until passed", s.key, "betty", now, "203.0.113.6", now.Add(-time.Second)},
+ {"a /24", s.key, "betty", now, "203.0.113.0/24", now.Add(burstCooldown)},
+ {"a v4-mapped /128", s.key, "betty", now, "::ffff:203.0.113.8/128", now.Add(burstCooldown)},
+ {"an IPv6 /64 not masked", s.key, "betty", now, "2001:db8:1:2::1/64", now.Add(burstCooldown)},
+ }
+ for _, c := range cases {
+ client := c.client
+ if !strings.Contains(client, "/") {
+ client += "/32"
+ }
+ body := noticeBody(client, c.until, "annie", "x")
+ if w := b.post(signBurstNotice(c.key, c.to, c.ts, []byte(body)), body); w.Code != http.StatusNotFound {
+ t.Errorf("%s: answered %d, want 404", c.name, w.Code)
+ }
+ }
+ // A valid signature over a different body.
+ body := noticeBody("203.0.113.9/32", now.Add(burstCooldown), "annie", "x")
+ sig := signBurstNotice(s.key, "betty", now, []byte(noticeBody("203.0.113.10/32", now.Add(burstCooldown), "annie", "x")))
+ if w := b.post(sig, body); w.Code != http.StatusNotFound {
+ t.Errorf("a signature over another body: answered %d, want 404", w.Code)
+ }
+ for i := 1; i <= 10; i++ {
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, fmt.Sprintf("203.0.113.%d", i))); ok {
+ t.Errorf("203.0.113.%d is cooling on betty after a refused notice", i)
+ }
+ }
+ st := b.edge().notices.stats()
+ if st.Accepted != 0 || st.RefusedAuth != 5 || st.RefusedUntil != 2 || st.RefusedNotice != 3 {
+ t.Fatalf("betty's counts %+v, want 5 auth, 2 until and 3 notice refusals", st)
+ }
+
+ // The same shape, properly signed, applies: the refusals above were the
+ // faults and nothing else.
+ good := noticeBody("203.0.113.11/32", now.Add(burstCooldown), "annie", "x")
+ if w := b.post(signBurstNotice(s.key, "betty", now, []byte(good)), good); w.Code != http.StatusNoContent {
+ t.Fatalf("a valid notice: answered %d, want 204", w.Code)
+ }
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.11")); !ok {
+ t.Fatal("a valid notice did not apply")
+ }
+}
+
+// A box without the mesh key (a fleet box) neither sends nor accepts.
+func TestBurstNoticeNoKeyNoSendNoAccept(t *testing.T) {
+ s := newNoticeScene(t, false)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ if len(s.key) != 0 {
+ t.Fatal("test bug: the scene has a mesh key")
+ }
+ s.trip(t, a, "203.0.113.7")
+ if st := a.edge().notices.stats(); st != (burstNoticeStats{}) {
+ t.Fatalf("annie with no key counted %+v, want nothing at all", st)
+ }
+ if n := a.edge().notices.peerCount(); n != 0 {
+ t.Fatalf("annie with no key started %d peer senders", n)
+ }
+
+ key := make([]byte, 32)
+ rand.Read(key)
+ now := s.clock.now()
+ body := noticeBody("203.0.113.8/32", now.Add(burstCooldown), "annie", "x")
+ if w := b.post(signBurstNotice(key, "betty", now, []byte(body)), body); w.Code != http.StatusNotFound {
+ t.Fatalf("betty with no key answered %d, want 404", w.Code)
+ }
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.8")); ok {
+ t.Fatal("betty with no key applied a notice")
+ }
+ if st := b.edge().notices.stats(); st.RefusedNoKey != 1 || st.Accepted != 0 {
+ t.Fatalf("betty's counts %+v, want one no-key refusal", st)
+ }
+ if got := len(b.arrivals()); got != 0 {
+ t.Fatalf("betty saw %d notices from a box with no key", got)
+ }
+}
+
+// Review Focus 3: the sender transmits at most 120 notices in a minute
+// whatever the trips, and the rest are dropped and counted; a receiver
+// applies at most 600 in a minute and counts the rest.
+func TestBurstNoticeCaps(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ c := s.add(t, "carol", "127.0.0.13", "docs.example.com", "bab", "docs", true)
+ d := s.add(t, "dora", "127.0.0.14", "news.example.com", "bdk", "news", true)
+ s.publish(t)
+ peers := []*noticeEdge{b, c, d}
+
+ for i := range 50 {
+ s.trip(t, a, noticeClient(i))
+ }
+ waitFor(t, 10*time.Second, "every notice sent or dropped", func() bool {
+ st := a.edge().notices.stats()
+ return st.Sent+st.Failed+st.OverBudget == 150
+ })
+ got := 0
+ for _, p := range peers {
+ got += len(p.arrivals())
+ }
+ st := a.edge().notices.stats()
+ if got != 120 || st.Sent != 120 || st.Failed != 0 {
+ t.Fatalf("peers saw %d notices (stats %+v), want exactly 120 transmitted", got, st)
+ }
+ // 50 trips to three peers is 150 messages: 120 sent, 30 kept local (ten
+ // trips' worth), every one counted.
+ if st.OverBudget != 30 || st.Overflow != 0 || st.Stale != 0 {
+ t.Fatalf("annie's counts %+v, want 30 dropped over the budget", st)
+ }
+
+ // The receiver's cap, in a fresh minute.
+ s.clock.advance(61 * time.Second)
+ now := s.clock.now()
+ before := b.edge().notices.stats().Accepted
+ applied, refused := 0, 0
+ for i := range 610 {
+ client := fmt.Sprintf("198.19.%d.%d", i/250, i%250+1)
+ body := noticeBody(client+"/32", now.Add(burstCooldown), "annie", "x")
+ switch w := b.post(signBurstNotice(s.key, "betty", now, []byte(body)), body); w.Code {
+ case http.StatusNoContent:
+ applied++
+ case http.StatusNotFound:
+ refused++
+ default:
+ t.Fatalf("notice %d answered %d", i, w.Code)
+ }
+ }
+ bst := b.edge().notices.stats()
+ if applied != 600 || refused != 10 || bst.Accepted-before != 600 || bst.RefusedCap != 10 {
+ t.Fatalf("applied %d refused %d (stats %+v), want 600 applied and 10 refused over the cap", applied, refused, bst)
+ }
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "198.19.2.110")); ok {
+ t.Fatal("the 610th notice applied")
+ }
+}
+
+// R3-1: a peer whose edges file does not say burst_notices (an older
+// release) is sent nothing, and its app never sees the notice path.
+func TestBurstNoticeOnlyToAdvertisingPeers(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ c := s.add(t, "carol", "127.0.0.13", "docs.example.com", "bab", "docs", false)
+ s.publish(t)
+
+ s.trip(t, a, "203.0.113.7")
+ waitFor(t, 5*time.Second, "the notice to betty", func() bool { return transmitted(a) == 1 })
+ if st := a.edge().notices.stats(); st.Sent != 1 {
+ t.Fatalf("annie's counts %+v, want one notice sent", st)
+ }
+ if n := len(b.arrivals()); n != 1 {
+ t.Fatalf("betty saw %d notices, want 1", n)
+ }
+ if n := len(c.arrivals()); n != 0 || c.appNotice.Load() != 0 {
+ t.Fatalf("carol, which does not advertise, saw %d notices and its app %d", n, c.appNotice.Load())
+ }
+ if _, _, ok := c.edge().burst.cooling(noticePrefix(t, "203.0.113.7")); ok {
+ t.Fatal("carol is cooling the client")
+ }
+
+ // The flag is the only thing that kept carol out: once its file says
+ // so, it is sent the next one.
+ c.file.advertise = true
+ s.publish(t)
+ s.trip(t, a, "203.0.113.8")
+ waitFor(t, 5*time.Second, "the notices to betty and carol", func() bool { return transmitted(a) == 3 })
+ if n := len(c.arrivals()); n != 1 || c.appNotice.Load() != 0 {
+ t.Fatalf("carol saw %d notices once it advertised (its app %d), want 1 (0)", n, c.appNotice.Load())
+ }
+}
+
+// R3-2: the budget is taken at dispatch, over any 60 s and not per
+// calendar minute, and a notice that cannot be sent within 10 s of its
+// trip is dropped and counted.
+func TestBurstNoticeBudgetAtDispatch(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ c := s.add(t, "carol", "127.0.0.13", "docs.example.com", "bab", "docs", true)
+ d := s.add(t, "dora", "127.0.0.14", "news.example.com", "bdk", "news", true)
+ s.publish(t)
+ peers := []*noticeEdge{b, c, d}
+ next := 0
+ trips := func(n int) {
+ t.Helper()
+ for range n {
+ s.trip(t, a, noticeClient(next))
+ next++
+ }
+ }
+ stats := func() burstNoticeStats { return a.edge().notices.stats() }
+
+ // The clock starts on a minute. 40 trips 50 s in use the whole budget.
+ s.clock.advance(50 * time.Second)
+ trips(40)
+ waitFor(t, 10*time.Second, "120 notices sent", func() bool { return stats().Sent == 120 })
+
+ // 61 s in, a new calendar minute: a per-minute counter would send these.
+ // The window still holds 120, the next slot is 49 s away, so all 30
+ // are dropped at once.
+ s.clock.advance(11 * time.Second)
+ trips(10)
+ waitFor(t, 5*time.Second, "30 notices over the budget", func() bool { return stats().OverBudget == 30 })
+
+ // 105 s in, the next slot (110 s) is within 10 s of the trip, so its
+ // three notices wait for it. The clock then moves past their 10 s and
+ // they are dropped as stale, unsent.
+ s.clock.advance(44 * time.Second)
+ trips(1)
+ time.Sleep(300 * time.Millisecond)
+ if st := stats(); st.Sent != 120 || st.Stale != 0 || st.OverBudget != 30 {
+ t.Fatalf("counts %+v while three notices wait for a slot", st)
+ }
+ s.clock.advance(11 * time.Second)
+ waitFor(t, 5*time.Second, "three stale notices", func() bool { return stats().Stale == 3 })
+
+ // 116 s in, the window has emptied: the next 30 go.
+ trips(10)
+ waitFor(t, 10*time.Second, "150 notices sent", func() bool { return stats().Sent == 150 })
+
+ var at []time.Time
+ for _, p := range peers {
+ at = append(at, p.arrivals()...)
+ }
+ slices.SortFunc(at, func(x, y time.Time) int { return x.Compare(y) })
+ if len(at) != 150 {
+ t.Fatalf("peers saw %d notices, want 150", len(at))
+ }
+ for i := range at {
+ in := 0
+ for j := i; j < len(at) && at[j].Sub(at[i]) < burstWindow; j++ {
+ in++
+ }
+ if in > burstNoticeSendPerMinute {
+ t.Fatalf("%d notices transmitted in the 60 s from %v", in, at[i])
+ }
+ }
+ if st := stats(); st.Sent != 150 || st.OverBudget != 30 || st.Stale != 3 || st.Failed != 0 || st.Overflow != 0 {
+ t.Fatalf("final counts %+v", st)
+ }
+}
+
+// R2-3: a notice whose body never arrives is answered 404 and its
+// connection closed within the 2 s body deadline.
+func TestBurstNoticeStalledBodyBounded(t *testing.T) {
+ s := newNoticeScene(t, true)
+ s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ now := s.clock.now()
+ body := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x")
+
+ conn, err := tls.Dial("tcp", net.JoinHostPort(b.file.ip, s.port), &tls.Config{ServerName: b.file.host, RootCAs: s.ca.pool, NextProtos: []string{"http/1.1"}})
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer conn.Close()
+ start := time.Now()
+ fmt.Fprintf(conn, "POST %s HTTP/1.1\r\nHost: %s\r\n%s: %s\r\nContent-Type: application/json\r\nContent-Length: %d\r\n\r\n%s",
+ burstNoticePath, b.file.host, burstNoticeAuthHeader, signBurstNotice(s.key, "betty", now, []byte(body)), len(body), body[:10])
+ conn.SetReadDeadline(time.Now().Add(10 * time.Second))
+ br := bufio.NewReader(conn)
+ resp, err := http.ReadResponse(br, nil)
+ if err != nil {
+ t.Fatalf("no answer to a stalled body: %v", err)
+ }
+ io.Copy(io.Discard, resp.Body)
+ resp.Body.Close()
+ took := time.Since(start)
+ if resp.StatusCode != http.StatusNotFound {
+ t.Fatalf("a stalled body answered %d, want 404", resp.StatusCode)
+ }
+ if took < burstNoticeReadTimeout-200*time.Millisecond || took > burstNoticeReadTimeout+time.Second {
+ t.Fatalf("answered after %v, want about %v", took, burstNoticeReadTimeout)
+ }
+ conn.SetReadDeadline(time.Now().Add(time.Second))
+ if _, err := br.ReadByte(); !errors.Is(err, io.EOF) {
+ t.Fatalf("connection still open after the refusal: %v", err)
+ }
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.7")); ok {
+ t.Fatal("a stalled notice applied")
+ }
+ if st := b.edge().notices.stats(); st.RefusedBody != 1 || st.Accepted != 0 {
+ t.Fatalf("betty's counts %+v, want one body refusal", st)
+ }
+
+ // An oversized body is refused the same way.
+ big := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", strings.Repeat("x", burstNoticeMaxBody))
+ if w := b.post(signBurstNotice(s.key, "betty", now, []byte(big)), big); w.Code != http.StatusNotFound {
+ t.Fatalf("an oversized notice answered %d, want 404", w.Code)
+ }
+ if st := b.edge().notices.stats(); st.RefusedBody != 2 {
+ t.Fatalf("betty's counts %+v, want two body refusals", st)
+ }
+}
+
+// The path alone is not a notice: without the header it is the app's.
+func TestBurstNoticePathWithoutAuthReachesApp(t *testing.T) {
+ s := newNoticeScene(t, true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ w := b.post("", `{"anything":1}`)
+ if b.appNotice.Load() != 1 || w.Body.String() != "the app's own 404" {
+ t.Fatalf("POST %s without the header: app saw %d, answer %d %q", burstNoticePath, b.appNotice.Load(), w.Code, w.Body.String())
+ }
+ if st := b.edge().notices.stats(); st != (burstNoticeStats{}) {
+ t.Fatalf("counted %+v for a request that is not a notice", st)
+ }
+ // And a GET with the header is not one either.
+ r := httptest.NewRequest(http.MethodGet, "http://"+b.file.host+burstNoticePath, nil)
+ r.Header.Set(burstNoticeAuthHeader, "1:00")
+ b.edge().ServeHTTP(httptest.NewRecorder(), r)
+ if b.appNotice.Load() != 2 {
+ t.Fatal("a GET of the notice path did not reach the app")
+ }
+}
+
+// R1-6: a peer that never answers costs only its own sender: the healthy
+// peer applies within a second, and the stalled send gives up at 3 s.
+func TestBurstNoticeSlowPeerIsolated(t *testing.T) {
+ s := newNoticeScene(t, true)
+ a := s.add(t, "annie", "127.0.0.11", "shop.example.com", "bdk", "shop", true)
+ // carol sorts before dora, so its sender is started first.
+ s.addStalled(t, "carol", "127.0.0.13", "docs.example.com")
+ d := s.add(t, "dora", "127.0.0.14", "news.example.com", "bdk", "news", true)
+ s.publish(t)
+
+ const client = "203.0.113.7"
+ s.trip(t, a, client)
+ start := time.Now()
+ waitFor(t, time.Second, "dora applies the notice", func() bool {
+ _, _, ok := d.edge().burst.cooling(noticePrefix(t, client))
+ return ok
+ })
+ waitFor(t, 6*time.Second, "the stalled send fails", func() bool { return a.edge().notices.stats().Failed == 1 })
+ took := time.Since(start)
+ if took < burstNoticeSendTimeout-200*time.Millisecond || took > burstNoticeSendTimeout+1500*time.Millisecond {
+ t.Fatalf("the stalled send gave up after %v, want about %v", took, burstNoticeSendTimeout)
+ }
+ if st := a.edge().notices.stats(); st.Sent != 1 || st.Failed != 1 {
+ t.Fatalf("annie's counts %+v, want one sent and one failed", st)
+ }
+}
+
+// Domain separation: a hop or door signature is not a notice signature,
+// and a notice signature is neither.
+func TestBurstNoticeIsNotAHop(t *testing.T) {
+ s := newNoticeScene(t, true)
+ b := s.add(t, "betty", "127.0.0.12", "blog.example.com", "bab", "blog", true)
+ s.publish(t)
+ now := s.clock.now()
+ body := noticeBody("203.0.113.7/32", now.Add(burstCooldown), "annie", "x")
+ for name, sig := range map[string]string{
+ "hop for the host": signHop(s.key, b.file.host, now),
+ "hop for the box": signHop(s.key, "betty", now),
+ "door for the host": signHopDoor(s.key, b.file.host, now),
+ "door for the box": signHopDoor(s.key, "betty", now),
+ } {
+ if w := b.post(sig, body); w.Code != http.StatusNotFound {
+ t.Errorf("%s: answered %d, want 404", name, w.Code)
+ }
+ }
+ if _, _, ok := b.edge().burst.cooling(noticePrefix(t, "203.0.113.7")); ok {
+ t.Fatal("a hop signature applied a notice")
+ }
+ if st := b.edge().notices.stats(); st.RefusedAuth != 4 {
+ t.Fatalf("betty's counts %+v, want four auth refusals", st)
+ }
+
+ sig := signBurstNotice(s.key, "betty", now, []byte(body))
+ for _, host := range []string{"betty", b.file.host} {
+ if verifyHopEitherKey(s.key, nil, host, sig, now) || verifyHopDoorEitherKey(s.key, nil, host, sig, now) {
+ t.Fatalf("a notice signature verifies as a hop or door mark for %s", host)
+ }
+ }
+ // Carried as a hop, it is not one.
+ r := httptest.NewRequest(http.MethodGet, "http://"+b.file.host+"/", nil)
+ r.Header.Set(hopHeader, "1")
+ r.Header.Set(hopAuthHeader, sig)
+ if _, ok := b.edge().acceptHop(r, b.file.host); ok {
+ t.Fatal("a notice signature was accepted as a hop")
+ }
+}
+
+// Either mirrored key verifies a notice, as for hops, so a rotation never
+// refuses one.
+func TestBurstNoticeVerifiesEitherKey(t *testing.T) {
+ cur, next, other := make([]byte, 32), make([]byte, 32), make([]byte, 32)
+ rand.Read(cur)
+ rand.Read(next)
+ rand.Read(other)
+ now := time.Now()
+ body := []byte(`{"client":"203.0.113.7/32","until":1,"from":"annie","ref":"x"}`)
+ for _, key := range [][]byte{cur, next} {
+ if !verifyBurstNoticeEitherKey(cur, next, "betty", signBurstNotice(key, "betty", now, body), body, now) {
+ t.Fatal("a notice under a mirrored key did not verify")
+ }
+ }
+ if verifyBurstNoticeEitherKey(cur, next, "betty", signBurstNotice(other, "betty", now, body), body, now) {
+ t.Fatal("a notice under an unknown key verified")
+ }
+ if verifyBurstNoticeEitherKey(nil, nil, "betty", signBurstNotice(cur, "betty", now, body), body, now) {
+ t.Fatal("a notice verified with no key")
+ }
+}
+
+// stopAll stops every peer sender, for a test's cleanup: in production an
+// edge lives as long as its process.
+func (n *burstNotices) stopAll() {
+ n.mu.Lock()
+ defer n.mu.Unlock()
+ for box, p := range n.peers {
+ close(p.stop)
+ delete(n.peers, box)
+ }
+}
+
+func (n *burstNotices) peerCount() int {
+ n.mu.Lock()
+ defer n.mu.Unlock()
+ return len(n.peers)
+}
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 7a9d1768f..b05283a7c 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -283,6 +283,9 @@ type Edge struct {
// app and client in the observer defer, and the box-wide cool-downs the
// guard checks catalogue requests against.
burst *burstLimiter
+ // notices carries this box's trips to the other platform edges and
+ // applies theirs here (burst_notice.go). Created in New.
+ notices *burstNotices
// issuer, when set, gates certificate ISSUANCE on this box holding the
// deployment's housekeeper lease (certsync.go). It arrives through
// WithIssuerGate because internal/host imports this package and never the
@@ -533,7 +536,7 @@ func New(reg *registry.Registry, act Activator) (*Edge, error) {
func newEdge(reg *registry.Registry, act Activator, hold localHold) (*Edge, error) {
e := &Edge{reg: reg, act: act, hold: hold, gate: gate.New(), probers: newProberSet(hold), gzipOn: gzipEnabled(), guard: guardModeFromEnv(os.Getenv), steeringHost: steeringProbeHostFromEnv(), appsDomain: appsDomainFromEnv(),
lbHealth: lbHealthFromEnv(os.Getenv, act), rateMode: rateModeFromEnv(), rateLimiter: ratelimit.NewLimiter(time.Now, 100_000),
- planLimiter: ratelimit.NewLimiter(time.Now, 100_000), burst: newBurstLimiter(time.Now)}
+ planLimiter: ratelimit.NewLimiter(time.Now, 100_000), burst: newBurstLimiter(time.Now), notices: newBurstNotices()}
e.geo = geo.NewSwappable()
e.geoLookup = e.geo.Lookup
e.guardMint = e.mintRef
@@ -1882,6 +1885,14 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// On a request carrying no X-Carlos-Hop this is one Header.Get and
// nothing else.
r, hopped := e.acceptHop(r, host)
+ // A probe-burst notice from another edge (burst_notice.go) is answered
+ // here, ahead of every route, so it never reaches a tenant's app. Only a
+ // POST to its path carrying its header is one: anything else, that path
+ // included, goes on as before. A door caller is an app on this box, not
+ // an edge, and is never one.
+ if !isDoor && e.serveBurstNotice(w, r) {
+ return
+ }
// The asset cache's fill vocabulary (assetcatch.go, design §5.3) is this
// edge's to send, never a client's: a far edge's assertion is honoured
// only on a verified hop, where the home's fill hook consumes it, and no
diff --git a/internal/edge/guard.go b/internal/edge/guard.go
index 34243563d..8ad974637 100644
--- a/internal/edge/guard.go
+++ b/internal/edge/guard.go
@@ -5,7 +5,6 @@ import (
"io"
"log"
"net/http"
- "net/netip"
"strings"
"time"
@@ -298,11 +297,6 @@ func (e *Edge) noteBurst(rt registry.Route, r *http.Request, status int, out *ou
e.sendBurstNotices(client, until, ref)
}
-// sendBurstNotices tells the platform's other edges that client tripped
-// here, so they apply the same cool-down. Task 4 of the probe-burst plan
-// fills it in; until then a trip stays on this box.
-func (e *Edge) sendBurstNotices(client netip.Prefix, until time.Time, ref string) {}
-
// writeGuardBlock writes the block page: a plain 404 that says no more than
// a missing page would, with the reference code in a header and in the
// body, so the visitor can pass it to the site's owner. It is never cached:
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index 829b82bdf..02c193165 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -150,6 +150,10 @@ type edgesFileView struct {
// never in view.
DataBucket string `json:"data_bucket"`
SecretsKeyFP string `json:"secrets_key_fp"`
+ // BurstNotices says the box answers probe-burst notices itself
+ // (burst_notice.go). A box sends notices only to a file that says so:
+ // on an older box the notice path would reach a tenant's app.
+ BurstNotices bool `json:"burst_notices"`
}
// dialPoint is f's dial fields, as edgesfile reads them.
diff --git a/internal/edge/mesh.go b/internal/edge/mesh.go
index 54d21b992..b84e83b80 100644
--- a/internal/edge/mesh.go
+++ b/internal/edge/mesh.go
@@ -266,6 +266,62 @@ func verifyHopDoorEitherKey(current, next []byte, host, header string, now time.
return len(current) > 0 && verifyHopMAC(current, hopDoorDomain, host, header, now)
}
+// burstNoticeDomain separates a probe-burst notice's MAC (burst_notice.go)
+// from the hop's and the door mark's, by the NUL argument hopDoorDomain
+// makes: a request host never holds a NUL, so no hop or door MAC input can
+// begin with this prefix, and neither verifies as a notice or the reverse.
+const burstNoticeDomain = "carlos-burst-notice\x00"
+
+// signBurstNotice produces the value of the X-Carlos-Burst-Auth header: the
+// timestamp, then the hex HMAC over the domain, the receiving box's name,
+// the timestamp and the body. The receiver is bound in so a notice sent to
+// one box cannot be replayed at another, and the body so nothing in it can
+// be changed on the way.
+func signBurstNotice(key []byte, receiver string, now time.Time, body []byte) string {
+ ts := strconv.FormatInt(now.Unix(), 10)
+ return ts + ":" + hex.EncodeToString(burstNoticeMAC(key, receiver, ts, body))
+}
+
+// verifyBurstNoticeEitherKey checks a notice's header for this receiver
+// under either mirrored key, as verifyHopEitherKey does for hops: the
+// timestamp within ±hopSkew of now, the MAC compared in constant time.
+func verifyBurstNoticeEitherKey(current, next []byte, receiver, header string, body []byte, now time.Time) bool {
+ ts, sig, ok := strings.Cut(header, ":")
+ if !ok || ts == "" || sig == "" {
+ return false
+ }
+ sec, err := strconv.ParseInt(ts, 10, 64)
+ if err != nil {
+ return false
+ }
+ skew := now.Sub(time.Unix(sec, 0))
+ if skew < 0 {
+ skew = -skew
+ }
+ if skew > hopSkew {
+ return false
+ }
+ got, err := hex.DecodeString(sig)
+ if err != nil {
+ return false
+ }
+ if len(next) > 0 && hmac.Equal(got, burstNoticeMAC(next, receiver, ts, body)) {
+ return true
+ }
+ return len(current) > 0 && hmac.Equal(got, burstNoticeMAC(current, receiver, ts, body))
+}
+
+func burstNoticeMAC(key []byte, receiver, ts string, body []byte) []byte {
+ mac := hmac.New(sha256.New, key)
+ mac.Write([]byte(burstNoticeDomain))
+ mac.Write([]byte(receiver))
+ mac.Write([]byte("\n"))
+ mac.Write([]byte(ts))
+ mac.Write([]byte("\n"))
+ mac.Write(body)
+ return mac.Sum(nil)
+}
+
// hopMAC is the MAC signHop and verifyHop both compute — one place so the
// two can never drift out of sync on what bytes are actually signed, and
// the one choke point that canonicalizes host before it enters the MAC.
diff --git a/internal/edge/testdata/edges-forward-hub.json b/internal/edge/testdata/edges-forward-hub.json
index f3102adcc..5a4b0ed97 100644
--- a/internal/edge/testdata/edges-forward-hub.json
+++ b/internal/edge/testdata/edges-forward-hub.json
@@ -1 +1 @@
-{"v":1,"box":"hub","eip":"198.51.100.7","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"2026-10-30T00:00:00Z","hosts":{"*.bah-certonly.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-certs.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-regional.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-wild.example.com":{"role":"home","platform":false,"alias":true,"wildcard":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"bah-certonly.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah-custom.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah.example.com":{"role":"home","platform":true,"account":"bah","app":"shop"},"tickets.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"}}}
+{"v":1,"box":"hub","eip":"198.51.100.7","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"burst_notices":true,"moves_protocol":0,"seeds_protocol":0,"addrs":null,"generation":"2026-10-30T00:00:00Z","hosts":{"*.bah-certonly.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-certs.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-regional.example.com":{"role":"wildcard","platform":false,"wildcard":true},"*.bah-wild.example.com":{"role":"home","platform":false,"alias":true,"wildcard":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"bah-certonly.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah-custom.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"},"shop.bah.example.com":{"role":"home","platform":true,"account":"bah","app":"shop"},"tickets.example.com":{"role":"home","platform":false,"alias":true,"account":"bah","app":"shop","target_host":"shop.bah.example.com"}}}
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index 0a217e3cc..cb9a2fedc 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -325,6 +325,13 @@ type edgesFile struct {
// (edgesFileEligibility), never a second reading of the environment.
ServesSharedPool bool `json:"serves_shared_pool"`
AcceptsInbound bool `json:"accepts_inbound"`
+ // BurstNotices says this box's edge answers probe-burst notices itself
+ // (internal/edge burst_notice.go), so the other edges may send them
+ // here. Set by every pass of this build (edgesFileWriteClaims), never
+ // from config: the edge that answers them is in the same binary.
+ // Absent is an older build, which would hand the notice path to a
+ // tenant's app, so senders skip it.
+ BurstNotices bool `json:"burst_notices,omitempty"`
// SecretsKeyFP is the fingerprint of this box's CARLOS_SECRETS_KEY's
// public half (appconfig.KeyFingerprint), NEVER the key. Additive and
@@ -938,6 +945,7 @@ 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.BurstNotices = true
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)
diff --git a/internal/host/edgesfile_test.go b/internal/host/edgesfile_test.go
index 3172d3819..43ae61091 100644
--- a/internal/host/edgesfile_test.go
+++ b/internal/host/edgesfile_test.go
@@ -327,7 +327,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,"addrs":null,"generation":"` +
+ want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"burst_notices":true,"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)
@@ -370,7 +370,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,"addrs":null,"generation":"` +
+ want := `{"v":1,"box":"quiet-harbour","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"burst_notices":true,"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)
@@ -389,7 +389,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,"addrs":null,"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,"burst_notices":true,"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)
@@ -943,7 +943,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,"addrs":null,"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,"burst_notices":true,"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)
@@ -1442,6 +1442,29 @@ func TestEdgesFileOmitsBoxEvidenceWhenAbsent(t *testing.T) {
}
}
+// Every file this build writes says it accepts probe-burst notices, whatever
+// identity it was handed: the edge's interceptor is in every build that
+// runs this writer, and the other edges send only to a box that says so.
+func TestEdgesFileAdvertisesBurstNotices(t *testing.T) {
+ s, reg := release.NewDirStore(t.TempDir()), edgesTestRegistry(t)
+ seedRoute(t, reg, "app.example.com")
+ var last []byte
+ if err := edgesFilePass(context.Background(), s, reg, edgesFile{Box: "annie"}, "1.2.3.4", &last); err != nil {
+ t.Fatal(err)
+ }
+ body, _, err := s.Get(context.Background(), "control/edges/annie.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var raw map[string]json.RawMessage
+ if err := json.Unmarshal(body, &raw); err != nil {
+ t.Fatal(err)
+ }
+ if got := string(raw["burst_notices"]); got != "true" {
+ t.Fatalf("burst_notices = %q in %s, want true", got, body)
+ }
+}
+
func TestEdgesFileHeadroomAloneDoesNotRewriteTheFile(t *testing.T) {
st := &putCountingStore{Store: release.NewDirStore(t.TempDir())}
reg := edgesTestRegistry(t)
@@ -1762,7 +1785,7 @@ func TestEdgesFileAddrsEmptyAndUnreadable(t *testing.T) {
}
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 head = `{"v":1,"box":"%s","eip":"203.0.113.10","hibernation_configured":false,"serves_shared_pool":false,"accepts_inbound":false,"burst_notices":true,"moves_protocol":0,"seeds_protocol":0,`
const tail = `,"generation":"GEN","hosts":{"app.example.com":{"role":"home","platform":false}}}`
r := &addrsReader{}
diff --git a/internal/host/egress_nopolicy_linux_test.go b/internal/host/egress_nopolicy_linux_test.go
index fcea9a91a..44f1649f8 100644
--- a/internal/host/egress_nopolicy_linux_test.go
+++ b/internal/host/egress_nopolicy_linux_test.go
@@ -176,7 +176,8 @@ func (n *countedNudge) Egress(ctx context.Context, host string) error {
// - the snapshot, written by WriteBox, is main's byte for byte (no
// "egress" key), with main's store requests;
// - the edges file is main's byte for byte but for the documented
-// "addrs" field (Task 8), at its place, with main's store requests:
+// "addrs" field (Task 8) and "burst_notices" (probe-burst notices),
+// each at its place, with main's store requests:
// a write on the first pass and none on an unchanged second.
//
// Its socket needs a short TMPDIR (/tmp/g).
@@ -383,8 +384,10 @@ func TestEgressNoPolicyBoxPublishesAsMain(t *testing.T) {
}
mainBody := fmt.Sprintf(mainNoPolicyEdges, probeGen.Generation)
const addrsField = `"addrs":["10.0.1.5","fe80::1"],`
- if wantBody := strings.Replace(mainBody, `"generation":`, addrsField+`"generation":`, 1); string(body) != wantBody {
- t.Fatalf("the edges file is not main's plus addrs:\n%s\nwant:\n%s", body, wantBody)
+ wantBody := strings.Replace(mainBody, `"generation":`, addrsField+`"generation":`, 1)
+ wantBody = strings.Replace(wantBody, `"moves_protocol":`, `"burst_notices":true,"moves_protocol":`, 1)
+ if string(body) != wantBody {
+ t.Fatalf("the edges file is not main's plus addrs and burst_notices:\n%s\nwant:\n%s", body, wantBody)
}
})
}