util

package
v0.0.0-...-9bffb30 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Overview

Package util contains helper functions for processes, IP addresses, env variables, etc.

Index

Constants

This section is empty.

Variables

IPBufferPool is meant to be used in conjunction with `NetIPFromAddress`

Functions

func ChunkPayloadsBySizeAndWeight

func ChunkPayloadsBySizeAndWeight[T any, P any](l *PayloadList[P], a *ChunkAllocator[T, P], maxChunkSize int, maxChunkWeight int)

ChunkPayloadsBySizeAndWeight allocates chunks of payloads taking max allowed size and max allowed weight algorithm in the nutshell: - iterate through payloads in the `payloadList` - keep track of size and weight available for allocation (`TakenSize` and `TakenWeight`) - create a new chunk once we exceed these limits - consider case when the current item exceeds the max allowed weight and create a new chunk at the end (`Append`) this implementation allows for multiple passes through the chunks, which can be useful in cases with different payload types being allocated within chunks See PayloadList and ChunkAllocator for a description of the type params.

func GetDockerSocketPath

func GetDockerSocketPath() (string, error)

GetDockerSocketPath is only for exposing the sockpath out of the module

func HandleSignals

func HandleSignals(exit chan struct{})

HandleSignals tells us whether we should exit.

func NetIPFromAddress

func NetIPFromAddress(addr Address, buf []byte) net.IP

NetIPFromAddress returns a net.IP from an Address Warning: the returned `net.IP` will share the same underlying memory as the given `buf` argument.

func ToLowHigh added in v0.9.0

func ToLowHigh(addr Address) (l, h uint64)

ToLowHigh converts an address into a pair of uint64 numbers

func ToLowHighIP

func ToLowHighIP(a netip.Addr) (l, h uint64)

ToLowHighIP converts a netaddr.IP into a pair of uint64 numbers

Types

type Address

type Address struct {
	netip.Addr
}

Address is an IP abstraction that is family (v4/v6) agnostic

func AddressFromNetIP

func AddressFromNetIP(ip net.IP) Address

AddressFromNetIP returns an Address from a provided net.IP

func AddressFromString

func AddressFromString(s string) Address

AddressFromString creates an Address using the string representation of an IP

func FromLowHigh

func FromLowHigh(l, h uint64) Address

FromLowHigh creates an address from a pair of uint64 numbers

func V4Address

func V4Address(ip uint32) Address

V4Address creates an Address using the uint32 representation of an v4 IP

func V6Address

func V6Address(low, high uint64) Address

V6Address creates an Address using the uint128 representation of an v6 IP

type AppendToChunk

type AppendToChunk[T any, P any] func(t *T, ps []P)

type ChunkAllocator

type ChunkAllocator[T any, P any] struct {

	// A function which adds the group of payloads to the chunk
	AppendToChunk AppendToChunk[T, P]
	// An optional callback that allows for manipulation the chunk when a payload is added
	OnAccept OnAccept[T]
	// contains filtered or unexported fields
}

ChunkAllocator manages operations for chunk allocation. The type T is the type of the chunk, and the type P is the type of the payload.

func (*ChunkAllocator[T, P]) Accept

func (c *ChunkAllocator[T, P]) Accept(ps []P, weight int)

Accept accepts a group of payloads into the current chunk

func (*ChunkAllocator[T, P]) Append

func (c *ChunkAllocator[T, P]) Append()

Append creates a new chunk at the end (cases when it is known any previously allocated chunks cannot fit the payload)

func (*ChunkAllocator[T, P]) GetChunks

func (c *ChunkAllocator[T, P]) GetChunks() *[]T

func (*ChunkAllocator[T, P]) Next

func (c *ChunkAllocator[T, P]) Next()

Next moves to the next chunk or allocates a new chunk if the current chunk is the last

func (*ChunkAllocator[T, P]) SetActiveChunk

func (c *ChunkAllocator[T, P]) SetActiveChunk(i int)

SetActiveChunk allows for rewinding in the case of multiple runs

func (*ChunkAllocator[T, P]) SetLastChunk

func (c *ChunkAllocator[T, P]) SetLastChunk()

SetLastChunk sets the last chunk in case there is space at end across multiple runs

func (*ChunkAllocator[T, P]) TakenSize

func (c *ChunkAllocator[T, P]) TakenSize() int

TakenSize returns the size allocated to the current chunk

func (*ChunkAllocator[T, P]) TakenWeight

func (c *ChunkAllocator[T, P]) TakenWeight() int

TakenWeight returns the weight allocated to the current chunk

type OnAccept

type OnAccept[T any] func(t *T)

type PayloadList

type PayloadList[T any] struct {
	// The items to chunk
	Items []T
	// A function which returns the weight of an item at the given index
	WeightAt WeightAt
}

PayloadList is a wrapper for payloads subject to chunking

func (*PayloadList[T]) Len

func (l *PayloadList[T]) Len() int

Len returns the number of items in the list

type SSBytes added in v0.9.0

type SSBytes [][]byte

SSBytes implements the sort.Interface for the [][]byte type

func (SSBytes) Len added in v0.9.0

func (ss SSBytes) Len() int

func (SSBytes) Less added in v0.9.0

func (ss SSBytes) Less(i, j int) bool

func (SSBytes) Search added in v0.9.0

func (ss SSBytes) Search(x []byte) int

Search returns the index of element x if found or -1 otherwise. SSBytes is expected to be sorted.

func (SSBytes) Swap added in v0.9.0

func (ss SSBytes) Swap(i, j int)

type WeightAt

type WeightAt func(int) int

Directories

Path Synopsis
api module
mocks
Package mock_containers is a generated GoMock package.
Package mock_containers is a generated GoMock package.

Jump to

Keyboard shortcuts

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