Documentation
¶
Overview ¶
Package networkstate freezes address and egress facts for a connectivity generation.
Index ¶
- Constants
- type Address
- type Monitor
- type Observer
- type Route
- type Snapshot
- type Source
- type State
- type SystemSource
- type Watcher
- func (w *Watcher) Close()
- func (w *Watcher) Current() Snapshot
- func (w *Watcher) Poll(ctx context.Context, now time.Time) (Snapshot, bool, error)
- func (w *Watcher) Snapshot(ctx context.Context) (Snapshot, error)
- func (w *Watcher) Step(ctx context.Context) (Snapshot, bool, error)
- func (w *Watcher) Subscribe() (<-chan Snapshot, func())
- func (w *Watcher) Watch(ctx context.Context, onChange func(Snapshot))
- type WatcherConfig
Constants ¶
const DefaultDebounce = 500 * time.Millisecond
const DefaultPollInterval = time.Second
const ResumeGap = 10 * time.Second
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
func (*Monitor) Poll ¶
Poll detects resume by an unexpectedly long observation gap. Platform route and address facts are read together and never applied to an existing snapshot.
func (*Monitor) ResetPollGap ¶ added in v0.1.6
func (m *Monitor) ResetPollGap()
ResetPollGap clears the prior poll timestamp when a watcher pauses polling while idle so resuming later is not misclassified as an OS sleep.
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
func (Snapshot) GenerationID ¶
func (Snapshot) LocalAddresses ¶
type SystemSource ¶
type SystemSource struct{}
type Watcher ¶ added in v0.1.6
type Watcher struct {
// contains filtered or unexported fields
}
Watcher owns one host-wide polling cadence and fans out immutable generation transitions to all subscribers. Polling runs only while at least one subscriber is active; Snapshot and Poll reuse recent observations so concurrent callers never multiply OS queries, while still surfacing expired snapshots and persistent background sampling failures.
func NewWatcher ¶ added in v0.1.6
func NewWatcher(config WatcherConfig) *Watcher
func (*Watcher) Poll ¶ added in v0.1.6
Poll satisfies pull-based consumers without triggering redundant OS queries while the cached snapshot is fresh. Concurrent cache misses wait on either the in-flight sample or their own context cancellation; non-cancellation sampling errors and samples captured at or after the caller's timestamp are shared with that round's waiters, while caller cancellation stays isolated and older samples recheck snapshot freshness.
func (*Watcher) Step ¶ added in v0.1.6
Step forces one poll against the underlying monitor and broadcasts any true generation transition (after the initial baseline) to active subscribers.