BL6 (ba43e400) kept KeyPart and ParseKeyPart in meshcatalogclient until the callers moved; they have, so the wrappers and their duplicate test go. Builds: design 47 G §670 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"sort"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient"
|
|
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey"
|
|
)
|
|
|
|
// Every node's published compositions, read only to compare (novox/hq ADR 0593 §8): each node's engine writes its own
|
|
// `composed-<node>` (buckets.ComposedRead, one bucket per node), and `mesh-wants.upgrade` with compare names, for every
|
|
// node, the composition its own have runs beside the newest it published of each module and of the node, so a person sees
|
|
// where they part. The assigner composes nothing and never writes these.
|
|
|
|
// publishedRow is one composition a node published: the module ("node" for its own), the fingerprint, the digest, or why
|
|
// it was refused or cannot be read.
|
|
type publishedRow struct {
|
|
Key string `json:"key"`
|
|
Module string `json:"module"`
|
|
FP string `json:"fp,omitempty"`
|
|
Digest string `json:"digest,omitempty"`
|
|
Refused string `json:"refused,omitempty"`
|
|
Unread string `json:"unread,omitempty"`
|
|
}
|
|
|
|
// published is, by node, every composition it published, sorted by key, from every key of the per-node state (a key
|
|
// names its node first): each value decoded and digested here, as the node-engine digests it (nodeengineclient.ComposedDigest).
|
|
// A value or key that does not read is named with why, never left out.
|
|
func published(values map[string][]byte) map[string][]publishedRow {
|
|
byNode := map[string]map[string][]byte{}
|
|
for key, raw := range values {
|
|
node, _, _ := strings.Cut(key, ".")
|
|
if byNode[node] == nil {
|
|
byNode[node] = map[string][]byte{}
|
|
}
|
|
byNode[node][key] = raw
|
|
}
|
|
out := map[string][]publishedRow{}
|
|
for node, keys := range byNode {
|
|
var rows []publishedRow
|
|
for key, raw := range keys {
|
|
row := publishedRow{Key: key}
|
|
_, module, part, isNode, err := nodeengineclient.ParseComposedKey(key)
|
|
var fp string
|
|
if err == nil && !isNode {
|
|
fp, err = meshcatalogkey.ParseKeyPart(part)
|
|
}
|
|
switch {
|
|
case err != nil:
|
|
row.Unread = err.Error()
|
|
case isNode:
|
|
row.Module = "node"
|
|
default:
|
|
row.Module, row.FP = module, fp
|
|
}
|
|
if err == nil {
|
|
c, derr := nodeengineclient.DecodeComposition(raw)
|
|
switch {
|
|
case derr != nil:
|
|
row.Unread = derr.Error()
|
|
case c.Refused != "":
|
|
row.Refused = c.Refused
|
|
default:
|
|
if d, err := nodeengineclient.ComposedDigest(c); err != nil {
|
|
row.Unread = err.Error()
|
|
} else {
|
|
row.Digest = d
|
|
}
|
|
}
|
|
}
|
|
rows = append(rows, row)
|
|
}
|
|
sort.Slice(rows, func(i, j int) bool { return rows[i].Key < rows[j].Key })
|
|
out[node] = rows
|
|
}
|
|
return out
|
|
}
|