Files
mesh-host/internal/compositions/candidate.go
T
jschoubben 5906e18028 Node-engine: a composition, its codec, digest and keys come from the node-engine client; the candidate answer and its limits from the seat's contract; the declared packages are the engine's own (H-2, H-3, ADR 0634 §1; issue 1966)
The engine's Composed keeps the catalogue's Plan and the declaration types and goes through nodeengineclient's codec; the fingerprint key part is meshcatalogclient's. The candidate answer is nodeengine.CandidateAnswer; the have still holds it through an interim JSON bridge (link.interimAnswers) until the Have group moves.

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
2026-11-05 15:10:45 +01:00

54 lines
2.1 KiB
Go

package compositions
import (
seat "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-contracts/identity-and-access/go/clients/meshvaultclient"
)
// The bounds of a module's shown bodies in a candidate answer, and of one answer as the node's key holds it (the node-engine
// seat's state have, key `<node>.node`, takes a value of about 1 MiB and holds every proposal's answer beside the node's
// facts, so one answer keeps to a sixth).
const (
MaxBodies = 20
MaxBody = 8192
MaxPaths = 64
MaxAnswerBytes = 160 << 10
)
// ReturnsToNothing is what a node answers a proposal that takes its placement key away.
const ReturnsToNothing = "the proposal takes this node's placement away: it composes nothing then"
// NodeWord is the last part of a node's own key, and the name of its own composition in an answer.
const NodeWord = "node"
// VerdictOf is the verdict of an answer's lists: refused on any refusal, differs on any difference, addition or
// removal, same otherwise.
func VerdictOf(a seat.CandidateAnswer) string {
switch {
case a.Refused != "" || len(a.Refusals) > 0:
return seat.CandidateAnswerVerdictRefused
case len(a.Differs)+len(a.Added)+len(a.Removed) > 0:
return seat.CandidateAnswerVerdictDiffers
}
return seat.CandidateAnswerVerdictSame
}
// WithValuesDiffer is answers with each one's ValuesDiffer counted: how many shown bodies hold a value the node opened on
// both sides to two values (the vault's value and the one that runs drifted apart; issue 1126, cause C4).
func WithValuesDiffer(answers map[string]seat.CandidateAnswer) map[string]seat.CandidateAnswer {
out := make(map[string]seat.CandidateAnswer, len(answers))
for g, a := range answers {
var shown []meshvaultclient.ModuleBodies
for _, d := range a.Differs {
m := meshvaultclient.ModuleBodies{Module: d.Module}
for _, b := range d.Bodies {
m.Bodies = append(m.Bodies, meshvaultclient.Body{ID: b.ID, Composed: b.Composed, Running: b.Running})
}
shown = append(shown, m)
}
a.ValuesDiffer = int64(meshvaultclient.ValuesDiffer(shown))
out[g] = a
}
return out
}