state

package
v0.0.1-dev.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const HeartbeatInterval = 15 * time.Second

Variables

View Source
var (
	ErrSpecOwnedByPeer = errors.New("spec already published by another peer")
	ErrInvalidDigest   = errors.New("invalid manifest digest")
)

Functions

func NormaliseProtocol

func NormaliseProtocol(p statev1.ServiceProtocol) statev1.ServiceProtocol

Backward compatibility: gossip data that predates the protocol field carries UNSPECIFIED, which callers treat as TCP.

Types

type AddressesChanged

type AddressesChanged struct{ Peer types.PeerKey }

type BlobSpec

type BlobSpec struct {
	Name   string
	Digest string
}

type BlobSpecView

type BlobSpecView struct {
	Spec      BlobSpec
	Publisher types.PeerKey
}

type Digest

type Digest struct {
	// contains filtered or unexported fields
}

func UnmarshalDigest

func UnmarshalDigest(data []byte) (Digest, error)

func (Digest) Marshal

func (d Digest) Marshal() ([]byte, error)

type Event

type Event interface {
	// contains filtered or unexported methods
}

type NodeResources

type NodeResources struct {
	MemTotalBytes uint64
	CPUPercent    uint32
	MemPercent    uint32
	NumCPU        uint32
}

type NodeView

type NodeView struct {
	LastEventAt        time.Time
	BackoffExpiry      time.Time
	TrafficRates       map[types.PeerKey]TrafficSnapshot
	Reachable          map[types.PeerKey]struct{}
	Services           map[string]*Service
	CallCounts         map[string]uint64
	Blobs              map[string]struct{}
	VivaldiCoord       *coords.Coord
	ObservedExternalIP string
	LastAddr           string
	Name               string
	PeerPub            []byte
	IPs                []string
	NatType            nat.Type
	VivaldiErr         float64
	MemTotalBytes      uint64
	CertExpiry         int64
	MemPercent         uint32
	NumCPU             uint32
	CPUPercent         uint32
	ExternalPort       uint32
	LocalPort          uint32
	PubliclyAccessible bool
	AdminCapable       bool
	CanServeStatic     bool
}

type PeerDenied

type PeerDenied struct{ Key types.PeerKey }

type PeerJoined

type PeerJoined struct{ Key types.PeerKey }

type Service

type Service struct {
	Properties *structpb.Struct
	Name       string
	Port       uint32
	Protocol   statev1.ServiceProtocol
}

type ServiceChanged

type ServiceChanged struct {
	Name string
	Peer types.PeerKey
}

type ServiceInfo

type ServiceInfo struct {
	Properties *structpb.Struct
	Name       string
	Peer       types.PeerKey
	Port       uint32
	Protocol   statev1.ServiceProtocol
}

type Snapshot

type Snapshot struct {
	Nodes          map[types.PeerKey]NodeView
	Specs          map[string]WorkloadSpecView
	Claims         map[string]map[types.PeerKey]struct{}
	DrainingClaims map[string]map[types.PeerKey]struct{}
	StaticSpecs    map[string]StaticSpecView
	StaticClaims   map[string]map[types.PeerKey]struct{}
	BlobSpecs      map[string]BlobSpecView

	PeerKeys   []types.PeerKey
	DeniedKeys []types.PeerKey
	LocalID    types.PeerKey
	// contains filtered or unexported fields
}

func (Snapshot) BlobByName

func (s Snapshot) BlobByName(name string) (string, BlobSpecView, bool)

func (Snapshot) DeniedPeers

func (s Snapshot) DeniedPeers() []types.PeerKey

func (Snapshot) Digest

func (s Snapshot) Digest() Digest

func (Snapshot) LocalSpecByName

func (s Snapshot) LocalSpecByName(name string, localID types.PeerKey) (string, bool)

func (Snapshot) PeersWithBlob

func (s Snapshot) PeersWithBlob(hash string) []types.PeerKey

PeersWithBlob returns live peers advertising hash. Stale BlobAvailability from offline peers persists in gossip until cert expiry; including them would direct fetches at unreachable nodes.

func (Snapshot) Services

func (s Snapshot) Services() []ServiceInfo

func (Snapshot) SpecByName

func (s Snapshot) SpecByName(name string) (string, WorkloadSpecView, bool)

type StateStore

type StateStore interface {
	Snapshot() Snapshot
	ApplyDelta(from types.PeerKey, data []byte) ([]Event, []byte, error)
	EncodeDelta(since Digest) []byte
	EncodeFull() []byte
	PendingNotify() <-chan struct{}
	FlushPendingGossip() []*statev1.GossipEvent

	DenyPeer(key types.PeerKey) []Event
	SetLocalAddresses(addrs []netip.AddrPort) []Event
	SetLocalNAT(t nat.Type) []Event
	SetLocalCoord(c coords.Coord, coordErr float64) []Event
	SetLocalReachable(peers []types.PeerKey) []Event
	SetLocalObservedAddress(ip string, port uint32) []Event

	PublishWorkload(spec WorkloadSpec) ([]Event, error)
	DeleteWorkloadSpec(hash string) []Event
	ClaimWorkload(hash string) []Event
	MarkWorkloadDraining(hash string) []Event
	ReleaseWorkload(hash string) []Event
	SetLocalResources(r NodeResources) []Event
	SetBackoffTTL(expiresAt time.Time) []Event
	SetPerSeedCallCounts(counts map[string]uint64) []Event
	SetLocalBlobs(digests []string) []Event

	SetStaticSpec(spec StaticSpec) ([]Event, error)
	DeleteStaticSpec(name string) []Event
	ClaimStatic(name string) []Event
	ReleaseStatic(name string) []Event

	SetBlobSpec(spec BlobSpec) ([]Event, error)
	DeleteBlobSpec(digest string) []Event

	SetService(port uint32, name string, protocol statev1.ServiceProtocol, properties *structpb.Struct) []Event
	RemoveService(name string) []Event
	SetLocalTraffic(peer types.PeerKey, in, out uint64) []Event

	EmitHeartbeatIfNeeded() []Event
	LoadGossipState(data []byte) error

	SetPeerLastAddr(pk types.PeerKey, addr string)
	SetPublic()
	SetAdmin()
	ClearAdmin()
	SetStaticCapable()
	SetNodeName(name string)
	ExportLastAddrs() map[types.PeerKey]string
	LoadLastAddrs(addrs map[types.PeerKey]string)
}

func New

func New(self types.PeerKey) StateStore

type StaticChanged

type StaticChanged struct{ Name string }

type StaticSpec

type StaticSpec struct {
	Name           string
	ManifestDigest string
}

type StaticSpecView

type StaticSpecView struct {
	Spec      StaticSpec
	Publisher types.PeerKey
}

type TopologyChanged

type TopologyChanged struct{ Peer types.PeerKey }

type TrafficSnapshot

type TrafficSnapshot struct {
	RateIn  uint64
	RateOut uint64
}

type WorkloadChanged

type WorkloadChanged struct{ Hash string }

type WorkloadSpec

type WorkloadSpec struct {
	Hash        string
	Name        string
	MemoryBytes uint64
	Timeout     time.Duration
	MinReplicas uint32
	Spread      float32
}

type WorkloadSpecView

type WorkloadSpecView struct {
	Spec      WorkloadSpec
	Publisher types.PeerKey
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL