Before the catalog half's first views are in (a read refused, or none-yet), the keeper reads the manifest on the trunk of the holder of the seat mesh-catalog from the seat's states modules and manifests (the holder from the seat that places modules) and makes its kept data as any module's, each entry said as ever; every other module waits as A-367 says. Builds: design 47 G A-376 (G-22-lead-answers-2.md) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
67 lines
3.1 KiB
Go
67 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
|
|
"git.novox.be/novox/mesh-sdk/go/seatlist"
|
|
|
|
"nats-tools/internal/keeper"
|
|
)
|
|
|
|
// The keeper makes the kept data of the holder of the seat mesh-catalog before the catalog half's first views are in (design
|
|
// 47 G A-376, completing A-367): that holder is the catalog half's own source and needs its kept data to answer them. Its
|
|
// manifest on the trunk is read as the holder's first views `modules` (the manifest's digest by module) and `manifests` (the
|
|
// manifest by digest) give it, both followed as the seat's states (views.ProcessReader.FollowSeat), and the holder is the
|
|
// module the seat that places modules answers for the seat (seatlist.HolderOf): no module is named here.
|
|
|
|
// holderAccepted is what the holder's manifest on the trunk asks of the bus: the holder's entry of `modules` names its
|
|
// manifest's digest, and `manifests` holds that manifest. An error says what is not yet in.
|
|
func holderAccepted(holder string, modules, manifests map[string]json.RawMessage) (keeper.Accepted, error) {
|
|
raw, ok := modules[holder]
|
|
if !ok {
|
|
return keeper.Accepted{}, fmt.Errorf("the first view `modules` holds no entry of %s yet", holder)
|
|
}
|
|
// Only the manifest's digest is read of the entry, so an entry whose fingerprint is not (yet) there still names it.
|
|
var v struct {
|
|
Manifest string `json:"manifest"`
|
|
}
|
|
if err := json.Unmarshal(raw, &v); err != nil {
|
|
return keeper.Accepted{}, fmt.Errorf("the entry of %s in `modules` does not read: %w", holder, err)
|
|
}
|
|
if v.Manifest == "" {
|
|
return keeper.Accepted{}, fmt.Errorf("the entry of %s in `modules` names no manifest", holder)
|
|
}
|
|
m, ok := manifests[v.Manifest]
|
|
if !ok {
|
|
return keeper.Accepted{}, fmt.Errorf("the first view `manifests` holds no manifest %s of %s yet", v.Manifest, holder)
|
|
}
|
|
var by catalog.ManifestsByDigestValue
|
|
if err := json.Unmarshal(m, &by); err != nil {
|
|
return keeper.Accepted{}, fmt.Errorf("the manifest %s of %s does not read: %w", v.Manifest, holder, err)
|
|
}
|
|
var manifest map[string]any
|
|
if err := json.Unmarshal([]byte(by.Manifest), &manifest); err != nil {
|
|
return keeper.Accepted{}, fmt.Errorf("the manifest %s of %s does not read: %w", v.Manifest, holder, err)
|
|
}
|
|
a, err := AsksOf(catalog.CatalogEntry{Module: holder, Manifest: manifest})
|
|
if err != nil {
|
|
return keeper.Accepted{}, err
|
|
}
|
|
return a.Accepted, nil
|
|
}
|
|
|
|
// holder is the keeper's Holder: the seat's holder through the seat that places modules, its two states followed as the
|
|
// seat's, nothing asked on a timer (the follows read the holder again at each change of a view the reader follows).
|
|
func (f *catalogFollow) holder() (keeper.Accepted, error) {
|
|
if f.holderModules == nil || f.holderManifests == nil {
|
|
return keeper.Accepted{}, fmt.Errorf("the seat %s's states are not followed", catalog.Seat)
|
|
}
|
|
who, err := seatlist.HolderOf(f.call, catalog.Seat)
|
|
if err != nil {
|
|
return keeper.Accepted{}, err
|
|
}
|
|
return holderAccepted(who, f.holderModules.Follower().Values(), f.holderManifests.Follower().Values())
|
|
}
|