Files
mesh-contracts/placement/go/seats/meshmoduleassigner/contract.go
T

686 lines
25 KiB
Go

// Code generated by seatgen from the seat definitions; DO NOT EDIT.
// Package meshmoduleassigner is the contract of the seat "mesh-module-assigner", defined whole (seats/mesh-module-assigner/seat.json): The seat that places modules on nodes (ADR 0567): the state of placement and the proposals that change it. Renamed from mesh-placement (ADR 0634 §9).
package meshmoduleassigner
import (
"bytes"
"encoding/json"
"errors"
"strings"
"time"
)
// Seat is the seat's name.
const Seat = "mesh-module-assigner"
const (
VerbPlacement = "placement"
VerbProposals = "proposals"
VerbPropose = "propose"
VerbWithdraw = "withdraw"
VerbAgain = "again"
)
const (
EventPlacementProposed = "placement-proposed"
EventPlacementWithdrawn = "placement-withdrawn"
EventPlacementJudged = "placement-judged"
EventPlacementChanged = "placement-changed"
)
// Verbs is every verb the seat serves, in its definition's order: a new copy each call.
func Verbs() []string {
return []string{VerbPlacement, VerbProposals, VerbPropose, VerbWithdraw, VerbAgain}
}
// Events is every event published on the seat's subject: a new copy each call.
func Events() []string {
return []string{EventPlacementProposed, EventPlacementWithdrawn, EventPlacementJudged, EventPlacementChanged}
}
// Family is where the seat's events are kept: the shared events stream, filtered to the seat's subjects.
const (
Family = "mesh-module-assigner.events"
FamilyMaxAgeDays = 7
)
// SubjectPlacementProposed is where placement-proposed is published.
const SubjectPlacementProposed = "mesh.seat.mesh-module-assigner.event.placement-proposed"
// SubjectPlacementWithdrawn is where placement-withdrawn is published.
const SubjectPlacementWithdrawn = "mesh.seat.mesh-module-assigner.event.placement-withdrawn"
// SubjectPlacementJudged is where placement-judged is published.
const SubjectPlacementJudged = "mesh.seat.mesh-module-assigner.event.placement-judged"
// SubjectPlacementChanged is where placement-changed is published.
const SubjectPlacementChanged = "mesh.seat.mesh-module-assigner.event.placement-changed"
const (
StatePlacement = "placement"
StateProposals = "proposals"
StateCandidates = "candidates"
StatePulses = "pulses"
StateSeatHolders = "seat-holders"
)
// PlacementByNodeNodeKey is the key of one value of the state placement under the form "<node>.node".
func PlacementByNodeNodeKey(node string) string { return node + ".node" }
// ParsePlacementByNodeNodeKey reads the parts of a key of the form "<node>.node", in the order of the form; the last result is false for a key of another form.
func ParsePlacementByNodeNodeKey(key string) (string, bool) {
rest := key
v0, after0, found0 := strings.Cut(rest, ".node")
if !found0 || v0 == "" {
return "", false
}
rest = after0
if rest != "" {
return "", false
}
return v0, true
}
// DecodePlacementByNodeNodeValue reads one value of the state placement under the form "<node>.node", refusing a field PlacementByNodeNodeValue does not know and any text after the value.
func DecodePlacementByNodeNodeValue(raw []byte) (PlacementByNodeNodeValue, error) {
var v PlacementByNodeNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// PlacementByNodeModuleKey is the key of one value of the state placement under the form "<node>.<module>".
func PlacementByNodeModuleKey(node, module string) string { return node + "." + module }
// ParsePlacementByNodeModuleKey reads the parts of a key of the form "<node>.<module>", in the order of the form; the last result is false for a key of another form.
func ParsePlacementByNodeModuleKey(key string) (string, string, bool) {
rest := key
v0, after0, found0 := strings.Cut(rest, ".")
if !found0 || v0 == "" {
return "", "", false
}
rest = after0
if rest == "" {
return "", "", false
}
v2 := rest
rest = ""
if rest != "" {
return "", "", false
}
return v0, v2, true
}
// DecodePlacementByNodeModuleValue reads one value of the state placement under the form "<node>.<module>", refusing a field PlacementByNodeModuleValue does not know and any text after the value.
func DecodePlacementByNodeModuleValue(raw []byte) (PlacementByNodeModuleValue, error) {
var v PlacementByNodeModuleValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// ProposalsByProposalKey is the key of one value of the state proposals under the form "<proposal>".
func ProposalsByProposalKey(proposal string) string { return proposal }
// ParseProposalsByProposalKey reads the parts of a key of the form "<proposal>", in the order of the form; the last result is false for a key of another form.
func ParseProposalsByProposalKey(key string) (string, bool) {
rest := key
if rest == "" {
return "", false
}
v0 := rest
rest = ""
if rest != "" {
return "", false
}
return v0, true
}
// DecodeProposalsByProposalValue reads one value of the state proposals under the form "<proposal>", refusing a field ProposalsByProposalValue does not know and any text after the value.
func DecodeProposalsByProposalValue(raw []byte) (ProposalsByProposalValue, error) {
var v ProposalsByProposalValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// CandidatesByProposalNodeKey is the key of one value of the state candidates under the form "<proposal>.<node>".
func CandidatesByProposalNodeKey(proposal, node string) string { return proposal + "." + node }
// ParseCandidatesByProposalNodeKey reads the parts of a key of the form "<proposal>.<node>", in the order of the form; the last result is false for a key of another form.
func ParseCandidatesByProposalNodeKey(key string) (string, string, bool) {
rest := key
v0, after0, found0 := strings.Cut(rest, ".")
if !found0 || v0 == "" {
return "", "", false
}
rest = after0
if rest == "" {
return "", "", false
}
v2 := rest
rest = ""
if rest != "" {
return "", "", false
}
return v0, v2, true
}
// DecodeCandidatesByProposalNodeValue reads one value of the state candidates under the form "<proposal>.<node>", refusing a field CandidatesByProposalNodeValue does not know and any text after the value.
func DecodeCandidatesByProposalNodeValue(raw []byte) (CandidatesByProposalNodeValue, error) {
var v CandidatesByProposalNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// PulsesByAnswerProposalNodeKey is the key of one value of the state pulses under the form "answer.<proposal>.<node>".
func PulsesByAnswerProposalNodeKey(proposal, node string) string {
return "answer." + proposal + "." + node
}
// ParsePulsesByAnswerProposalNodeKey reads the parts of a key of the form "answer.<proposal>.<node>", in the order of the form; the last result is false for a key of another form.
func ParsePulsesByAnswerProposalNodeKey(key string) (string, string, bool) {
rest := key
if !strings.HasPrefix(rest, "answer.") {
return "", "", false
}
rest = rest[7:]
v1, after1, found1 := strings.Cut(rest, ".")
if !found1 || v1 == "" {
return "", "", false
}
rest = after1
if rest == "" {
return "", "", false
}
v3 := rest
rest = ""
if rest != "" {
return "", "", false
}
return v1, v3, true
}
// DecodePulsesByAnswerProposalNodeValue reads one value of the state pulses under the form "answer.<proposal>.<node>", refusing a field PulsesByAnswerProposalNodeValue does not know and any text after the value.
func DecodePulsesByAnswerProposalNodeValue(raw []byte) (PulsesByAnswerProposalNodeValue, error) {
var v PulsesByAnswerProposalNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// PulsesByAskProposalKey is the key of one value of the state pulses under the form "ask.<proposal>".
func PulsesByAskProposalKey(proposal string) string { return "ask." + proposal }
// ParsePulsesByAskProposalKey reads the parts of a key of the form "ask.<proposal>", in the order of the form; the last result is false for a key of another form.
func ParsePulsesByAskProposalKey(key string) (string, bool) {
rest := key
if !strings.HasPrefix(rest, "ask.") {
return "", false
}
rest = rest[4:]
if rest == "" {
return "", false
}
v1 := rest
rest = ""
if rest != "" {
return "", false
}
return v1, true
}
// DecodePulsesByAskProposalValue reads one value of the state pulses under the form "ask.<proposal>", refusing a field PulsesByAskProposalValue does not know and any text after the value.
func DecodePulsesByAskProposalValue(raw []byte) (PulsesByAskProposalValue, error) {
var v PulsesByAskProposalValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// SeatHoldersBySeatKey is the key of one value of the state seat-holders under the form "<seat>".
func SeatHoldersBySeatKey(seat string) string { return seat }
// ParseSeatHoldersBySeatKey reads the parts of a key of the form "<seat>", in the order of the form; the last result is false for a key of another form.
func ParseSeatHoldersBySeatKey(key string) (string, bool) {
rest := key
if rest == "" {
return "", false
}
v0 := rest
rest = ""
if rest != "" {
return "", false
}
return v0, true
}
// DecodeSeatHoldersBySeatValue reads one value of the state seat-holders under the form "<seat>", refusing a field SeatHoldersBySeatValue does not know and any text after the value.
func DecodeSeatHoldersBySeatValue(raw []byte) (SeatHoldersBySeatValue, error) {
var v SeatHoldersBySeatValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// SeatHoldersBySeatNodeKey is the key of one value of the state seat-holders under the form "<seat>.<node>".
func SeatHoldersBySeatNodeKey(seat, node string) string { return seat + "." + node }
// ParseSeatHoldersBySeatNodeKey reads the parts of a key of the form "<seat>.<node>", in the order of the form; the last result is false for a key of another form.
func ParseSeatHoldersBySeatNodeKey(key string) (string, string, bool) {
rest := key
v0, after0, found0 := strings.Cut(rest, ".")
if !found0 || v0 == "" {
return "", "", false
}
rest = after0
if rest == "" {
return "", "", false
}
v2 := rest
rest = ""
if rest != "" {
return "", "", false
}
return v0, v2, true
}
// DecodeSeatHoldersBySeatNodeValue reads one value of the state seat-holders under the form "<seat>.<node>", refusing a field SeatHoldersBySeatNodeValue does not know and any text after the value.
func DecodeSeatHoldersBySeatNodeValue(raw []byte) (SeatHoldersBySeatNodeValue, error) {
var v SeatHoldersBySeatNodeValue
dec := json.NewDecoder(bytes.NewReader(raw))
dec.DisallowUnknownFields()
if err := dec.Decode(&v); err != nil {
return v, err
}
if dec.More() {
return v, errors.New("text after the value")
}
return v, nil
}
// FoundTunnel is a tunnel found on the machine when it was adopted: everything but its private key.
type FoundTunnel struct {
Address string `json:"address,omitempty"`
Config string `json:"config,omitempty"`
Interface string `json:"interface"`
Mtu int64 `json:"mtu,omitempty"`
Peers []FoundTunnelPeer `json:"peers,omitempty"`
Port int64 `json:"port,omitempty"`
PublicKey string `json:"public-key,omitempty"`
Range string `json:"range,omitempty"`
Unit string `json:"unit,omitempty"`
}
// FoundTunnelPeer is one peer of a found tunnel.
type FoundTunnelPeer struct {
Address string `json:"address,omitempty"`
PublicKey string `json:"public-key"`
}
// Holding is one seat a module placed on the node holds.
type Holding struct {
Claim string `json:"claim"`
Kind string `json:"kind,omitempty"`
Module string `json:"module"`
Scope string `json:"scope,omitempty"`
Site string `json:"site,omitempty"`
}
// NodeDecided is what a person decides of a node; no secret and no key material.
type NodeDecided struct {
Account string `json:"account,omitempty"`
AccountHome string `json:"account-home,omitempty"`
Address string `json:"address,omitempty"`
Adopted bool `json:"adopted,omitempty"`
AgentAccount string `json:"agent-account,omitempty"`
AgentAccountHome string `json:"agent-account-home,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Hub bool `json:"hub,omitempty"`
// on the hub, the name a person gave a peer of that tunnel, by its public key
PeerNames map[string]string `json:"peer-names,omitempty"`
PublicDomain string `json:"public-domain,omitempty"`
Site string `json:"site,omitempty"`
Taken []string `json:"taken,omitempty"`
// the tunnel found on the node when it was adopted
Tunnel *FoundTunnel `json:"tunnel,omitempty"`
}
// PlacedModule is one module placed on a node.
type PlacedModule struct {
// by provision, the provider each requirement that keeps data is bound to
Bindings map[string]Provider `json:"bindings,omitempty"`
HasLayer bool `json:"has-layer,omitempty"`
HasMeshWide bool `json:"has-mesh-wide,omitempty"`
// this node's settings layer of the module's placement
Layer map[string]any `json:"layer,omitempty"`
// the whole mesh's settings layer of the module's placement
MeshWide map[string]any `json:"mesh-wide,omitempty"`
// config values a person set in the whole mesh's layer, for a module in the settings form
MeshWideValues map[string]any `json:"mesh-wide-values,omitempty"`
Module string `json:"module"`
// the host port each declared port is published on, by the port the software listens on
Ports map[string]int64 `json:"ports,omitempty"`
// config values a person set in this node's layer, for a module in the settings form
Values map[string]any `json:"values,omitempty"`
}
// Placement is one node's placement assembled.
type Placement struct {
Decided NodeDecided `json:"decided"`
Holds []Holding `json:"holds,omitempty"`
Modules []PlacedModule `json:"modules"`
Node string `json:"node"`
// by provision, the provider chosen for the node
Pins map[string]Provider `json:"pins,omitempty"`
Revision string `json:"revision,omitempty"`
V int64 `json:"v,omitempty"`
}
// PlacementEventWarrant is who approved it, through which channel, when.
type PlacementEventWarrant struct {
At time.Time `json:"at"`
Warrant string `json:"warrant"`
Words string `json:"words"`
}
// PlacementEvent is what each placement event carries.
type PlacementEvent struct {
// for placement-withdrawn, why it ended
Ended string `json:"ended,omitempty"`
// for placement-changed, by node the revisions before and after and the modules added, removed or changed
Nodes []map[string]any `json:"nodes,omitempty"`
Proposal Proposal `json:"proposal"`
// who approved it, through which channel, when
Warrant *PlacementEventWarrant `json:"warrant,omitempty"`
}
// Proposal is an open proposal.
type Proposal struct {
Again *time.Time `json:"again,omitempty"`
Ask string `json:"ask,omitempty"`
At time.Time `json:"at"`
// by node whose key it changes, the revision of the key it was laid over (0: none)
Base map[string]int64 `json:"base"`
By string `json:"by"`
Changes []ProposalChange `json:"changes"`
ExportDigest string `json:"export-digest,omitempty"`
HandBack bool `json:"hand-back,omitempty"`
ID string `json:"id"`
Must []string `json:"must,omitempty"`
Seed bool `json:"seed,omitempty"`
// answering, failed or asked
State string `json:"state"`
V int64 `json:"v,omitempty"`
Verdict *Verdict `json:"verdict,omitempty"`
Warrant *Warrant `json:"warrant,omitempty"`
Why string `json:"why"`
Withdrawn string `json:"withdrawn,omitempty"`
Words string `json:"words,omitempty"`
Written *time.Time `json:"written,omitempty"`
}
// ProposalChangeKeys is the public halves of a joining node's keys.
type ProposalChangeKeys struct {
Identity string `json:"identity"`
Overlay string `json:"overlay,omitempty"`
Sealing string `json:"sealing"`
Serving string `json:"serving,omitempty"`
}
// ProposalChange is one change of a proposal.
type ProposalChange struct {
Bindings map[string]Provider `json:"bindings,omitempty"`
Claim string `json:"claim,omitempty"`
Decided *NodeDecided `json:"decided,omitempty"`
Field string `json:"field,omitempty"`
// the public halves of a joining node's keys
Keys *ProposalChangeKeys `json:"keys,omitempty"`
Kind string `json:"kind,omitempty"`
Layer map[string]any `json:"layer,omitempty"`
MeshWide map[string]any `json:"mesh-wide,omitempty"`
MeshWideValues map[string]any `json:"mesh-wide-values,omitempty"`
Module string `json:"module,omitempty"`
Node string `json:"node"`
// place, take-off, pin, unpin, hold, unhold, decide, config, seed, add-node or remove-node
Op string `json:"op"`
Ports map[string]int64 `json:"ports,omitempty"`
Provider *Provider `json:"provider,omitempty"`
Provision string `json:"provision,omitempty"`
Scope string `json:"scope,omitempty"`
Site string `json:"site,omitempty"`
// a decided field's value
Value any `json:"value,omitempty"`
Values map[string]any `json:"values,omitempty"`
// the node's whole placement, for a seed
Whole *Placement `json:"whole,omitempty"`
}
// Provider is the module on a node that answers a requirement or holds a seat.
type Provider struct {
Module string `json:"module"`
Node string `json:"node"`
}
// SeatHoldersHoldersItem is a type of the contract.
type SeatHoldersHoldersItem struct {
Module string `json:"module"`
Node string `json:"node"`
}
// SeatHolders is one key of seat-holders.
type SeatHolders struct {
Holders []SeatHoldersHoldersItem `json:"holders"`
Node string `json:"node,omitempty"`
// the claim names no seat of the seat list
Outside bool `json:"outside,omitempty"`
Scope string `json:"scope"`
Seat string `json:"seat"`
V int64 `json:"v,omitempty"`
}
// Verdict is the holder's judgement of a proposal's answers.
type Verdict struct {
// every node's answer to its candidate, by node
Answers map[string]map[string]any `json:"answers,omitempty"`
At time.Time `json:"at"`
Carried map[string][]string `json:"carried,omitempty"`
Fails []string `json:"fails,omitempty"`
Intended map[string][]string `json:"intended,omitempty"`
Notes []string `json:"notes,omitempty"`
Silent []string `json:"silent,omitempty"`
// waits, pass or fail
State string `json:"state"`
Unintended map[string][]string `json:"unintended,omitempty"`
Until *time.Time `json:"until,omitempty"`
}
// Warrant is the enrolment's warrant an add-node carries.
type Warrant struct {
Address string `json:"address"`
Ask string `json:"ask"`
Node string `json:"node"`
Warrant string `json:"warrant"`
}
// PlacementInput is what placement takes.
type PlacementInput struct {
// "true": the changes in order, from the stream and the state's revisions
History string `json:"history,omitempty"`
// one module: the nodes it is placed on
Module string `json:"module,omitempty"`
// one node
Node string `json:"node,omitempty"`
// "true": who holds each seat, and on which node (the state seat-holders); with node, that node's
Seats string `json:"seats,omitempty"`
}
// The values of PlacementInput's history.
const (
PlacementInputHistoryTrue = "true"
PlacementInputHistoryFalse = "false"
)
// The values of PlacementInput's seats.
const (
PlacementInputSeatsTrue = "true"
PlacementInputSeatsFalse = "false"
)
// PlacementAnswer is what placement answers.
type PlacementAnswer = map[string]any
// ProposalsInput is what proposals takes.
type ProposalsInput struct {
// one proposal's id
ID string `json:"id,omitempty"`
}
// ProposalsAnswer is what proposals answers.
type ProposalsAnswer = map[string]any
// ProposeInput is what propose takes.
type ProposeInput struct {
// the changes, each an object with `op`: place (node, module, ports, bindings), take-off (node, module), pin (node, provision, provider {node, module}), unpin (node, provision), hold (node, module, claim, scope, kind, site), unhold (node, module, claim), decide (node, field, value: a decided field of the node, its address among them), config (node, module, mesh-wide, layer, mesh-wide-values, values), add-node (node, decided, keys: a joining node, mesh-enrolment's alone, the proposal's one change, with the enrolment's warrant, its tunnel key alone at the operator's yes; ADR 0587 §7), remove-node (node: a joining node never confirmed, taken off when its enrolment ends; mesh-enrolment's alone, on the same warrant)
Changes []map[string]any `json:"changes"`
// for an add-node alone: the enrolment's warrant {node, address, ask, warrant}, naming the change's node and address
Warrant map[string]any `json:"warrant,omitempty"`
// why, shown to the operator with the proposal
Why string `json:"why"`
}
// ProposeAnswer is what propose answers.
type ProposeAnswer = map[string]any
// WithdrawInput is what withdraw takes.
type WithdrawInput struct {
// the proposal's id
ID string `json:"id"`
// why, kept in the event
Why string `json:"why"`
}
// WithdrawAnswer is what withdraw answers.
type WithdrawAnswer = map[string]any
// AgainInput is what again takes.
type AgainInput struct {
// the proposal's id
ID string `json:"id"`
}
// AgainAnswer is what again answers.
type AgainAnswer = map[string]any
// PlacementProposedEvent is the body of the event placement-proposed.
type PlacementProposedEvent = PlacementEvent
// PlacementWithdrawnEvent is the body of the event placement-withdrawn.
type PlacementWithdrawnEvent = PlacementEvent
// PlacementJudgedEvent is the body of the event placement-judged.
type PlacementJudgedEvent = PlacementEvent
// PlacementChangedEvent is the body of the event placement-changed.
type PlacementChangedEvent = PlacementEvent
// PlacementByNodeNodeValueModulesItem is a type of the contract.
type PlacementByNodeNodeValueModulesItem struct {
// the digest of the module key's value it stands for
Digest string `json:"digest"`
Module string `json:"module"`
}
// PlacementByNodeNodeValue is one value of the state placement under the key <node>.node.
type PlacementByNodeNodeValue struct {
Decided NodeDecided `json:"decided"`
Holds []Holding `json:"holds,omitempty"`
// the modules placed, in the order the composition reads them
Modules []PlacementByNodeNodeValueModulesItem `json:"modules"`
Node string `json:"node"`
Pins map[string]Provider `json:"pins,omitempty"`
V int64 `json:"v,omitempty"`
}
// PlacementByNodeModuleValue is one value of the state placement under the key <node>.<module>.
type PlacementByNodeModuleValue struct {
Node string `json:"node"`
Placed PlacedModule `json:"placed"`
// the value it replaces while a write is under way
Previous *PlacedModule `json:"previous,omitempty"`
V int64 `json:"v,omitempty"`
}
// ProposalsByProposalValue is one value of the state proposals under the key <proposal>.
type ProposalsByProposalValue = Proposal
// CandidatesByProposalNodeValue is one value of the state candidates under the key <proposal>.<node>.
type CandidatesByProposalNodeValue struct {
// the node's placement with the proposal laid over it; absent when the proposal takes its key away
Placement *Placement `json:"placement,omitempty"`
Proposal string `json:"proposal"`
// the proposal changes this node's composition through another's key
Reached bool `json:"reached,omitempty"`
V int64 `json:"v,omitempty"`
}
// PulsesByAnswerProposalNodeValue is one value of the state pulses under the key answer.<proposal>.<node>.
type PulsesByAnswerProposalNodeValue struct {
V int64 `json:"v,omitempty"`
}
// PulsesByAskProposalValue is one value of the state pulses under the key ask.<proposal>.
type PulsesByAskProposalValue struct {
V int64 `json:"v,omitempty"`
}
// SeatHoldersBySeatValue is one value of the state seat-holders under the key <seat>.
type SeatHoldersBySeatValue = SeatHolders
// SeatHoldersBySeatNodeValue is one value of the state seat-holders under the key <seat>.<node>.
type SeatHoldersBySeatNodeValue = SeatHolders