network

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package network defines fail-closed address and retry policy.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEndpoint        = errors.New("network: invalid manager endpoint")
	ErrIPv6Unavailable = errors.New("network: IPv6 unavailable in target stack")
)
View Source
var (
	ErrCancelled = errors.New("network: lifetime cancelled")
	ErrTimeout   = errors.New("network: asynchronous operation deadline exceeded")
)
View Source
var ErrEntropy = errors.New("network: entropy unavailable")
View Source
var ErrPolling = errors.New("network: invalid poller configuration")

Functions

func EnsureConnected

func EnsureConnected(
	isUp func() bool,
	join func() error,
	configure func() error,
	sleep func(time.Duration),
) error

EnsureConnected restores a lost link and then refreshes its network configuration. An already healthy link is left untouched.

func PollManager

func PollManager(hooks PollHooks) error

PollManager runs the outbound-only device lifecycle. Successful polls use a low-frequency interval; failures use capped exponential backoff; active USB always wins arbitration.

func RetryDelay

func RetryDelay(failures uint) time.Duration

func RetryUntilConnected

func RetryUntilConnected(attempt func() error, sleep func(time.Duration)) error

RetryUntilConnected retries a link operation until it succeeds. The caller owns cancellation by making attempt return success when the runtime stops.

func SelectIPv4

func SelectIPv4(addresses []netip.Addr, port uint16) (netip.AddrPort, error)

Types

type CounterReader

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

CounterReader mixes a monotonic counter into platform-provided random words. The manager-provided cryptographic challenge remains the security anchor; this reader guarantees per-boot nonce variation on the Pico side.

func NewCounterReader

func NewCounterReader(source WordSource, counter uint64) (*CounterReader, error)

func (*CounterReader) Read

func (reader *CounterReader) Read(destination []byte) (int, error)

type Endpoint

type Endpoint struct {
	Host string
	Port uint16
}

func ParseEndpoint

func ParseEndpoint(value string) (Endpoint, error)

type Lifetime

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

Lifetime is created once after epochstore durably reserves a boot epoch. This is uniqueness, NOT entropy: no weak platform RNG enters cryptography. Pico supplies an authenticated epoch/session challenge; the manager supplies a cryptographic random client nonce. Existing HMAC derives session keys. See RFC5116 sections3.1–3.2 and SPEC-screen-session. https://www.rfc-editor.org/rfc/rfc5116.html#section-3.1

func NewLifetime

func NewLifetime(uid [8]byte, reservedEpoch uint64) (*Lifetime, error)

func (*Lifetime) BootID

func (l *Lifetime) BootID() [16]byte

BootID is public board UID + durable epoch. It distinguishes ordinary reboots and boards, not authorized journal resets; recovery must reset all host caches.

func (*Lifetime) NextSession

func (l *Lifetime) NextSession() (epoch, session uint64, err error)

NextSession consumes before any handshake/preface bytes can be emitted or lost. Keep one Lifetime across reconnects and credential rotation. TCP dialer Pico still uses the cryptographic Device role (ServerHandshake).

type PollHooks

type PollHooks struct {
	Continue func() bool
	USB      func() bool
	Exchange func() error
	Sleep    func(time.Duration)
	Interval time.Duration
}

type Waiter

type Waiter struct {
	Now   func() time.Time
	Sleep func(time.Duration)
}

Waiter polls existing asynchronous stack APIs. Check must be nonblocking; this cannot turn a blocking CYW Join call into a cancellable operation.

func (Waiter) Wait

func (w Waiter) Wait(budget time.Duration, check func() (bool, error), cancelled func() bool) error

type WordSource

type WordSource func() (uint32, error)

Jump to

Keyboard shortcuts

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