state

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAge

func GetAge() time.Duration

GetAge returns how old the current snapshot is.

func GetBannedTotal

func GetBannedTotal() int64

GetBannedTotal returns total banned IPs (IPv4 + IPv6).

func GetFeedsActive

func GetFeedsActive() int

GetFeedsActive returns number of active feeds.

func GetFeedsIPs

func GetFeedsIPs() int64

GetFeedsIPs returns total IPs from all feeds.

func GetWhitelistTotal

func GetWhitelistTotal() int64

GetWhitelistTotal returns total whitelist IPs (IPv4 + IPv6).

func IsInitialized

func IsInitialized() bool

IsInitialized returns true if snapshot has been populated at least once.

func IsStale

func IsStale(maxAge time.Duration) bool

IsStale returns true if snapshot is older than given duration.

func Update

func Update(snap BasicSnapshot)

Update is called by watchdog after each collection cycle. This populates the shared state that all BASIC tier consumers read from.

func UpdateFeeds

func UpdateFeeds(active int, totalIPs int64)

UpdateFeeds updates just the feeds-related fields in the snapshot. Called by feeds loader/sync after feed operations complete. This allows feeds data to be updated independently of watchdog nftables collection.

Types

type BasicSnapshot

type BasicSnapshot struct {
	// nftables data (from watchdog netlink - NO CLI)
	BannedIPv4    int64 `json:"banned_ipv4"`
	BannedIPv6    int64 `json:"banned_ipv6"`
	WhitelistIPv4 int64 `json:"whitelist_ipv4"`
	WhitelistIPv6 int64 `json:"whitelist_ipv6"`
	RulesTotal    int64 `json:"rules_total"`

	// Feeds data (from loader in-memory - NO CLI)
	FeedsActive int   `json:"feeds_active"`
	FeedsIPs    int64 `json:"feeds_ips"`

	// Timestamp
	UpdatedAt time.Time `json:"updated_at"`
}

BasicSnapshot holds data needed by BASIC tier consumers. This is the single source of truth for:

  • nftban stats command
  • nftban status command
  • Web UI dashboard
  • Sampler (when metrics disabled)

Data is populated by watchdog (netlink) and feeds loader (in-memory). NO CLI CALLS - all consumers read from this shared state.

func Get

func Get() BasicSnapshot

Get returns current snapshot for BASIC tier consumers (sampler, stats CLI, status CLI, UI handlers).

Jump to

Keyboard shortcuts

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