internal

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package internal has bits and bobs for the internal implementation details of wirelink, esp. test utilities, mocks, and abstractions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Memoize added in v0.14.0

func Memoize[K comparable, V any](size, ratio int, f func(K) V) func(K) V

Memoize uses an LRUMap to memoize the given function.

Types

type LRUMap added in v0.14.0

type LRUMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

LRUMap wraps a Map with a crude LRU system. It works by tracking a top level counter (`n`) that is incremented for every Get and Set, and the new counter value stored with each item as well. After a Set, `trim` may be invoked. The `trim` operation constrains the map size by computing a threshold value for the counter `n` and deleting any entry whose last access is below that threshold. The threshold is determined as a `ratio` times the number of map items, providing a crude heuristic of removing items not accessed in the last `ratio` passes through the full map. As such, the LRUMap does _not_ defend against degenerate use cases where new items are often Set but rarely or never Get, but it will systematically prune items that are rarely accessed, with `ratio` determining what "rare" means.

func NewLRUMap added in v0.14.0

func NewLRUMap[K comparable, V any](size, ratio int) *LRUMap[K, V]

NewLRUMap creates a new LRUMap with the given initial map allocation size and trim ratio

func (*LRUMap[K, V]) Get added in v0.14.0

func (m *LRUMap[K, V]) Get(k K) (v V, ok bool)

Get attempts to retrieve an item from the map, returning the item (or the zero value for V) and an ok indicator whether it was found in the map or not. If an item was found, its last used counter will be incremented.

func (*LRUMap[K, V]) Set added in v0.14.0

func (m *LRUMap[K, V]) Set(k K, v V)

Set adds or overwrites the value associated with a key in the map, and updates its last used counter.

type WgClient

type WgClient interface {
	io.Closer
	Devices() ([]*wgtypes.Device, error)
	Device(name string) (*wgtypes.Device, error)
	ConfigureDevice(name string, cfg wgtypes.Config) error
}

WgClient is a copy-pasta of wginternal.Client because we can't import that

Directories

Path Synopsis
Package channels contains various generic helpers for working with channels
Package channels contains various generic helpers for working with channels
Package mocks has just test files for use by other packages' tests
Package mocks has just test files for use by other packages' tests
Package networking provides abstraction layers for accessing networking resources both across platform specific details, and for virtual / mock configurations for testing
Package networking provides abstraction layers for accessing networking resources both across platform specific details, and for virtual / mock configurations for testing
darwin
Package darwin provides an implementation of networking.Environment for the host darwin (macOS) system, leveraging the Go native package, and then filling in the gaps by exececuting command line tools such as ifconfig.
Package darwin provides an implementation of networking.Environment for the host darwin (macOS) system, leveraging the Go native package, and then filling in the gaps by exececuting command line tools such as ifconfig.
host
Package host provides a generic accessor factory to create the appropriate platform-specific interface to the host networking APIs.
Package host provides a generic accessor factory to create the appropriate platform-specific interface to the host networking APIs.
linux
Package linux provides an implementation of networking.Environment for the host Linux system, leveraging the Go native package, and then filling in the gaps using netlink APIs.
Package linux provides an implementation of networking.Environment for the host Linux system, leveraging the Go native package, and then filling in the gaps using netlink APIs.
mocks
Package mocks provides mock implementations of the networking apis, for the testify mock library, generated via go generate and mockery.
Package mocks provides mock implementations of the networking apis, for the testify mock library, generated via go generate and mockery.
native
Package native provdies common base implementations of the networking.Environment and related interfaces, or at least the portions that can be implemented using common native Go APIs.
Package native provdies common base implementations of the networking.Environment and related interfaces, or at least the portions that can be implemented using common native Go APIs.
vnet
Package vnet provides a virtual (as opposed to mocked) implementation of the abstracted UDP networking stack.
Package vnet provides a virtual (as opposed to mocked) implementation of the abstracted UDP networking stack.
Package testutils provides utility code needed by multiple packages' test suites, but which should not be referenced in any non-test code.
Package testutils provides utility code needed by multiple packages' test suites, but which should not be referenced in any non-test code.
facts
Package facts provides helper code for generating facts for use in unit tests.
Package facts provides helper code for generating facts for use in unit tests.

Jump to

Keyboard shortcuts

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