edge: one ownership verdict for dispatch and upgrades (#186)
Task 8 review round 2 (Astra P2, the request/upgrade ownership family). nameOwnerVerdict is now the whole ownership decision for a name: serve here, refuse, or send elsewhere, the legacy no-key local fallback included. With no mesh key mirrored, on a request that is neither a hop nor a door call, a name another box owns is served here unless the owner is admission-aware or the request is a case 3 target (refused). serveNameOwner serves locally exactly on ownerLocal. If the key goes between the verdict and the backhaul, it refuses rather than falling back. The upgrade reservation and sweep keep only ownerLocal, so an ordinary upgrade in the no-key case is no longer refused or swept. TestUpgradeOwnershipAgreesWithDispatch runs a table of ownership situations through ServeHTTP and upgradeSelection and requires "served here" to equal "upgrade kept". TestUpgradeOwnershipReserveAndSweep covers reservation and sweep for the no-key keep and the refusals. TestPathAcrossUpgradeFrontAuthority now runs keyed and admission-aware, the two deployments where a request yields to the new owner.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+321
−59
internal/edge/ownership_agree_test.go+219 −0internal/edge/path_across_e2e_test.go+55 −36internal/edge/pathhop.go+47 −23
diff --git a/internal/edge/ownership_agree_test.go b/internal/edge/ownership_agree_test.go| new file mode 100644 |
| index 000000000..d8595aee1 |
| --- /dev/null |
| +++ b/internal/edge/ownership_agree_test.go |
| @@ -0,0 +1,219 @@ |
| +package edge |
| + |
| +// One ownership decision for a request and an upgrade (#186 Task 8 review, |
| +// the request/upgrade ownership family). nameOwnerVerdict decides serve |
| +// here / refuse / send elsewhere for a name, legacy no-key fallback |
| +// included. ServeHTTP's ownership block acts on it, and an admitted |
| +// upgrade's reservation and sweep keep only "serve here". These tests run |
| +// each ownership situation through both and require them to agree: a |
| +// request is served locally exactly when its upgrade is kept. |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "net" |
| + "net/http" |
| + "net/http/httptest" |
| + "sync/atomic" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// ownPeerFile is the peer box's edges file publishing hosts (host -> entry |
| +// JSON); aware makes the box admission-aware. |
| +func ownPeerFile(aware bool, hosts map[string]string) string { |
| + head := `{"v":1,` |
| + if aware { |
| + head = `{"v":1,"box_role":"serve","admitted":true,"drained":false,` |
| + } |
| + body := "" |
| + for h, e := range hosts { |
| + if body != "" { |
| + body += "," |
| + } |
| + body += fmt.Sprintf("%q:%s", h, e) |
| + } |
| + return head + fmt.Sprintf(`"box":"peer","eip":"192.0.2.2","hosts":{%s}}`, body) |
| +} |
| + |
| +const ownOtherRoute = `{"role":"home","account":"xyz","app":"other"}` |
| + |
| +func TestUpgradeOwnershipAgreesWithDispatch(t *testing.T) { |
| + const ticket = "tickets.example.com" |
| + for _, tc := range []struct { |
| + name string |
| + primary string // the local route row's host |
| + alias string // an attached alias of primary, if any |
| + case3 bool // primary is a path target of hub.example.com, a front served elsewhere |
| + peer map[string]string |
| + aware bool // the peer box is admission-aware |
| + keyed bool // a mesh key is mirrored |
| + host string |
| + path string |
| + want bool // served here, and the upgrade kept |
| + }{ |
| + {name: "local-exact", primary: ticket, peer: map[string]string{"elsewhere.example.org": ownOtherRoute}, keyed: true, host: ticket, want: true}, |
| + {name: "catchall-aware-nokey", primary: "*.example.com", peer: map[string]string{ticket: ownOtherRoute}, aware: true, host: ticket}, |
| + {name: "catchall-aware-keyed", primary: "*.example.com", peer: map[string]string{ticket: ownOtherRoute}, aware: true, keyed: true, host: ticket}, |
| + {name: "catchall-legacy-nokey", primary: "*.example.com", peer: map[string]string{ticket: ownOtherRoute}, host: ticket, want: true}, |
| + {name: "catchall-legacy-keyed", primary: "*.example.com", peer: map[string]string{ticket: ownOtherRoute}, keyed: true, host: ticket}, |
| + {name: "alias-aware-nokey", primary: "shop.b.example.net", alias: ticket, peer: map[string]string{ticket: ownOtherRoute}, aware: true, host: ticket}, |
| + {name: "alias-legacy-nokey", primary: "shop.b.example.net", alias: ticket, peer: map[string]string{ticket: ownOtherRoute}, host: ticket, want: true}, |
| + // A legacy peer row with no stamp does not outrank the local alias |
| + // (TestGroupNamesLegacyLocalAnswers): resolved here, key or not. |
| + {name: "alias-legacy-keyed", primary: "shop.b.example.net", alias: ticket, peer: map[string]string{ticket: ownOtherRoute}, keyed: true, host: ticket, want: true}, |
| + {name: "alias-aware-keyed", primary: "shop.b.example.net", alias: ticket, peer: map[string]string{ticket: ownOtherRoute}, aware: true, keyed: true, host: ticket}, |
| + {name: "case3-front-legacy-nokey", primary: "tenant.example.com", case3: true, peer: map[string]string{"hub.example.com": frontRow("abc", "hub")}, host: "hub.example.com", path: "/acme/x", want: true}, |
| + {name: "case3-front-aware-keyed", primary: "tenant.example.com", case3: true, peer: map[string]string{"hub.example.com": frontRow("abc", "hub")}, aware: true, keyed: true, host: "hub.example.com", path: "/acme/x", want: true}, |
| + {name: "case3-front-prefix-miss", primary: "tenant.example.com", case3: true, peer: map[string]string{"hub.example.com": frontRow("abc", "hub")}, keyed: true, host: "hub.example.com", path: "/other"}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + var hits atomic.Int64 |
| + app := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| + hits.Add(1) |
| + _, _ = w.Write([]byte("local")) |
| + })) |
| + t.Cleanup(app.Close) |
| + reg := openReg(t) |
| + kind := "service" |
| + if tc.case3 { |
| + kind = "instance" |
| + } |
| + if err := reg.Upsert(registry.Route{Host: tc.primary, Account: "abc", App: "shop", Kind: kind, Status: "ready", Addr: app.Listener.Addr().String(), Incarnation: 1, ServingSeq: 1}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if tc.alias != "" { |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: tc.alias, Host: tc.primary, Account: "abc", App: "shop", DNSStatus: "pointing"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if tc.case3 { |
| + remotePathRow(t, reg, "hub.example.com", "acme", tc.primary, "abc", "hub") |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + s := release.NewDirStore(t.TempDir()) |
| + if tc.keyed { |
| + if err := MintMeshKey(t.Context(), s); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + putJSON(t, s, "control/edges/peer.json", ownPeerFile(tc.aware, tc.peer)) |
| + m := newHomeMap(s, "local") |
| + refreshHomeMap(t, m) |
| + e.homes.Store(m) |
| + peerHits := new(atomic.Int64) |
| + if tc.keyed { |
| + peer := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| + peerHits.Add(1) |
| + _, _ = w.Write([]byte("peer")) |
| + })) |
| + t.Cleanup(peer.Close) |
| + tr := peer.Client().Transport.(*http.Transport).Clone() |
| + tr.DialContext = func(ctx context.Context, network, _ string) (net.Conn, error) { |
| + return (&net.Dialer{}).DialContext(ctx, network, peer.Listener.Addr().String()) |
| + } |
| + e.backhaulTransports.Store("192.0.2.2", tr) |
| + t.Cleanup(tr.CloseIdleConnections) |
| + } |
| + path := tc.path |
| + if path == "" { |
| + path = "/cable" |
| + } |
| + |
| + w := httptest.NewRecorder() |
| + e.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "https://"+tc.host+path, nil)) |
| + servedHere := hits.Load() == 1 && w.Code == http.StatusOK |
| + _, kept := e.upgradeSelection(context.Background(), tc.host, path) |
| + if servedHere != kept { |
| + t.Fatalf("dispatch served here = %v (%d %q), upgrade kept = %v: they must agree", servedHere, w.Code, w.Body.String(), kept) |
| + } |
| + if servedHere != tc.want { |
| + t.Fatalf("served here = %v (%d %q, peer hits %d), want %v", servedHere, w.Code, w.Body.String(), peerHits.Load(), tc.want) |
| + } |
| + if !servedHere && hits.Load() != 0 { |
| + t.Fatalf("the local app was reached (%d) though dispatch did not serve here", hits.Load()) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Reservation and sweep for the decision's two sides on a tunnel route |
| +// reached through a catch-all, while another box publishes the exact name: |
| +// the legacy no-key fallback serves the name here, so its upgrade is |
| +// reserved and kept; an admission-aware owner, or a mirrored key, sends the |
| +// name elsewhere, so the upgrade is refused and an existing one is swept. |
| +func TestUpgradeOwnershipReserveAndSweep(t *testing.T) { |
| + const name, target = "x.tunnel.example", "t.example.com" |
| + ten := tenancy{ArmTunnel, fwdOther, "blog", "", "t1", ""} |
| + adm := upgradeAdmission{Host: name, Path: "/cable", Tenancy: ten} |
| + scene := func(t *testing.T, keyed, aware bool) (*Edge, *tunnelConn, *homeMap) { |
| + _, hub, _ := forwardHubAndBox(t, []registry.Route{ |
| + {Host: target, Kind: "instance", Status: "ready", Tunnel: "t1", Account: fwdOther, App: "blog"}, |
| + }, nil, namedHandler("box-1")) |
| + if err := hub.reg.UpsertAlias(registry.RouteAlias{Alias: "*.tunnel.example", Host: target, Account: fwdOther, App: "blog"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := hub.Reload(); err != nil { |
| + t.Fatal(err) |
| + } |
| + s := meshTestStore(t) |
| + if keyed { |
| + if err := MintMeshKey(t.Context(), s); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + putJSON(t, s, "control/edges/peer.json", ownPeerFile(aware, map[string]string{name: ownOtherRoute})) |
| + m := newHomeMap(s, "annie") |
| + refreshHomeMap(t, m) |
| + hub.homes.Store(m) |
| + tc := hub.tunnels.channel("home/box-1") |
| + if tc == nil { |
| + t.Fatal("home/box-1 has no channel connection") |
| + } |
| + if up, ok := hub.lookupUpstreamPath(name, "/cable"); !ok || up.tenancy != ten { |
| + t.Fatalf("fixture: the catch-all does not serve %s with the target's tenancy", name) |
| + } |
| + return hub, tc, m |
| + } |
| + |
| + t.Run("legacy-nokey-kept", func(t *testing.T) { |
| + hub, tc, m := scene(t, false, false) |
| + r, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10) |
| + if err != nil { |
| + t.Fatalf("reserve: %v, want admitted (dispatch serves the name here)", err) |
| + } |
| + defer r.release(relBody) |
| + hub.sweepUpgrades() |
| + if n := heldFor(hub, name); n != 1 { |
| + t.Fatalf("after a sweep: %d held, want 1", n) |
| + } |
| + // The owner turns admission-aware: the name now belongs elsewhere. |
| + putJSON(t, m.s, "control/edges/peer.json", ownPeerFile(true, map[string]string{name: ownOtherRoute})) |
| + refreshHomeMap(t, m) |
| + hub.sweepUpgrades() |
| + if n := heldFor(hub, name); n != 0 { |
| + t.Fatalf("after the owner turned admission-aware: %d held, want 0", n) |
| + } |
| + if _, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10); !errors.Is(err, errTenancyStale) { |
| + t.Fatalf("reserve after: %v, want errTenancyStale", err) |
| + } |
| + }) |
| + for _, v := range []struct { |
| + name string |
| + keyed, aware bool |
| + }{{"aware-nokey-refused", false, true}, {"legacy-keyed-refused", true, false}, {"aware-keyed-refused", true, true}} { |
| + t.Run(v.name, func(t *testing.T) { |
| + hub, tc, _ := scene(t, v.keyed, v.aware) |
| + if _, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10); !errors.Is(err, errTenancyStale) { |
| + t.Fatalf("reserve: %v, want errTenancyStale (dispatch does not serve the name here)", err) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/edge/path_across_e2e_test.go b/internal/edge/path_across_e2e_test.go| index e3a75a9d0..8b2f214d0 100644 |
| --- a/internal/edge/path_across_e2e_test.go |
| +++ b/internal/edge/path_across_e2e_test.go |
| @@ -841,18 +841,20 @@ func TestPathAcrossUpgradeCase3Reserved(t *testing.T) { |
| // Review A-P1-2: an upgrade's re-check judges the front name's authority as |
| // well as the tenancy. The front's published owner moves to another account |
| // and a reload installs a local catch-all pointing at the target, which |
| -// would lend the re-selection the target's tenancy; an ordinary request |
| -// would yield to the new exact owner, so the reservation is refused (the |
| -// transition inside beforeReserve) and an existing one is swept. |
| +// would lend the re-selection the target's tenancy. Where an ordinary |
| +// request would yield to the new exact owner (a mesh key is mirrored, or |
| +// the owner is admission-aware), the reservation is refused (the transition |
| +// inside beforeReserve) and an existing one is swept. |
| func TestPathAcrossUpgradeFrontAuthority(t *testing.T) { |
| const front, target = "hub.tunnel.example", "t.example.com" |
| ten := tenancy{ArmTunnel, fwdOther, "blog", "", "t1", ""} |
| adm := upgradeAdmission{Host: front, Path: "/acme/cable", Tenancy: ten} |
| // scene is a hub serving the target over a tunnel, with the front's |
| // remote map and the front published for the target's account; move |
| - // republishes the front for another account and installs the catch-all, |
| - // and its Reload runs the sweep. |
| - scene := func(t *testing.T) (hub *Edge, tc *tunnelConn, move func() error) { |
| + // republishes the front for another account (admission-aware when aware) |
| + // and installs the catch-all, and its Reload runs the sweep. keyed |
| + // mirrors a mesh key. |
| + scene := func(t *testing.T, keyed, aware bool) (hub *Edge, tc *tunnelConn, move func() error) { |
| _, hub, _ = forwardHubAndBox(t, []registry.Route{ |
| {Host: target, Kind: "instance", Status: "ready", Tunnel: "t1", Account: fwdOther, App: "blog"}, |
| }, nil, namedHandler("box-1")) |
| @@ -861,13 +863,25 @@ func TestPathAcrossUpgradeFrontAuthority(t *testing.T) { |
| t.Fatal(err) |
| } |
| m := newHomeMap(meshTestStore(t), "annie") |
| + if keyed { |
| + if err := MintMeshKey(t.Context(), m.s); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| putPathFile(t, m, "betty", "2.2.2.2", map[string]string{front: frontRow(fwdOther, "hub")}) |
| refreshHomeMap(t, m) |
| + if got := len(signingKey(m.meshKeys())) > 0; got != keyed { |
| + t.Fatalf("fixture: mesh key mirrored = %v, want %v", got, keyed) |
| + } |
| hub.homes.Store(m) |
| if tc = hub.tunnels.channel("home/box-1"); tc == nil { |
| t.Fatal("home/box-1 has no channel connection") |
| } |
| - otherFile := fmt.Sprintf(`{"v":1,"box":"betty","eip":"2.2.2.2","hosts":{%q:%s}}`, front, frontRow(fwdOwner, "other")) |
| + head := `{"v":1,` |
| + if aware { |
| + head = `{"v":1,"box_role":"serve","admitted":true,"drained":false,` |
| + } |
| + otherFile := head + fmt.Sprintf(`"box":"betty","eip":"2.2.2.2","hosts":{%q:%s}}`, front, frontRow(fwdOwner, "other")) |
| move = func() error { |
| _, etag, err := m.s.Get(context.Background(), "control/edges/betty.json") |
| if err != nil { |
| @@ -887,33 +901,38 @@ func TestPathAcrossUpgradeFrontAuthority(t *testing.T) { |
| return hub, tc, move |
| } |
| - t.Run("sweep", func(t *testing.T) { |
| - hub, tc, move := scene(t) |
| - r, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10) |
| - if err != nil { |
| - t.Fatalf("reserve before the move: %v, want admitted", err) |
| - } |
| - defer r.release(relBody) |
| - if err := move(); err != nil { |
| - t.Fatal(err) |
| - } |
| - if up, ok := hub.lookupUpstreamPath(front, "/acme/cable"); !ok || up.tenancy != ten { |
| - t.Fatalf("fixture: the catch-all does not lend the front the target's tenancy (%v %+v)", ok, up.tenancy) |
| - } |
| - if n := heldFor(hub, front); n != 0 { |
| - t.Fatalf("after the move and its reload sweep: %d held, want 0", n) |
| - } |
| - }) |
| - t.Run("beforeReserve", func(t *testing.T) { |
| - hub, tc, move := scene(t) |
| - moved := make(chan error, 1) |
| - hub.open.beforeReserve = func() { moved <- move() } |
| - _, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10) |
| - if merr := <-moved; merr != nil { |
| - t.Fatal(merr) |
| - } |
| - if !errors.Is(err, errTenancyStale) { |
| - t.Fatalf("reserve across the move: %v, want errTenancyStale", err) |
| - } |
| - }) |
| + for _, v := range []struct { |
| + name string |
| + keyed, aware bool |
| + }{{"keyed", true, false}, {"admission-aware", false, true}} { |
| + t.Run(v.name+"/sweep", func(t *testing.T) { |
| + hub, tc, move := scene(t, v.keyed, v.aware) |
| + r, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10) |
| + if err != nil { |
| + t.Fatalf("reserve before the move: %v, want admitted", err) |
| + } |
| + defer r.release(relBody) |
| + if err := move(); err != nil { |
| + t.Fatal(err) |
| + } |
| + if up, ok := hub.lookupUpstreamPath(front, "/acme/cable"); !ok || up.tenancy != ten { |
| + t.Fatalf("fixture: the catch-all does not lend the front the target's tenancy (%v %+v)", ok, up.tenancy) |
| + } |
| + if n := heldFor(hub, front); n != 0 { |
| + t.Fatalf("after the move and its reload sweep: %d held, want 0", n) |
| + } |
| + }) |
| + t.Run(v.name+"/beforeReserve", func(t *testing.T) { |
| + hub, tc, move := scene(t, v.keyed, v.aware) |
| + moved := make(chan error, 1) |
| + hub.open.beforeReserve = func() { moved <- move() } |
| + _, _, err := hub.reserveUpgrade(context.Background(), adm, tc, 10) |
| + if merr := <-moved; merr != nil { |
| + t.Fatal(merr) |
| + } |
| + if !errors.Is(err, errTenancyStale) { |
| + t.Fatalf("reserve across the move: %v, want errTenancyStale", err) |
| + } |
| + }) |
| + } |
| } |
diff --git a/internal/edge/pathhop.go b/internal/edge/pathhop.go| index b56ad7f65..560423685 100644 |
| --- a/internal/edge/pathhop.go |
| +++ b/internal/edge/pathhop.go |
| @@ -105,20 +105,35 @@ func (e *Edge) frontMarkHolds(host string, up upstream) bool { |
| type ownerVerdict int |
| const ( |
| - // ownerLocal: serve the selection here. |
| + // ownerLocal: serve the selection here. The ONLY verdict under which |
| + // a request is served on this box, and the only one under which an |
| + // upgrade is reserved or kept. |
| ownerLocal ownerVerdict = iota |
| // ownerHeld: the exact name is held; refused (503), even on a hop. |
| ownerHeld |
| - // ownerElsewhere: another box owns the name (the resolution says which). |
| + // ownerElsewhere: another box owns the name (the resolution says |
| + // which) and this box can send it there: the backhaul (or the far |
| + // asset catch), the stale-hop refusal on a hop, the unknown-host answer |
| + // to a door call. |
| ownerElsewhere |
| - // ownerRefused: a case 3 target whose front mark no longer holds and |
| - // whose name no other box owns; refused (503), never served unchecked. |
| + // ownerRefused: another box owns the name but nothing can sign a hop |
| + // to it while the owner is admission-aware or the request is a case 3 |
| + // target; or a case 3 target whose front mark no longer holds and whose |
| + // name no other box owns. Refused (503), never served unchecked. |
| ownerRefused |
| ) |
| -// nameOwnerVerdict is the ownership block's decision, with no side effect: |
| -// ServeHTTP acts on it (serveNameOwner), and an admitted upgrade's re-check |
| -// requires ownerLocal (upgradeSelection), so both judge the name alike. |
| +// nameOwnerVerdict is the ownership block's whole decision, with no side |
| +// effect: serve here, refuse, or send elsewhere. ServeHTTP acts on it |
| +// (serveNameOwner) and an admitted upgrade's reservation and sweep keep only |
| +// ownerLocal (upgradeSelection), so a request and an upgrade on the same |
| +// name and path are always judged alike (TestUpgradeOwnershipAgreesWithDispatch). |
| +// |
| +// It includes the legacy local fallback: a name another box owns, on a |
| +// request that is neither a hop nor a door call, when no mesh key is |
| +// mirrored (nothing can sign the backhaul, and the far asset catch needs the |
| +// key too), is served here (ownerLocal) unless the owner is admission-aware |
| +// or the request is a case 3 target (ownerRefused). |
| // |
| // The NAME is judged by the request Host's own entry here (sel.Front: an |
| // exact route, an attached alias, a catch-all), never by a path-selected |
| @@ -157,12 +172,21 @@ func (e *Edge) nameOwnerVerdict(host string, sel requestSelection, hopped, isDoo |
| if class == edgesfile.NameAlias { |
| local.TargetHost = id.route.Host |
| } |
| - resolved := e.homes.Load().resolveName(host, []edgesfile.NameClaim{local}, false) |
| + m := e.homes.Load() |
| + resolved := m.resolveName(host, []edgesfile.NameClaim{local}, false) |
| switch { |
| case resolved.State == edgesfile.NameHeld: |
| return ownerHeld, resolved |
| case resolved.State == edgesfile.NameDialable && !resolved.Serving.Local && (resolved.AdmissionAware || (!hopped && !isDoor)): |
| - return ownerElsewhere, resolved |
| + // backhaulTo answers an empty dial address itself (503), ahead of |
| + // the key check, so only a dialable owner with no key falls back. |
| + if hopped || isDoor || resolved.Serving.Dial == "" || len(signingKey(m.meshKeys())) > 0 { |
| + return ownerElsewhere, resolved |
| + } |
| + if resolved.AdmissionAware || up.front != nil { |
| + return ownerRefused, resolved |
| + } |
| + return ownerLocal, resolved |
| case up.front != nil: |
| return ownerRefused, resolved |
| } |
| @@ -170,9 +194,10 @@ func (e *Edge) nameOwnerVerdict(host string, sel requestSelection, hopped, isDoo |
| } |
| // serveNameOwner is ServeHTTP's ownership block: it acts on |
| -// nameOwnerVerdict and reports whether it answered. A held exact name |
| -// refuses even a signed hop; a hop or door request never starts another |
| -// backhaul here. |
| +// nameOwnerVerdict and reports whether it answered. It falls through (serves |
| +// here) exactly when the verdict is ownerLocal. A held exact name refuses |
| +// even a signed hop; a hop or door request never starts another backhaul |
| +// here. |
| func (e *Edge) serveNameOwner(w http.ResponseWriter, r *http.Request, host string, sel requestSelection, hopped, isDoor bool) bool { |
| v, resolved := e.nameOwnerVerdict(host, sel, hopped, isDoor) |
| switch v { |
| @@ -193,14 +218,11 @@ func (e *Edge) serveNameOwner(w http.ResponseWriter, r *http.Request, host strin |
| if e.serveAssetFar(w, r, host) || e.backhaulTo(w, r, host, resolved.Serving.Dial, resolved.Serving.Box, backhaulOwnerOf(resolved.Authority)) { |
| return true |
| } |
| - // A known remote owner must not fall through to another local app when |
| - // its mesh key or transport is unavailable, nor a case 3 target whose |
| - // front has moved. |
| - if resolved.AdmissionAware || sel.Up.front != nil { |
| - AdmissionResponse(w, r) |
| - return true |
| - } |
| - return false |
| + // The verdict saw a key, and the backhaul found none: the key went |
| + // between the two reads. The name was judged to belong elsewhere, so it |
| + // is not served here (only ownerLocal is); the next request judges again. |
| + AdmissionResponse(w, r) |
| + return true |
| } |
| // upgradeSelection is the selection an admitted upgrade is re-checked against |
| @@ -209,9 +231,11 @@ func (e *Edge) serveNameOwner(w http.ResponseWriter, r *http.Request, host strin |
| // verified hop and door hop marks), so a target selected for a front this |
| // box does not serve (case 3) still maps to the tenancy it was admitted |
| // under while its front holds. A Remote selection is no upstream here, and |
| -// neither is one ServeHTTP's ownership block would not serve here |
| -// (nameOwnerVerdict): a name another box now owns, or holds, loses its |
| -// upgrade whatever tenancy a local catch-all would lend it. |
| +// neither is one ServeHTTP's ownership block would not serve here: only |
| +// nameOwnerVerdict's ownerLocal keeps it, the verdict under which dispatch |
| +// serves locally, so a name another box now owns, or holds, loses its |
| +// upgrade whatever tenancy a local catch-all would lend it, and a name the |
| +// legacy no-key fallback serves here keeps it. |
| func (e *Edge) upgradeSelection(ctx context.Context, host, urlPath string) (upstream, bool) { |
| sel := e.selectUpstream(new(http.Request).WithContext(ctx), host, urlPath) |
| if !sel.OK { |