Files
mesh-host/internal/compositions/candidate.go
T
jschoubben 8717ec76d4 The node-engine follows the module-assignment seat: assignments, not placement; the seat's packages move to mesh-contracts and mesh-delivery (issue 1966)
The state, events and types of the seat mesh-module-assigner say assignments; the legacy node key form is gone from the
reads; the dead seat-verb list of the retired name is deleted. The placement guard and the placed-file sense stay.

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
2026-11-05 22:08:40 +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 assignment key away.
const ReturnsToNothing = "the proposal takes this node's assignment 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
}