52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
package buscompose
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// The mesh's caps on a bucket, the same for every module: a value is a piece of state, not a file,
|
|
// and a bucket that grew without bound would be one module filling the bus's disk for everyone.
|
|
const (
|
|
StateMaxValueBytes = 256 * 1024
|
|
)
|
|
|
|
// A Bucket is one module's declared state as the bus holds it.
|
|
type Bucket struct {
|
|
Module string
|
|
Name string
|
|
// History is how many values a key keeps; zero is one.
|
|
History int
|
|
// TTLSeconds is how long a value lives; zero is until replaced or deleted.
|
|
TTLSeconds int
|
|
// PerMachine says each machine's instance writes only the key named for its machine (novox/hq ADR
|
|
// 0260), and is granted that key and no other.
|
|
PerMachine bool
|
|
// KeyTTL says the bucket allows a time to live per key (novox/hq ADR 0433 §1): its owner writes each key with its
|
|
// own, and the server writes a delete marker, kept KeyTTLMarkerTTL, when it ends.
|
|
KeyTTL bool
|
|
}
|
|
|
|
// BucketName is the bucket a module's state lives in: the module and the local name joined by an
|
|
// underscore, which neither may contain, so two modules can never derive one bucket.
|
|
func BucketName(module, name string) string { return module + "_" + name }
|
|
|
|
// Bucket is this bucket's name on the bus.
|
|
func (b Bucket) Bucket() string { return BucketName(b.Module, b.Name) }
|
|
|
|
// Why is carried into the server's description of the bucket, so somebody reading the server's
|
|
// own state finds whose it is and why it is kept.
|
|
func (b Bucket) Why() string {
|
|
return fmt.Sprintf("%s's state %q (novox/hq ADR 0201): its current value per key, written by %s, "+
|
|
"read by whatever declares it reads it; kept when %s is unassigned, because it is data",
|
|
b.Module, b.Name, b.Module, b.Module)
|
|
}
|
|
|
|
// KeyedRead is one key of another module's state a principal reads, and no other key of it.
|
|
type KeyedRead struct {
|
|
Read string `json:"read"`
|
|
Key string `json:"key"`
|
|
}
|
|
|
|
// ResolvedBucket is mesh-config's state of resolved values, keyed `<node>.<module>.<key>`.
|
|
const ResolvedBucket = "mesh-config_resolved"
|