Node-engine: the placement, the wants and the placement candidates are the seats' contract types and the assigner client's keys and codecs; the found tunnel is the placement seat's typed record (ADR 0634 §1, §4; issue 1966)

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
2026-11-05 15:34:02 +01:00
parent 7eb7b9fa62
commit c35cc1d9e4
26 changed files with 489 additions and 390 deletions
+35 -32
View File
@@ -21,6 +21,9 @@ import (
"fmt"
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-contracts/placement/go/clients/meshmoduleassignerclient"
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshmoduleassigner"
"git.novox.be/novox/mesh-contracts/placement/go/seats/meshwants"
"github.com/novox/mesh-host/internal/buckets"
"github.com/novox/mesh-host/internal/compositions"
engcomp "github.com/novox/mesh-host/internal/compositions"
@@ -129,11 +132,11 @@ type Composer struct {
env Env
mu sync.Mutex
wants map[string]delivery.Want // by module, the node's own under agent.NodeModule
placements map[string]delivery.Placement
wants map[string]meshwants.WantsByWantNodeModuleValue // by module, the node's own under agent.NodeModule
placements map[string]meshmoduleassigner.Placement
// placementKeys is the seat's state placement key by key in either form, each node's placement assembled from it
// (delivery.PlacementKeys; research 072 row 37): a write of the holder's under way is never composed half.
placementKeys *delivery.PlacementKeys
// (meshmoduleassignerclient.Keys; research 072 row 37): a write of the holder's under way is never composed half.
placementKeys *meshmoduleassignerclient.Keys
records map[string]nodeengine.NodeRecord
// inOwn is, by module, whether this node's have of it names no fingerprint of the new form (mesh-wireguard, a module
// at a build of the old form): the node runs it inside its own composition, and composes it there again (issue 1126).
@@ -300,7 +303,7 @@ func New(env Env) *Composer {
if env.Say == nil {
env.Say = func(string) {}
}
return &Composer{env: env, wants: map[string]delivery.Want{}, placements: map[string]delivery.Placement{}, placementKeys: delivery.NewPlacementKeys(),
return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, placements: map[string]meshmoduleassigner.Placement{}, placementKeys: meshmoduleassignerclient.NewKeys(),
records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, modules: map[string]delivery.Module{}, values: map[string]map[string]any{},
manifests: map[string][]byte{}, archives: map[string][]byte{}, builds: map[string]delivery.BuilderBuild{}, handed: map[string]string{}, sealedOwn: map[string]ownSealed{},
pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)}
@@ -355,8 +358,8 @@ type input struct {
func (c *Composer) inputs() []input {
node := c.env.Node
return []input{
{delivery.AssignerWantsBucket, "want." + node + ".>", (*Composer).takeWant, nil},
{delivery.PlacementBucket, ">", (*Composer).takePlacement, nil},
{buckets.Wants, "want." + node + ".>", (*Composer).takeWant, nil},
{buckets.Placement, ">", (*Composer).takePlacement, nil},
// Every node's record, and this node's own haves (what it runs inside its own composition): two watches, each
// within the node's grant (buscompose: readGrants of the have bucket at `*.node`, NodeKeysGrants at `<node>.>`).
// A watch of every key is refused by the bus (issue 1126, 2026-10-27 09:21: the fold's `>` stopped every agent).
@@ -395,7 +398,7 @@ func (c *Composer) takeBuildDone(u agent.Update) bool {
c.mu.Unlock()
// A module placed here is composed at its trunk's build once that is done, for the composition state, before its
// want moves (ADR 0593 §6).
if !(wanted && w.FP == fp) && !((wanted || placedHere) && m.FP2 == fp) {
if !(wanted && w.Fp == fp) && !((wanted || placedHere) && m.FP2 == fp) {
return false
}
b, err := delivery.DecodeBuilderBuild(u.Value)
@@ -604,22 +607,22 @@ func (c *Composer) entry(bucket, key string) (v any, has, known bool) {
c.mu.Lock()
defer c.mu.Unlock()
switch bucket {
case delivery.AssignerWantsBucket:
case buckets.Wants:
// A want is composed by its fingerprint alone (fingerprints); its words, rule and newest change nothing composed.
module := agent.NodeModule
if _, err := delivery.ParseWantNodeKey(key); err != nil {
node, m, err := delivery.ParseWantKey(key)
if err != nil || node != c.env.Node {
if _, ok := meshwants.ParseWantsByWantNodeNodeKey(key); !ok {
node, m, ok := meshwants.ParseWantsByWantNodeModuleKey(key)
if !ok || node != c.env.Node {
return nil, false, true
}
module = m
}
w, ok := c.wants[module]
return w.FP, ok, true
case delivery.PlacementBucket:
return w.Fp, ok, true
case buckets.Placement:
// Any key of a node, its node key, a module key or its legacy key, stands for the node's whole placement: a
// module key written before its node key names it changes nothing composed.
node, _, _, err := delivery.ParsePlacementKey(key)
node, _, _, err := meshmoduleassignerclient.ParseKey(key)
if err != nil {
return nil, false, true
}
@@ -650,20 +653,20 @@ func (c *Composer) entry(bucket, key string) (v any, has, known bool) {
func (c *Composer) takeWant(u agent.Update) {
c.mu.Lock()
defer c.mu.Unlock()
if _, err := delivery.ParseWantNodeKey(u.Key); err == nil {
if _, ok := meshwants.ParseWantsByWantNodeNodeKey(u.Key); ok {
if u.Deleted {
delete(c.wants, agent.NodeModule)
} else {
c.wants[agent.NodeModule] = delivery.Want{}
c.wants[agent.NodeModule] = meshwants.WantsByWantNodeModuleValue{}
}
return
}
node, module, err := delivery.ParseWantKey(u.Key)
if err != nil || node != c.env.Node {
node, module, ok := meshwants.ParseWantsByWantNodeModuleKey(u.Key)
if !ok || node != c.env.Node {
return
}
w, err := delivery.DecodeWant(u.Value)
if u.Deleted || err != nil || w.Removed || w.FP == "" {
w, err := meshwants.DecodeWantsByWantNodeModuleValue(u.Value)
if u.Deleted || err != nil || w.Removed || w.Fp == "" {
delete(c.wants, module)
return
}
@@ -676,7 +679,7 @@ func (c *Composer) takePlacement(u agent.Update) {
}
c.mu.Lock()
if c.placementKeys == nil {
c.placementKeys = delivery.NewPlacementKeys()
c.placementKeys = meshmoduleassignerclient.NewKeys()
}
node, err := c.placementKeys.Put(u.Key, u.Value, u.Revision, u.Deleted || len(u.Value) == 0)
if node != "" {
@@ -769,7 +772,7 @@ func (c *Composer) Machines() (byAddress map[string]string, hub string) {
return byAddress, hub
}
func (c *Composer) inOwnOf(p delivery.Placement) []string {
func (c *Composer) inOwnOf(p meshmoduleassigner.Placement) []string {
var out []string
for _, m := range p.Modules {
if c.inOwn[m.Module] {
@@ -859,8 +862,8 @@ func (c *Composer) compose(ctx context.Context) []agent.Update {
if module == agent.NodeModule {
continue
}
fps[module] = w.FP
if m, ok := c.modules[module]; ok && m.FP2 != w.FP {
fps[module] = w.Fp
if m, ok := c.modules[module]; ok && m.FP2 != w.Fp {
behind = append(behind, module)
}
}
@@ -1310,7 +1313,7 @@ var _ frombus.SignersReader = reader{}
// certificateWanted says whether a module the placement p puts on this node asks for a certificate for the machine's
// internal name (its manifest's `certificate`), read from the indexer's manifests; a manifest that cannot be read is
// taken as asking none, and the composition says what it misses.
func (c *Composer) certificateWanted(ctx context.Context, r reader, p delivery.Placement) bool {
func (c *Composer) certificateWanted(ctx context.Context, r reader, p meshmoduleassigner.Placement) bool {
for _, m := range p.Modules {
c.mu.Lock()
digest := c.modules[m.Module].Manifest
@@ -1338,7 +1341,7 @@ func (c *Composer) certificateWanted(ctx context.Context, r reader, p delivery.P
// certifyIfWanted asks Certify once per serving key when a module placed here asks for a certificate and this node's
// record holds none for its internal name and serving key from an authority it trusts (the one it holds, or the vault's).
func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p delivery.Placement) {
func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p meshmoduleassigner.Placement) {
if c.env.Certify == nil || !c.certificateWanted(ctx, r, p) {
return
}
@@ -1367,10 +1370,10 @@ func (c *Composer) certifyIfWanted(ctx context.Context, r reader, p delivery.Pla
c.mu.Unlock()
}
func (r reader) Placements(context.Context) (map[string]delivery.Placement, error) {
func (r reader) Placements(context.Context) (map[string]meshmoduleassigner.Placement, error) {
r.c.mu.Lock()
defer r.c.mu.Unlock()
out := make(map[string]delivery.Placement, len(r.c.placements))
out := make(map[string]meshmoduleassigner.Placement, len(r.c.placements))
for k, v := range r.c.placements {
out[k] = v
}
@@ -1719,9 +1722,9 @@ func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string
if m == agent.NodeModule {
continue
}
fps[m] = w.FP
if mm, ok := c.modules[m]; ok && mm.FP2 != w.FP {
kept[m] = w.FP
fps[m] = w.Fp
if mm, ok := c.modules[m]; ok && mm.FP2 != w.Fp {
kept[m] = w.Fp
}
}
fps[module] = fp