state

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

README

Private state and traffic journals

store.go atomically persists authorization, accepted configuration, bans, and bounded private state. traffic.go exposes ordered immutable replay/acknowledgment. accounting.go commits raw totals and period-tagged samples together and seals barrier batches behind an outstanding report instead of replacing it.

The master must prefer samples for accounting-aware users, deduplicate the agent's immutable sequence and commit before acknowledging. Missing samples on legacy users remain supported. Old-period records survive resets and restart. The 64 MiB bound still stops admission instead of discarding recorded traffic.

Sampling timestamps have one-second granularity; an abrupt process or power failure can still lose bytes since the last successful sample. A quiesced barrier is complete only when the master has committed every batch through its sequence.

accounting_test.go covers restart, ordered replay, stable outstanding batches, separate periods and transactional overflow rejection.

Documentation

Overview

Package state persists private accepted state and a bounded acknowledged traffic journal.

Index

Constants

View Source
const MaxStoreBytes = 64 << 20

Variables

This section is empty.

Functions

func AtomicWrite

func AtomicWrite(path string, b []byte, mode os.FileMode) error

func ID

func ID() string

Types

type Batch

type Batch = protocol.TrafficReport

type Data

type Data struct {
	AgentID        string                            `json:"agent_id"`
	Revision       uint64                            `json:"revision"`
	ConfigRevision uint64                            `json:"config_revision"`
	Config         *protocol.Config                  `json:"config,omitempty"`
	Users          []protocol.User                   `json:"users"`
	Bans           map[int]time.Time                 `json:"bans,omitempty"`
	IPBlocks       map[string]protocol.IPBlock       `json:"ip_blocks,omitempty"`
	Sequence       uint64                            `json:"sequence"`
	Pending        *Batch                            `json:"pending,omitempty"`
	Accumulated    Traffic                           `json:"accumulated,omitempty"`
	Accounting     map[string]protocol.TrafficSample `json:"accounting,omitempty"`
	Backlog        []*Batch                          `json:"backlog,omitempty"`
}

type Store

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

func Open

func Open(dir string) (*Store, error)

func (*Store) Accept

func (s *Store) Accept(c protocol.Config, revision uint64) error

func (*Store) Ack

func (s *Store) Ack(id string) error

Ack retires only the matching head and advances queued barrier batches in order.

func (*Store) AddAccounting added in v1.0.2

func (s *Store) AddAccounting(delta Traffic, samples []protocol.TrafficSample) error

AddAccounting commits legacy totals and period samples in one durable mutation.

func (*Store) AddTraffic

func (s *Store) AddTraffic(delta Traffic) error

func (*Store) Authorize

func (s *Store) Authorize(users []protocol.User, revision uint64) error

func (*Store) Ban

func (s *Store) Ban(id int, until time.Time) error

func (*Store) Batch

func (s *Store) Batch() (*Batch, error)

Batch returns the oldest immutable unacknowledged batch.

func (*Store) BlockIP

func (s *Store) BlockIP(key string, block protocol.IPBlock) error

func (*Store) Flush added in v1.0.2

func (s *Store) Flush() (protocol.TrafficBarrier, error)

Flush seals all captured data without replacing an outstanding replay batch.

func (*Store) Snapshot

func (s *Store) Snapshot() Data

type Traffic

type Traffic = protocol.Traffic

Jump to

Keyboard shortcuts

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